mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 20:45:13 +00:00
fix
This commit is contained in:
parent
4a7f6e6de4
commit
cf573add27
2 changed files with 28 additions and 11 deletions
|
@ -87,6 +87,9 @@ type UploadFromUrlArgs = {
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DriveService {
|
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 registerLogger: Logger;
|
||||||
private downloaderLogger: Logger;
|
private downloaderLogger: Logger;
|
||||||
private deleteLogger: Logger;
|
private deleteLogger: Logger;
|
||||||
|
@ -650,15 +653,15 @@ export class DriveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@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;
|
const alwaysMarkNsfw = (await this.roleService.getUserPolicies(file.userId)).alwaysMarkNsfw;
|
||||||
|
|
||||||
if (values.name && !this.driveFileEntityService.validateFileName(file.name)) {
|
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) {
|
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) {
|
if (values.folderId != null) {
|
||||||
|
@ -668,7 +671,7 @@ export class DriveService {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (folder == null) {
|
if (folder == null) {
|
||||||
throw new Error('folder-not-found');
|
throw new DriveService.NoSuchFolderError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,14 +89,28 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
throw new ApiError(meta.errors.accessDenied);
|
throw new ApiError(meta.errors.accessDenied);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileObj = await this.driveService.update(file, {
|
let packedFile;
|
||||||
folderId: ps.folderId,
|
|
||||||
name: ps.name,
|
|
||||||
isSensitive: ps.isSensitive,
|
|
||||||
comment: ps.comment,
|
|
||||||
}, me);
|
|
||||||
|
|
||||||
return fileObj;
|
try {
|
||||||
|
packedFile = await this.driveService.updateFile(file, {
|
||||||
|
folderId: ps.folderId,
|
||||||
|
name: ps.name,
|
||||||
|
isSensitive: ps.isSensitive,
|
||||||
|
comment: ps.comment,
|
||||||
|
}, me);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DriveService.InvalidFileNameError) {
|
||||||
|
throw new ApiError(meta.errors.invalidFileName);
|
||||||
|
} else if (e instanceof DriveService.NoSuchFolderError) {
|
||||||
|
throw new ApiError(meta.errors.noSuchFolder);
|
||||||
|
} else if (e instanceof DriveService.CannotUnmarkSensitiveError) {
|
||||||
|
throw new ApiError(meta.errors.restrictedByRole);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return packedFile;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue