1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-11 21:29:08 +09:00
This commit is contained in:
syuilo 2018-04-17 19:55:58 +09:00
parent e69554f810
commit 0f67a544bd
2 changed files with 33 additions and 6 deletions

View File

@ -8,11 +8,11 @@ import MessagingMessage, { deleteMessagingMessage } from './messaging-message';
import User from './user';
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
DriveFile.createIndex('metadata.uri', { sparse: true, unique: true });
export default DriveFile;
export const DriveFileChunk = monkDb.get('driveFiles.chunks');
const getGridFSBucket = async (): Promise<mongo.GridFSBucket> => {
const db = await nativeDbConn();
const bucket = new mongo.GridFSBucket(db, {
@ -93,7 +93,7 @@ export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriv
}
// このDriveFileのチャンクをすべて削除
await monkDb.get('driveFiles.chunks').remove({
await DriveFileChunk.remove({
files_id: d._id
});

View File

@ -10,12 +10,12 @@ import * as debug from 'debug';
import fileType = require('file-type');
import prominence = require('prominence');
import DriveFile, { IMetadata, getGridFSBucket, IDriveFile } from '../../models/drive-file';
import DriveFile, { IMetadata, getGridFSBucket, IDriveFile, DriveFileChunk } from '../../models/drive-file';
import DriveFolder from '../../models/drive-folder';
import { pack } from '../../models/drive-file';
import event, { publishDriveStream } from '../../publishers/stream';
import getAcct from '../../acct/render';
import { IUser } from '../../models/user';
import { IUser, isLocalUser } from '../../models/user';
const gm = _gm.subClass({
imageMagick: true
@ -207,7 +207,34 @@ const addFile = async (
// If usage limit exceeded
if (usage + size > user.driveCapacity) {
throw 'no-free-space';
if (isLocalUser(user)) {
throw 'no-free-space';
} else {
//#region (アバターまたはバナーを含まず)最も古いファイルを削除する
const oldFile = await DriveFile.findOne({
_id: {
$nin: [user.avatarId, user.bannerId]
}
}, {
sort: {
_id: 1
}
});
if (oldFile) {
// チャンクをすべて削除
DriveFileChunk.remove({
files_id: oldFile._id
});
DriveFile.update({ _id: oldFile._id }, {
$set: {
'metadata.deletedAt': new Date()
}
});
}
//#endregion
}
}
})()
]);