リモートファイルの削除が重い問題を修正
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import * as Minio from 'minio';
|
||||
import { DriveFile } from '../../models/entities/drive-file';
|
||||
import { InternalStorage } from './internal-storage';
|
||||
import { DriveFiles, Instances, Notes } from '../../models';
|
||||
import { driveChart, perUserDriveChart, instanceChart } from '../chart';
|
||||
import { createDeleteObjectStorageFileJob } from '../../queue';
|
||||
import { fetchMeta } from '../../misc/fetch-meta';
|
||||
|
||||
export async function deleteFile(file: DriveFile, isExpired = false) {
|
||||
if (file.storedInternal) {
|
||||
@@ -27,6 +29,40 @@ export async function deleteFile(file: DriveFile, isExpired = false) {
|
||||
}
|
||||
}
|
||||
|
||||
postProcess(file, isExpired);
|
||||
}
|
||||
|
||||
export async function deleteFileSync(file: DriveFile, isExpired = false) {
|
||||
if (file.storedInternal) {
|
||||
InternalStorage.del(file.accessKey!);
|
||||
|
||||
if (file.thumbnailUrl) {
|
||||
InternalStorage.del(file.thumbnailAccessKey!);
|
||||
}
|
||||
|
||||
if (file.webpublicUrl) {
|
||||
InternalStorage.del(file.webpublicAccessKey!);
|
||||
}
|
||||
} else if (!file.isLink) {
|
||||
const promises = [];
|
||||
|
||||
promises.push(deleteObjectStorageFile(file.accessKey!));
|
||||
|
||||
if (file.thumbnailUrl) {
|
||||
promises.push(deleteObjectStorageFile(file.thumbnailAccessKey!));
|
||||
}
|
||||
|
||||
if (file.webpublicUrl) {
|
||||
promises.push(deleteObjectStorageFile(file.webpublicAccessKey!));
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
postProcess(file, isExpired);
|
||||
}
|
||||
|
||||
function postProcess(file: DriveFile, isExpired = false) {
|
||||
// リモートファイル期限切れ削除後は直リンクにする
|
||||
if (isExpired && file.userHost !== null && file.uri != null) {
|
||||
DriveFiles.update(file.id, {
|
||||
@@ -53,3 +89,18 @@ export async function deleteFile(file: DriveFile, isExpired = false) {
|
||||
Instances.decrement({ host: file.userHost }, 'driveFiles', 1);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteObjectStorageFile(key: string) {
|
||||
const meta = await fetchMeta();
|
||||
|
||||
const minio = new Minio.Client({
|
||||
endPoint: meta.objectStorageEndpoint!,
|
||||
region: meta.objectStorageRegion ? meta.objectStorageRegion : undefined,
|
||||
port: meta.objectStoragePort ? meta.objectStoragePort : undefined,
|
||||
useSSL: meta.objectStorageUseSSL,
|
||||
accessKey: meta.objectStorageAccessKey!,
|
||||
secretKey: meta.objectStorageSecretKey!,
|
||||
});
|
||||
|
||||
await minio.removeObject(meta.objectStorageBucket!, key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user