This commit is contained in:
syuilo 2023-09-23 18:01:09 +09:00
parent d17f4d52c9
commit 1766e923db
4 changed files with 55 additions and 12 deletions

View File

@ -42,6 +42,7 @@ import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import { correctFilename } from '@/misc/correct-filename.js';
import { isMimeImage } from '@/misc/is-mime-image.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
type AddFileArgs = {
/** User who wish to add file */
@ -119,6 +120,7 @@ export class DriveService {
private globalEventService: GlobalEventService,
private queueService: QueueService,
private roleService: RoleService,
private moderationLogService: ModerationLogService,
private driveChart: DriveChart,
private perUserDriveChart: PerUserDriveChart,
private instanceChart: InstanceChart,
@ -648,7 +650,7 @@ export class DriveService {
}
@bindThis
public async deleteFile(file: MiDriveFile, isExpired = false) {
public async deleteFile(file: MiDriveFile, isExpired = false, deleter: MiUser) {
if (file.storedInternal) {
this.internalStorageService.del(file.accessKey!);
@ -671,11 +673,11 @@ export class DriveService {
}
}
this.deletePostProcess(file, isExpired);
this.deletePostProcess(file, isExpired, deleter);
}
@bindThis
public async deleteFileSync(file: MiDriveFile, isExpired = false) {
public async deleteFileSync(file: MiDriveFile, isExpired = false, deleter: MiUser) {
if (file.storedInternal) {
this.internalStorageService.del(file.accessKey!);
@ -702,11 +704,11 @@ export class DriveService {
await Promise.all(promises);
}
this.deletePostProcess(file, isExpired);
this.deletePostProcess(file, isExpired, deleter);
}
@bindThis
private async deletePostProcess(file: MiDriveFile, isExpired = false) {
private async deletePostProcess(file: MiDriveFile, isExpired = false, deleter: MiUser) {
// リモートファイル期限切れ削除後は直リンクにする
if (isExpired && file.userHost !== null && file.uri != null) {
this.driveFilesRepository.update(file.id, {
@ -733,6 +735,17 @@ export class DriveService {
this.instanceChart.updateDrive(file, false);
}
}
if (file.userId) {
this.globalEventService.publishDriveStream(file.userId, 'fileDeleted', file.id);
}
if (await this.roleService.isModerator(deleter) && (file.userId !== deleter.id)) {
this.moderationLogService.log(deleter, 'deleteDriveFile', {
fileId: file.id,
fileUserId: file.userId,
});
}
}
@bindThis

View File

@ -65,11 +65,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.accessDenied);
}
// Delete
await this.driveService.deleteFile(file);
// Publish fileDeleted event
this.globalEventService.publishDriveStream(me.id, 'fileDeleted', file.id);
await this.driveService.deleteFile(file, me);
});
}
}

View File

@ -27,7 +27,20 @@ export const mutedNoteReasons = ['word', 'manual', 'spam', 'other'] as const;
export const ffVisibility = ['public', 'followers', 'private'] as const;
export const moderationLogTypes = ['updateServerSettings', 'suspend', 'unsuspend', 'updateUserNote', 'addCustomEmoji', 'assignRole', 'unassignRole', 'updateRole', 'deleteRole', 'clearQueue', 'promoteQueue'] as const;
export const moderationLogTypes = [
'updateServerSettings',
'suspend',
'unsuspend',
'updateUserNote',
'addCustomEmoji',
'assignRole',
'unassignRole',
'updateRole',
'deleteRole',
'clearQueue',
'promoteQueue',
'deleteDriveFile',
] as const;
export type ModerationLogPayloads = {
updateServerSettings: {
@ -70,4 +83,8 @@ export type ModerationLogPayloads = {
};
clearQueue: Record<string, never>;
promoteQueue: Record<string, never>;
deleteDriveFile: {
fileId: string;
fileUserId: string | null;
};
};

View File

@ -45,7 +45,20 @@ export const permissions = [
'write:flash-likes',
];
export const moderationLogTypes = ['updateServerSettings', 'suspend', 'unsuspend', 'updateUserNote', 'addCustomEmoji', 'assignRole', 'unassignRole', 'updateRole', 'deleteRole', 'clearQueue', 'promoteQueue'] as const;
export const moderationLogTypes = [
'updateServerSettings',
'suspend',
'unsuspend',
'updateUserNote',
'addCustomEmoji',
'assignRole',
'unassignRole',
'updateRole',
'deleteRole',
'clearQueue',
'promoteQueue',
'deleteDriveFile',
] as const;
export type ModerationLogPayloads = {
updateServerSettings: {
@ -88,4 +101,8 @@ export type ModerationLogPayloads = {
};
clearQueue: Record<string, never>;
promoteQueue: Record<string, never>;
deleteDriveFile: {
fileId: string;
fileUserId: string | null;
};
};