Initial commit
This commit is contained in:
132
src/models/collection.ts
Normal file
132
src/models/collection.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Class model for FileCollection Interface
|
||||
*/
|
||||
import type { FileCollection } from "@/types/node";
|
||||
|
||||
export class FileCollectionObject implements FileCollection {
|
||||
|
||||
_data!: FileCollection;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'files.collection',
|
||||
in: null,
|
||||
id: '',
|
||||
createdBy: '',
|
||||
createdOn: '',
|
||||
modifiedBy: '',
|
||||
modifiedOn: '',
|
||||
owner: '',
|
||||
signature: '',
|
||||
label: '',
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: FileCollection): FileCollectionObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): FileCollection {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): FileCollectionObject {
|
||||
const cloned = new FileCollectionObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get '@type'(): 'files.collection' {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get in(): string | null {
|
||||
return this._data.in;
|
||||
}
|
||||
|
||||
set in(value: string | null) {
|
||||
this._data.in = value;
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
set id(value: string) {
|
||||
this._data.id = value;
|
||||
}
|
||||
|
||||
get createdBy(): string {
|
||||
return this._data.createdBy;
|
||||
}
|
||||
|
||||
set createdBy(value: string) {
|
||||
this._data.createdBy = value;
|
||||
}
|
||||
|
||||
get createdOn(): string {
|
||||
return this._data.createdOn;
|
||||
}
|
||||
|
||||
set createdOn(value: string) {
|
||||
this._data.createdOn = value;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/** Helper methods */
|
||||
|
||||
get isRoot(): boolean {
|
||||
return this._data.id === '00000000-0000-0000-0000-000000000000';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
200
src/models/entity.ts
Normal file
200
src/models/entity.ts
Normal file
@@ -0,0 +1,200 @@
|
||||
/**
|
||||
* Class model for FileEntity Interface
|
||||
*/
|
||||
import type { FileEntity } from "@/types/node";
|
||||
|
||||
export class FileEntityObject implements FileEntity {
|
||||
|
||||
_data!: FileEntity;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'files.entity',
|
||||
in: null,
|
||||
id: '',
|
||||
createdBy: '',
|
||||
createdOn: '',
|
||||
modifiedBy: '',
|
||||
modifiedOn: '',
|
||||
owner: '',
|
||||
signature: '',
|
||||
label: '',
|
||||
size: 0,
|
||||
mime: '',
|
||||
format: '',
|
||||
encoding: '',
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: FileEntity): FileEntityObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): FileEntity {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): FileEntityObject {
|
||||
const cloned = new FileEntityObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get '@type'(): 'files.entity' {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get in(): string | null {
|
||||
return this._data.in;
|
||||
}
|
||||
|
||||
set in(value: string | null) {
|
||||
this._data.in = value;
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
set id(value: string) {
|
||||
this._data.id = value;
|
||||
}
|
||||
|
||||
get createdBy(): string {
|
||||
return this._data.createdBy;
|
||||
}
|
||||
|
||||
set createdBy(value: string) {
|
||||
this._data.createdBy = value;
|
||||
}
|
||||
|
||||
get createdOn(): string {
|
||||
return this._data.createdOn;
|
||||
}
|
||||
|
||||
set createdOn(value: string) {
|
||||
this._data.createdOn = value;
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
}
|
||||
8
src/models/index.ts
Normal file
8
src/models/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Central export point for all File Manager models
|
||||
*/
|
||||
|
||||
export { FileCollectionObject } from './collection';
|
||||
export { FileEntityObject } from './entity';
|
||||
export { ProviderObject } from './provider';
|
||||
export { ServiceObject } from './service';
|
||||
63
src/models/provider.ts
Normal file
63
src/models/provider.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Class model for Provider Interface
|
||||
*/
|
||||
import type { ProviderCapabilitiesInterface, ProviderInterface } from "@/types/provider";
|
||||
|
||||
export class ProviderObject implements ProviderInterface {
|
||||
|
||||
_data!: ProviderInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'files:provider',
|
||||
id: '',
|
||||
label: '',
|
||||
capabilities: {},
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: ProviderInterface): ProviderObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): ProviderInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): ProviderObject {
|
||||
const cloned = new ProviderObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
|
||||
return !!(this._data.capabilities && this._data.capabilities[capability]);
|
||||
}
|
||||
|
||||
capability(capability: keyof ProviderCapabilitiesInterface): boolean | string[] | Record<string, string> | Record<string, string[]> | undefined {
|
||||
if (this._data.capabilities) {
|
||||
return this._data.capabilities[capability];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Immutable Properties */
|
||||
|
||||
get '@type'(): string {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
get capabilities(): ProviderCapabilitiesInterface {
|
||||
return this._data.capabilities;
|
||||
}
|
||||
|
||||
}
|
||||
57
src/models/service.ts
Normal file
57
src/models/service.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Class model for Service Interface
|
||||
*/
|
||||
import type { ServiceInterface } from "@/types/service";
|
||||
|
||||
export class ServiceObject implements ServiceInterface {
|
||||
|
||||
_data!: ServiceInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'files:service',
|
||||
id: '',
|
||||
provider: '',
|
||||
label: '',
|
||||
rootId: '',
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: ServiceInterface): ServiceObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): ServiceInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): ServiceObject {
|
||||
const cloned = new ServiceObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Immutable Properties */
|
||||
|
||||
get '@type'(): string {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
get provider(): string {
|
||||
return this._data.provider;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
get rootId(): string {
|
||||
return this._data.rootId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user