enhance(backend): refine moderation log (#10939)

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update DriveService.ts
This commit is contained in:
syuilo
2023-09-23 18:28:16 +09:00
committed by GitHub
parent ba6e85482e
commit 9e4d3ebe5f
32 changed files with 563 additions and 39 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 (deleter && await this.roleService.isModerator(deleter) && (file.userId !== deleter.id)) {
this.moderationLogService.log(deleter, 'deleteDriveFile', {
fileId: file.id,
fileUserId: file.userId,
});
}
}
@bindThis