From 3a95396b773c3bfb5f8a407e256f98d926297002 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 10 Apr 2018 18:18:12 +0100 Subject: WIP: Add support for raw and meta views --- src/db/model/File.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'src/db/model/File.ts') 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 { @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 { @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 { 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'; + } } -- cgit v1.2.1 From 4ec93e886fc10de2c65e9599dbfca2a70db578e3 Mon Sep 17 00:00:00 2001 From: jw255 Date: Mon, 16 Apr 2018 19:34:57 +0100 Subject: World War Files, part 1\nRoot folder is automatically created at the start of the server. also project folder should now appear in the filesystem --- src/db/model/File.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/db/model/File.ts') diff --git a/src/db/model/File.ts b/src/db/model/File.ts index 4026b85..193a785 100644 --- a/src/db/model/File.ts +++ b/src/db/model/File.ts @@ -5,6 +5,24 @@ import { default as User } from './User'; import { FileTypeName, mimes } from '../../files'; +/* + * attributes: + * - nameInternal + * - fullPathInternal + * - uuid + * - type + * - size + * - parentFolderId + * - containedFilesInternal + * - creatorName + * - creator + * - rootFolderOf + * - uploadDate + * - modifyDate + * - status + * - metadataInternal +*/ + @Table export default class File extends Model { @AllowNull -- cgit v1.2.1 From 8f1837af9400ef0ef5c1cab1e853b46e11b1b76b Mon Sep 17 00:00:00 2001 From: jw255 Date: Tue, 17 Apr 2018 18:43:06 +0100 Subject: Files - now actually works --- src/db/model/File.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/db/model/File.ts') diff --git a/src/db/model/File.ts b/src/db/model/File.ts index 193a785..8a12431 100644 --- a/src/db/model/File.ts +++ b/src/db/model/File.ts @@ -27,7 +27,7 @@ import { FileTypeName, mimes } from '../../files'; export default class File extends Model { @AllowNull @Column - private nameInternal!: string; + public nameInternal!: string; @AllowNull @Column @@ -85,10 +85,14 @@ export default class File extends Model { public set name(name: string) { this.nameInternal = name; - this.fullPathInternal = this.fullPathInternal.substring( - 0, - this.fullPathInternal.lastIndexOf('/') + 1 - ) + this.name; + if (this.fullPathInternal) { + this.fullPathInternal = this.fullPathInternal.substring( + 0, + this.fullPathInternal.lastIndexOf('/') + 1 + ) + this.name; + } else { + this.fullPathInternal = this.name; + } } public get fullPath(): string { -- cgit v1.2.1