diff options
Diffstat (limited to 'src/db/model')
| -rw-r--r-- | src/db/model/File.ts | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/src/db/model/File.ts b/src/db/model/File.ts index 33043f0..4026b85 100644 --- a/src/db/model/File.ts +++ b/src/db/model/File.ts @@ -3,18 +3,27 @@ import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, HasOne, Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript'; import { default as User } from './User'; +import { FileTypeName, mimes } from '../../files'; + @Table export default class File extends Model<File> { @AllowNull @Column - public name!: string; + private nameInternal!: string; + + @AllowNull + @Column + private fullPathInternal!: string; @PrimaryKey @Column public uuid!: string; + @Column(DataType.TEXT) + public type!: FileTypeName; + @Column - public mimetype!: string; + public size!: number; @ForeignKey(() => File) @AllowNull @@ -46,6 +55,35 @@ export default class File extends Model<File> { @Column(DataType.DATE) public modifyDate!: Date; + @Column + public status!: string; + + @Column + private metadataInternal!: string; + + public get name(): string { + return this.nameInternal; + } + + public set name(name: string) { + this.nameInternal = name; + this.fullPathInternal = this.fullPathInternal.substring( + 0, + this.fullPathInternal.lastIndexOf('/') + 1 + ) + this.name; + } + + public get fullPath(): string { + return this.fullPathInternal; + } + + public set fullPath(path: string) { + this.fullPathInternal = path; + this.nameInternal = this.fullPath.substring( + this.fullPathInternal.lastIndexOf('/') + 1 + ); + } + public get containedFiles(): File[] { if (this.containedFilesInternal === undefined) { throw new Error('containedFiles is undefined'); @@ -56,4 +94,16 @@ export default class File extends Model<File> { public set containedFiles(files: File[]) { this.containedFilesInternal = files; } + + public get metadata(): object { + return JSON.parse(this.metadataInternal); + } + + public set metadata(metadata: object) { + this.metadataInternal = JSON.stringify(metadata); + } + + public set mimetype(mime: string) { + this.type = mimes.get(mime) || 'generic'; + } } |
