mirror of
https://github.com/sigmasternchen/tagify
synced 2025-03-15 07:08:55 +00:00
feat: preparations for new file attributes
This commit is contained in:
parent
d50c062d80
commit
1339ac275c
2 changed files with 66 additions and 3 deletions
|
@ -2,4 +2,7 @@ export const KEY_DIRECTORIES = "directories"
|
|||
export const KEY_FILES = "files"
|
||||
|
||||
export const KEY_FILE_PATH = "path"
|
||||
export const KEY_FILE_TAGS = "tags"
|
||||
export const KEY_FILE_TAGS = "tags"
|
||||
export const KEY_FILE_DESCRIPTION = "description"
|
||||
export const KEY_FILE_GROUP = "group"
|
||||
export const KEY_FILE_ORDINAL = "ordinal"
|
|
@ -1,15 +1,19 @@
|
|||
import {FileTypeFromExtension, MediaFileType} from "./file-type";
|
||||
import {KEY_FILE_PATH, KEY_FILE_TAGS} from "./config-keys";
|
||||
import {KEY_FILE_DESCRIPTION, KEY_FILE_GROUP, KEY_FILE_ORDINAL, KEY_FILE_PATH, KEY_FILE_TAGS} from "./config-keys";
|
||||
|
||||
export class MediaFile {
|
||||
private readonly path: string
|
||||
private readonly type: MediaFileType
|
||||
private description: string
|
||||
private group: string|null
|
||||
private ordinal: number|null
|
||||
private tags: string[]
|
||||
|
||||
constructor(path: string) {
|
||||
this.path = path
|
||||
this.type = FileTypeFromExtension(path)
|
||||
this.tags = []
|
||||
this.ordinal = 0
|
||||
}
|
||||
|
||||
public getPath(): string {
|
||||
|
@ -24,6 +28,22 @@ export class MediaFile {
|
|||
return this.tags
|
||||
}
|
||||
|
||||
public getDescription(): string {
|
||||
return this.description
|
||||
}
|
||||
|
||||
public setDescription(description: string) {
|
||||
this.description = description
|
||||
}
|
||||
|
||||
public getGroup(): string|null {
|
||||
return this.group
|
||||
}
|
||||
|
||||
public setGroup(group: string) {
|
||||
this.group = group
|
||||
}
|
||||
|
||||
public addTag(tag: string) {
|
||||
if (this.tags.indexOf(tag) < 0) {
|
||||
this.tags.push(tag)
|
||||
|
@ -41,7 +61,6 @@ export class MediaFile {
|
|||
return this.tags.indexOf(tag) >= 0
|
||||
}
|
||||
|
||||
|
||||
static fromRaw(obj: any): MediaFile {
|
||||
if (typeof obj[KEY_FILE_PATH] != "string") {
|
||||
throw "path attribute has to be string"
|
||||
|
@ -59,6 +78,21 @@ export class MediaFile {
|
|||
return t
|
||||
})
|
||||
|
||||
file.description = ""
|
||||
if (typeof obj[KEY_FILE_DESCRIPTION] == "string") {
|
||||
file.description = obj[KEY_FILE_DESCRIPTION]
|
||||
}
|
||||
|
||||
file.group = null
|
||||
if (typeof obj[KEY_FILE_GROUP] == "string") {
|
||||
file.group = obj[KEY_FILE_GROUP]
|
||||
}
|
||||
|
||||
file.ordinal = null
|
||||
if (typeof obj[KEY_FILE_ORDINAL] == "number") {
|
||||
file.ordinal = obj[KEY_FILE_ORDINAL]
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
|
@ -69,6 +103,12 @@ export class MediaFile {
|
|||
obj[KEY_FILE_PATH] = this.path
|
||||
// @ts-ignore
|
||||
obj[KEY_FILE_TAGS] = this.tags
|
||||
// @ts-ignore
|
||||
obj[KEY_FILE_DESCRIPTION] = this.description
|
||||
// @ts-ignore
|
||||
obj[KEY_FILE_GROUP] = this.group
|
||||
// @ts-ignore
|
||||
obj[KEY_FILE_ORDINAL] = this.ordinal
|
||||
|
||||
return obj
|
||||
}
|
||||
|
@ -78,4 +118,24 @@ export class MediaFile {
|
|||
clone.tags = [...this.tags]
|
||||
return clone
|
||||
}
|
||||
|
||||
public compareTo(file: MediaFile): number {
|
||||
if (!this.group) {
|
||||
if (!file.group) {
|
||||
return this.path.localeCompare(file.path)
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
if (file.group) {
|
||||
if (this.group != file.group) {
|
||||
return this.group.localeCompare(file.group)
|
||||
} else {
|
||||
return this.ordinal > file.ordinal ? 1 : -1
|
||||
}
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue