mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
MediaService: Change deleteFile
The former deleteFile was moved to the public apis media controller and the actual deletion functionality was moved in a separate function to be called on user deletion. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
63fcca6c0d
commit
f6121b58e8
3 changed files with 25 additions and 48 deletions
|
@ -132,7 +132,23 @@ export class MediaController {
|
|||
): Promise<void> {
|
||||
const username = req.user.userName;
|
||||
try {
|
||||
await this.mediaService.deleteFile(filename, username);
|
||||
this.logger.debug(
|
||||
`Deleting '${filename}' for user '${username}'`,
|
||||
'deleteFile',
|
||||
);
|
||||
const mediaUpload = await this.mediaService.findUploadByFilename(
|
||||
filename,
|
||||
);
|
||||
if (mediaUpload.user.userName !== username) {
|
||||
this.logger.warn(
|
||||
`${username} tried to delete '${filename}', but is not the owner`,
|
||||
'deleteFile',
|
||||
);
|
||||
throw new PermissionError(
|
||||
`File '${filename}' is not owned by '${username}'`,
|
||||
);
|
||||
}
|
||||
await this.mediaService.deleteFile(mediaUpload);
|
||||
} catch (e) {
|
||||
if (e instanceof PermissionError) {
|
||||
throw new UnauthorizedException(e.message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue