This commit is contained in:
syuilo
2018-04-15 11:57:33 +09:00
parent 10f6d5980f
commit 69c452a980
19 changed files with 28 additions and 748 deletions

View File

@ -84,14 +84,19 @@ export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriv
// このDriveFileがアバターやバナーに使われていたらそれらのプロパティをnullにする
const u = await User.findOne({ _id: d.metadata.userId });
if (u) {
if (u.avatarId.equals(d._id)) {
if (u.avatarId && u.avatarId.equals(d._id)) {
await User.update({ _id: u._id }, { $set: { avatarId: null } });
}
if (u.bannerId.equals(d._id)) {
if (u.bannerId && u.bannerId.equals(d._id)) {
await User.update({ _id: u._id }, { $set: { bannerId: null } });
}
}
// このDriveFileのチャンクをすべて削除
await monkDb.get('driveFiles.chunks').remove({
files_id: d._id
});
// このDriveFileを削除
await DriveFile.remove({
_id: d._id