This commit is contained in:
syuilo 2019-04-14 11:50:31 +09:00
parent e3b3f8fac1
commit 694ec7ebe1
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
1 changed files with 14 additions and 7 deletions

View File

@ -201,13 +201,20 @@ async function upload(key: string, stream: fs.ReadStream | Buffer, type: string,
} }
async function deleteOldFile(user: IRemoteUser) { async function deleteOldFile(user: IRemoteUser) {
const oldFile = await DriveFiles.createQueryBuilder() const q = DriveFiles.createQueryBuilder('file')
.select('file') .where('file.userId = :userId', { userId: user.id });
.where('file.id != :avatarId', { avatarId: user.avatarId })
.andWhere('file.id != :bannerId', { bannerId: user.bannerId }) if (user.avatarId) {
.andWhere('file.userId = :userId', { userId: user.id }) q.andWhere('file.id != :avatarId', { avatarId: user.avatarId });
.orderBy('file.id', 'DESC') }
.getOne();
if (user.bannerId) {
q.andWhere('file.id != :bannerId', { bannerId: user.bannerId })
}
q.orderBy('file.id', 'DESC');
const oldFile = await q.getOne();
if (oldFile) { if (oldFile) {
delFile(oldFile, true); delFile(oldFile, true);