mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-29 06:15:29 -04:00
feat: Add guest file uploads and add deletion for note owners
Signed-off-by: Yannick Bungers <git@innay.de> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
0f464dedfe
commit
485f7cd338
8 changed files with 244 additions and 68 deletions
|
@ -42,5 +42,5 @@ export class MediaUploadDto extends BaseDto {
|
|||
*/
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
username: string;
|
||||
username: string | null;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ export class MediaUpload {
|
|||
note: Promise<Note | null>;
|
||||
|
||||
@ManyToOne((_) => User, (user) => user.mediaUploads, {
|
||||
nullable: false,
|
||||
nullable: true,
|
||||
})
|
||||
user: Promise<User>;
|
||||
user: Promise<User | null>;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
|
@ -65,7 +65,7 @@ export class MediaUpload {
|
|||
public static create(
|
||||
id: string,
|
||||
note: Note,
|
||||
user: User,
|
||||
user: User | null,
|
||||
extension: string,
|
||||
backendType: BackendType,
|
||||
fileUrl: string,
|
||||
|
|
|
@ -78,13 +78,20 @@ export class MediaService {
|
|||
*/
|
||||
async saveFile(
|
||||
fileBuffer: Buffer,
|
||||
user: User,
|
||||
user: User | null,
|
||||
note: Note,
|
||||
): Promise<MediaUpload> {
|
||||
this.logger.debug(
|
||||
`Saving file for note '${note.id}' and user '${user.username}'`,
|
||||
'saveFile',
|
||||
);
|
||||
if (user) {
|
||||
this.logger.debug(
|
||||
`Saving file for note '${note.id}' and user '${user.username}'`,
|
||||
'saveFile',
|
||||
);
|
||||
} else {
|
||||
this.logger.debug(
|
||||
`Saving file for note '${note.id}' and not logged in user`,
|
||||
'saveFile',
|
||||
);
|
||||
}
|
||||
const fileTypeResult = await FileType.fromBuffer(fileBuffer);
|
||||
if (!fileTypeResult) {
|
||||
throw new ClientError('Could not detect file type.');
|
||||
|
@ -223,11 +230,12 @@ export class MediaService {
|
|||
}
|
||||
|
||||
async toMediaUploadDto(mediaUpload: MediaUpload): Promise<MediaUploadDto> {
|
||||
const user = await mediaUpload.user;
|
||||
return {
|
||||
url: mediaUpload.fileUrl,
|
||||
notePublicId: (await mediaUpload.note)?.publicId ?? null,
|
||||
createdAt: mediaUpload.createdAt,
|
||||
username: (await mediaUpload.user).username,
|
||||
username: user?.username ?? null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue