mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 01:56:43 -06:00
wip
This commit is contained in:
parent
adc3c16ef3
commit
a048939cf1
3 changed files with 37 additions and 23 deletions
|
@ -34,6 +34,8 @@ export type IMetadata = {
|
||||||
src?: string;
|
src?: string;
|
||||||
deletedAt?: Date;
|
deletedAt?: Date;
|
||||||
withoutChunks?: boolean;
|
withoutChunks?: boolean;
|
||||||
|
storage?: string;
|
||||||
|
storageProps?: any;
|
||||||
isSensitive?: boolean;
|
isSensitive?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,11 @@ async function save(readable: stream.Readable, name: string, type: string, hash:
|
||||||
await minio.putObject(config.drive.bucket, obj, readable);
|
await minio.putObject(config.drive.bucket, obj, readable);
|
||||||
|
|
||||||
Object.assign(metadata, {
|
Object.assign(metadata, {
|
||||||
storage: 'object-storage',
|
|
||||||
withoutChunks: true,
|
withoutChunks: true,
|
||||||
obj: id,
|
storage: 'object-storage',
|
||||||
|
storageProps: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
url: `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }/${ obj }`
|
url: `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }/${ obj }`
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,40 @@
|
||||||
|
import * as Minio from 'minio';
|
||||||
import DriveFile, { DriveFileChunk, IDriveFile } from '../../models/drive-file';
|
import DriveFile, { DriveFileChunk, IDriveFile } from '../../models/drive-file';
|
||||||
import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-file-thumbnail';
|
import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-file-thumbnail';
|
||||||
|
import config from '../../config';
|
||||||
|
|
||||||
export default async function(file: IDriveFile, isExpired = false) {
|
export default async function(file: IDriveFile, isExpired = false) {
|
||||||
// チャンクをすべて削除
|
if (file.metadata.withoutChunks) {
|
||||||
await DriveFileChunk.remove({
|
if (file.metadata.storage == 'object-storage') {
|
||||||
files_id: file._id
|
const minio = new Minio.Client(config.drive.config);
|
||||||
});
|
const obj = `${config.drive.prefix}/${file.metadata.storageProps.id}`;
|
||||||
|
await minio.removeObject(config.drive.bucket, obj);
|
||||||
await DriveFile.update({ _id: file._id }, {
|
|
||||||
$set: {
|
|
||||||
'metadata.deletedAt': new Date(),
|
|
||||||
'metadata.isExpired': isExpired
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
// チャンクをすべて削除
|
||||||
//#region サムネイルもあれば削除
|
await DriveFileChunk.remove({
|
||||||
const thumbnail = await DriveFileThumbnail.findOne({
|
files_id: file._id
|
||||||
'metadata.originalId': file._id
|
|
||||||
});
|
|
||||||
|
|
||||||
if (thumbnail) {
|
|
||||||
await DriveFileThumbnailChunk.remove({
|
|
||||||
files_id: thumbnail._id
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await DriveFileThumbnail.remove({ _id: thumbnail._id });
|
await DriveFile.update({ _id: file._id }, {
|
||||||
|
$set: {
|
||||||
|
'metadata.deletedAt': new Date(),
|
||||||
|
'metadata.isExpired': isExpired
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//#region サムネイルもあれば削除
|
||||||
|
const thumbnail = await DriveFileThumbnail.findOne({
|
||||||
|
'metadata.originalId': file._id
|
||||||
|
});
|
||||||
|
|
||||||
|
if (thumbnail) {
|
||||||
|
await DriveFileThumbnailChunk.remove({
|
||||||
|
files_id: thumbnail._id
|
||||||
|
});
|
||||||
|
|
||||||
|
await DriveFileThumbnail.remove({ _id: thumbnail._id });
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
//#endregion
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue