Compare commits

...

2 commits

Author SHA1 Message Date
Acid Chicken (硫酸鶏)
d956491c4a
Update delete-file.ts 2019-02-23 17:20:24 +09:00
Acid Chicken (硫酸鶏)
33ad190524
Update delete-file.ts 2019-02-23 17:19:52 +09:00

View file

@ -7,7 +7,7 @@ import perUserDriveChart from '../../services/chart/per-user-drive';
import instanceChart from '../../services/chart/instance'; import instanceChart from '../../services/chart/instance';
import DriveFileWebpublic, { DriveFileWebpublicChunk } from '../../models/drive-file-webpublic'; import DriveFileWebpublic, { DriveFileWebpublicChunk } from '../../models/drive-file-webpublic';
import Instance from '../../models/instance'; import Instance from '../../models/instance';
import { isRemoteUser } from '../../models/user'; import User, { isRemoteUser } from '../../models/user';
export default async function(file: IDriveFile, isExpired = false) { export default async function(file: IDriveFile, isExpired = false) {
if (file.metadata.storage == 'minio') { if (file.metadata.storage == 'minio') {
@ -56,6 +56,12 @@ export default async function(file: IDriveFile, isExpired = false) {
$set: set $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 サムネイルもあれば削除 //#region サムネイルもあれば削除
const thumbnail = await DriveFileThumbnail.findOne({ const thumbnail = await DriveFileThumbnail.findOne({
'metadata.originalId': file._id 'metadata.originalId': file._id