This commit is contained in:
syuilo
2023-09-24 16:24:13 +09:00
parent 4a7f6e6de4
commit cf573add27
2 changed files with 28 additions and 11 deletions

View File

@@ -87,6 +87,9 @@ type UploadFromUrlArgs = {
@Injectable()
export class DriveService {
public static NoSuchFolderError = class extends Error {};
public static InvalidFileNameError = class extends Error {};
public static CannotUnmarkSensitiveError = class extends Error {};
private registerLogger: Logger;
private downloaderLogger: Logger;
private deleteLogger: Logger;
@@ -650,15 +653,15 @@ export class DriveService {
}
@bindThis
public async update(file: MiDriveFile, values: Partial<MiDriveFile>, updater: MiUser) {
public async updateFile(file: MiDriveFile, values: Partial<MiDriveFile>, updater: MiUser) {
const alwaysMarkNsfw = (await this.roleService.getUserPolicies(file.userId)).alwaysMarkNsfw;
if (values.name && !this.driveFileEntityService.validateFileName(file.name)) {
throw new Error('invalid filename');
throw new DriveService.InvalidFileNameError();
}
if (values.isSensitive !== undefined && values.isSensitive !== file.isSensitive && alwaysMarkNsfw && !values.isSensitive) {
throw new Error('cannot unmark nsfw');
throw new DriveService.CannotUnmarkSensitiveError();
}
if (values.folderId != null) {
@@ -668,7 +671,7 @@ export class DriveService {
});
if (folder == null) {
throw new Error('folder-not-found');
throw new DriveService.NoSuchFolderError();
}
}