mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-31 23:28:34 -04:00
fix(media-upload): rework create and media services saveFile
This was done to make the create method more concise. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
ed5367d456
commit
62037acc97
2 changed files with 24 additions and 16 deletions
|
@ -3,7 +3,6 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import * as crypto from 'crypto';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
|
@ -53,24 +52,32 @@ export class MediaUpload {
|
|||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
||||
/**
|
||||
* Create a new media upload enity
|
||||
* @param id the id of the upload
|
||||
* @param note the note the upload should be associated with. This is required despite the fact the note field is optional, because it's possible to delete a note without also deleting the associated media uploads, but a note is required for the initial creation.
|
||||
* @param user the user that owns the upload
|
||||
* @param extension which file extension the upload has
|
||||
* @param backendType on which type of media backend the upload is saved
|
||||
* @param backendData the backend data returned by the media backend
|
||||
* @param fileUrl the url where the upload can be accessed
|
||||
*/
|
||||
public static create(
|
||||
id: string,
|
||||
note: Note,
|
||||
user: User,
|
||||
extension: string,
|
||||
backendType: BackendType,
|
||||
backendData?: string,
|
||||
backendData: BackendData | null,
|
||||
fileUrl: string,
|
||||
): Omit<MediaUpload, 'createdAt'> {
|
||||
const upload = new MediaUpload();
|
||||
const randomBytes = crypto.randomBytes(16);
|
||||
upload.id = randomBytes.toString('hex') + '.' + extension;
|
||||
upload.id = id;
|
||||
upload.note = note;
|
||||
upload.user = user;
|
||||
upload.backendType = backendType;
|
||||
if (backendData) {
|
||||
upload.backendData = backendData;
|
||||
} else {
|
||||
upload.backendData = null;
|
||||
}
|
||||
upload.backendData = backendData;
|
||||
upload.fileUrl = fileUrl;
|
||||
return upload;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue