Update delete-file.ts

This commit is contained in:
Acid Chicken (硫酸鶏) 2019-02-23 17:19:52 +09:00 committed by GitHub
parent 0709cac97f
commit 33ad190524
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
import * as Minio from 'minio';
import DriveFile, { DriveFileChunk, IDriveFile } from '../../models/drive-file';
import DriveFile, { DriveFileChunk, IDriveFile, getDriveFileBucket } from '../../models/drive-file';
import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-file-thumbnail';
import config from '../../config';
import driveChart from '../../services/chart/drive';
@ -7,7 +7,7 @@ import perUserDriveChart from '../../services/chart/per-user-drive';
import instanceChart from '../../services/chart/instance';
import DriveFileWebpublic, { DriveFileWebpublicChunk } from '../../models/drive-file-webpublic';
import Instance from '../../models/instance';
import { isRemoteUser } from '../../models/user';
import User, { isRemoteUser } from '../../models/user';
export default async function(file: IDriveFile, isExpired = false) {
if (file.metadata.storage == 'minio') {
@ -56,6 +56,12 @@ export default async function(file: IDriveFile, isExpired = false) {
$set: set
});
await Promise.all(['avatarId', 'bannerId', 'wallpaperId']
.map(target => User.find({ [target]: file._id })
.then(x => Promise.all(x.map(x => User.update({ _id: x._id }, {
$unset: { [target]: file._id }
}))))));
//#region サムネイルもあれば削除
const thumbnail = await DriveFileThumbnail.findOne({
'metadata.originalId': file._id