refactor: front end

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-03-28 12:47:21 -04:00
parent 28e5cce23a
commit ccb781f933
38 changed files with 4909 additions and 2897 deletions
+65 -161
View File
@@ -1,200 +1,104 @@
/**
* Class model for FileEntity Interface
* Class model for Entity Interface
*/
import type { FileEntity } from "@/types/node";
import type { EntityInterface, EntityModelInterface } from "@/types/entity";
import type { DocumentInterface, DocumentModelInterface } from "@/types/document";
import { DocumentObject } from "./document";
export class FileEntityObject implements FileEntity {
export class EntityObject implements EntityModelInterface {
_data!: FileEntity;
_data!: EntityInterface<DocumentInterface|DocumentModelInterface>;
constructor() {
this._data = {
'@type': 'files.entity',
in: null,
id: '',
createdBy: '',
createdOn: '',
modifiedBy: '',
modifiedOn: '',
owner: '',
signature: '',
label: '',
size: 0,
mime: '',
format: '',
encoding: '',
'@type': '',
schema: 1,
provider: '',
service: '',
collection: '',
identifier: '',
signature: null,
created: null,
modified: null,
properties: new DocumentObject(),
};
}
fromJson(data: FileEntity): FileEntityObject {
this._data = data;
fromJson(data: EntityInterface): EntityObject {
this._data = data
if (data.properties) {
this._data.properties = new DocumentObject().fromJson(data.properties as DocumentInterface);
}
return this;
}
toJson(): FileEntity {
return this._data;
toJson(): EntityInterface {
const json = { ...this._data }
if (this._data.properties instanceof DocumentObject) {
json.properties = this._data.properties.toJson();
}
return json as EntityInterface
}
clone(): FileEntityObject {
const cloned = new FileEntityObject();
cloned._data = JSON.parse(JSON.stringify(this._data));
return cloned;
clone(): EntityObject {
const cloned = new EntityObject()
cloned._data = { ...this._data }
cloned._data.properties = this.properties.clone();
return cloned
}
/** Properties */
/** Immutable Properties */
get '@type'(): 'files.entity' {
return this._data['@type'];
get provider(): string {
return this._data.provider
}
get in(): string | null {
return this._data.in;
get schema(): number {
return this._data.schema
}
set in(value: string | null) {
this._data.in = value;
get service(): string {
return this._data.service
}
get id(): string {
return this._data.id;
get collection(): string | number {
return this._data.collection
}
set id(value: string) {
this._data.id = value;
get identifier(): string | number {
return this._data.identifier
}
get createdBy(): string {
return this._data.createdBy;
get signature(): string | null {
return this._data.signature
}
set createdBy(value: string) {
this._data.createdBy = value;
get created(): Date | null {
return this._data.created ? new Date(this._data.created) : null
}
get createdOn(): string {
return this._data.createdOn;
get modified(): Date | null {
return this._data.modified ? new Date(this._data.modified) : null
}
set createdOn(value: string) {
this._data.createdOn = value;
get properties(): DocumentObject {
if (this._data.properties instanceof DocumentObject) {
return this._data.properties
}
if (this._data.properties) {
const hydrated = new DocumentObject().fromJson(this._data.properties as DocumentInterface)
this._data.properties = hydrated
return hydrated
}
const defaultProperties = new DocumentObject()
this._data.properties = defaultProperties
return defaultProperties
}
get modifiedBy(): string {
return this._data.modifiedBy;
}
set modifiedBy(value: string) {
this._data.modifiedBy = value;
}
get modifiedOn(): string {
return this._data.modifiedOn;
}
set modifiedOn(value: string) {
this._data.modifiedOn = value;
}
get owner(): string {
return this._data.owner;
}
set owner(value: string) {
this._data.owner = value;
}
get signature(): string {
return this._data.signature;
}
set signature(value: string) {
this._data.signature = value;
}
get label(): string {
return this._data.label;
}
set label(value: string) {
this._data.label = value;
}
get size(): number {
return this._data.size;
}
set size(value: number) {
this._data.size = value;
}
get mime(): string {
return this._data.mime;
}
set mime(value: string) {
this._data.mime = value;
}
get format(): string {
return this._data.format;
}
set format(value: string) {
this._data.format = value;
}
get encoding(): string {
return this._data.encoding;
}
set encoding(value: string) {
this._data.encoding = value;
}
/** Helper methods */
get createdOnDate(): Date | null {
return this._data.createdOn ? new Date(this._data.createdOn) : null;
}
get modifiedOnDate(): Date | null {
return this._data.modifiedOn ? new Date(this._data.modifiedOn) : null;
}
get extension(): string {
const parts = this._data.label.split('.');
return parts.length > 1 ? parts[parts.length - 1] : '';
}
get sizeFormatted(): string {
const bytes = this._data.size;
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
get isImage(): boolean {
return this._data.mime.startsWith('image/');
}
get isVideo(): boolean {
return this._data.mime.startsWith('video/');
}
get isAudio(): boolean {
return this._data.mime.startsWith('audio/');
}
get isText(): boolean {
return this._data.mime.startsWith('text/') ||
this._data.mime === 'application/json' ||
this._data.mime === 'application/xml';
}
get isPdf(): boolean {
return this._data.mime === 'application/pdf';
set properties(value: DocumentObject) {
this._data.properties = value
}
}