From 23ba2026cc7642fb48afb59edebbc39934eabb52 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Fri, 16 Oct 2020 22:32:58 +0200 Subject: [PATCH] Do not save file extension as a separate field. It turned out that saving the file extension in a separate field is not necessary. Instead, the extension is saved in the complete filename in the `id` field. Signed-off-by: David Mehren --- docs/dev/db-schema.plantuml | 1 - src/media/media-upload.entity.ts | 15 ++++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/docs/dev/db-schema.plantuml b/docs/dev/db-schema.plantuml index 280a71ece..3ec0fb4a7 100644 --- a/docs/dev/db-schema.plantuml +++ b/docs/dev/db-schema.plantuml @@ -120,7 +120,6 @@ entity "MediaUpload" { -- *noteId : uuid <> *userId : uuid <> - *extension : text *backendType: text backendData: text *createdAt : date diff --git a/src/media/media-upload.entity.ts b/src/media/media-upload.entity.ts index 485f9a883..5ec8739b1 100644 --- a/src/media/media-upload.entity.ts +++ b/src/media/media-upload.entity.ts @@ -8,6 +8,9 @@ import { } from 'typeorm'; import { Note } from '../notes/note.entity'; import { User } from '../users/user.entity'; +import { BackendType } from './backends/backend-type.enum'; + +export type BackendData = string | null; @Entity() export class MediaUpload { @@ -20,11 +23,6 @@ export class MediaUpload { @ManyToOne(_ => User, { nullable: false }) user: User; - @Column({ - nullable: false, - }) - extension: string; - @Column({ nullable: false, }) @@ -33,7 +31,7 @@ export class MediaUpload { @Column({ nullable: true, }) - backendData: string | null; + backendData: BackendData; @CreateDateColumn() createdAt: Date; @@ -45,15 +43,14 @@ export class MediaUpload { note: Note, user: User, extension: string, - backendType: string, + backendType: BackendType, backendData?: string, ): MediaUpload { const upload = new MediaUpload(); const randomBytes = crypto.randomBytes(16); - upload.id = randomBytes.toString('hex'); + upload.id = randomBytes.toString('hex') + '.' + extension; upload.note = note; upload.user = user; - upload.extension = extension; upload.backendType = backendType; if (backendData) { upload.backendData = backendData;