mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 01:43:08 +02:00
Fix bug nado
This commit is contained in:
parent
9c4e0a4ae6
commit
b3b82e7595
4 changed files with 55 additions and 64 deletions
|
@ -58,8 +58,7 @@ drive:
|
||||||
|
|
||||||
# OR
|
# OR
|
||||||
|
|
||||||
# storage: 'object-storage'
|
# storage: 'minio'
|
||||||
# service: 'minio'
|
|
||||||
# bucket:
|
# bucket:
|
||||||
# prefix:
|
# prefix:
|
||||||
# config:
|
# config:
|
||||||
|
|
|
@ -51,9 +51,8 @@ export type Source = {
|
||||||
|
|
||||||
drive?: {
|
drive?: {
|
||||||
storage: string;
|
storage: string;
|
||||||
bucket: string;
|
bucket?: string;
|
||||||
prefix: string;
|
prefix?: string;
|
||||||
service?: string;
|
|
||||||
config?: any;
|
config?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,36 +21,31 @@ import config from '../../config';
|
||||||
const log = debug('misskey:drive:add-file');
|
const log = debug('misskey:drive:add-file');
|
||||||
|
|
||||||
async function save(readable: stream.Readable, name: string, type: string, hash: string, size: number, metadata: any): Promise<IDriveFile> {
|
async function save(readable: stream.Readable, name: string, type: string, hash: string, size: number, metadata: any): Promise<IDriveFile> {
|
||||||
if (config.drive && config.drive.storage == 'object-storage') {
|
if (config.drive && config.drive.storage == 'minio') {
|
||||||
if (config.drive.service == 'minio') {
|
const minio = new Minio.Client(config.drive.config);
|
||||||
|
const id = uuid.v4();
|
||||||
|
const obj = `${config.drive.prefix}/${id}`;
|
||||||
|
await minio.putObject(config.drive.bucket, obj, readable);
|
||||||
|
|
||||||
const minio = new Minio.Client(config.drive.config);
|
Object.assign(metadata, {
|
||||||
const id = uuid.v4();
|
withoutChunks: true,
|
||||||
const obj = `${config.drive.prefix}/${id}`;
|
storage: 'minio',
|
||||||
await minio.putObject(config.drive.bucket, obj, readable);
|
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 }`
|
||||||
|
});
|
||||||
|
|
||||||
Object.assign(metadata, {
|
const file = await DriveFile.insert({
|
||||||
withoutChunks: true,
|
length: size,
|
||||||
storage: 'object-storage',
|
uploadDate: new Date(),
|
||||||
storageProps: {
|
md5: hash,
|
||||||
id: id
|
filename: name,
|
||||||
},
|
metadata: metadata,
|
||||||
url: `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }/${ obj }`
|
contentType: type
|
||||||
});
|
});
|
||||||
|
|
||||||
const file = await DriveFile.insert({
|
return file;
|
||||||
length: size,
|
|
||||||
uploadDate: new Date(),
|
|
||||||
md5: hash,
|
|
||||||
filename: name,
|
|
||||||
metadata: metadata,
|
|
||||||
contentType: type
|
|
||||||
});
|
|
||||||
|
|
||||||
return file;
|
|
||||||
} else {
|
|
||||||
throw 'unknown storage type';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Get MongoDB GridFS bucket
|
// Get MongoDB GridFS bucket
|
||||||
const bucket = await getDriveFileBucket();
|
const bucket = await getDriveFileBucket();
|
||||||
|
|
|
@ -4,37 +4,35 @@ import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
|
|
||||||
export default async function(file: IDriveFile, isExpired = false) {
|
export default async function(file: IDriveFile, isExpired = false) {
|
||||||
if (file.metadata.withoutChunks) {
|
if (file.metadata.storage == 'minio') {
|
||||||
if (file.metadata.storage == 'object-storage') {
|
const minio = new Minio.Client(config.drive.config);
|
||||||
const minio = new Minio.Client(config.drive.config);
|
const obj = `${config.drive.prefix}/${file.metadata.storageProps.id}`;
|
||||||
const obj = `${config.drive.prefix}/${file.metadata.storageProps.id}`;
|
await minio.removeObject(config.drive.bucket, obj);
|
||||||
await minio.removeObject(config.drive.bucket, obj);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// チャンクをすべて削除
|
|
||||||
await DriveFileChunk.remove({
|
|
||||||
files_id: file._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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// チャンクをすべて削除
|
||||||
|
await DriveFileChunk.remove({
|
||||||
|
files_id: file._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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue