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 { RoleService } from '@/core/RoleService.js';
import { correctFilename } from '@/misc/correct-filename.js'; import { correctFilename } from '@/misc/correct-filename.js';
import { isMimeImage } from '@/misc/is-mime-image.js'; import { isMimeImage } from '@/misc/is-mime-image.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
type AddFileArgs = { type AddFileArgs = {
/** User who wish to add file */ /** User who wish to add file */
@ -119,6 +120,7 @@ export class DriveService {
private globalEventService: GlobalEventService, private globalEventService: GlobalEventService,
private queueService: QueueService, private queueService: QueueService,
private roleService: RoleService, private roleService: RoleService,
private moderationLogService: ModerationLogService,
private driveChart: DriveChart, private driveChart: DriveChart,
private perUserDriveChart: PerUserDriveChart, private perUserDriveChart: PerUserDriveChart,
private instanceChart: InstanceChart, private instanceChart: InstanceChart,
@ -648,7 +650,7 @@ export class DriveService {
} }
@bindThis @bindThis
public async deleteFile(file: MiDriveFile, isExpired = false) { public async deleteFile(file: MiDriveFile, isExpired = false, deleter: MiUser) {
if (file.storedInternal) { if (file.storedInternal) {
this.internalStorageService.del(file.accessKey!); this.internalStorageService.del(file.accessKey!);
@ -671,11 +673,11 @@ export class DriveService {
} }
} }
this.deletePostProcess(file, isExpired); this.deletePostProcess(file, isExpired, deleter);
} }
@bindThis @bindThis
public async deleteFileSync(file: MiDriveFile, isExpired = false) { public async deleteFileSync(file: MiDriveFile, isExpired = false, deleter: MiUser) {
if (file.storedInternal) { if (file.storedInternal) {
this.internalStorageService.del(file.accessKey!); this.internalStorageService.del(file.accessKey!);
@ -702,11 +704,11 @@ export class DriveService {
await Promise.all(promises); await Promise.all(promises);
} }
this.deletePostProcess(file, isExpired); this.deletePostProcess(file, isExpired, deleter);
} }
@bindThis @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) { if (isExpired && file.userHost !== null && file.uri != null) {
this.driveFilesRepository.update(file.id, { this.driveFilesRepository.update(file.id, {
@ -733,6 +735,17 @@ export class DriveService {
this.instanceChart.updateDrive(file, false); 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 @bindThis

View File

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

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 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 = { export type ModerationLogPayloads = {
updateServerSettings: { updateServerSettings: {
@ -70,4 +83,8 @@ export type ModerationLogPayloads = {
}; };
clearQueue: Record<string, never>; clearQueue: Record<string, never>;
promoteQueue: 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', '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 = { export type ModerationLogPayloads = {
updateServerSettings: { updateServerSettings: {
@ -88,4 +101,8 @@ export type ModerationLogPayloads = {
}; };
clearQueue: Record<string, never>; clearQueue: Record<string, never>;
promoteQueue: Record<string, never>; promoteQueue: Record<string, never>;
deleteDriveFile: {
fileId: string;
fileUserId: string | null;
};
}; };