smartfile/ts/smartfile.classes.virtualdirectory.ts

58 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-10-02 13:26:53 +00:00
import { Smartfile } from './smartfile.classes.smartfile';
import * as plugins from './smartfile.plugins';
import * as fs from './smartfile.fs';
/**
* a virtual directory exposes a fs api
*/
export class VirtualDirectory {
2020-10-05 16:20:57 +00:00
// STATIC
public static async fromFsDirPath(pathArg: string): Promise<VirtualDirectory> {
2020-10-02 13:26:53 +00:00
const newVirtualDir = new VirtualDirectory();
newVirtualDir.addSmartfiles(await fs.fileTreeToObject(pathArg, '**/*'));
2020-10-02 14:34:09 +00:00
return newVirtualDir;
2020-10-02 13:29:40 +00:00
}
2020-10-02 13:26:53 +00:00
2020-10-05 16:20:57 +00:00
public static async fromVirtualDirTransferableObject(
virtualDirTransferableObjectArg: plugins.smartfileInterfaces.VirtualDirTransferableObject
): Promise<VirtualDirectory> {
const newVirtualDir = new VirtualDirectory();
for (const fileArg of virtualDirTransferableObjectArg.files) {
newVirtualDir.addSmartfiles([Smartfile.enfoldFromJson(fileArg) as Smartfile]);
}
return newVirtualDir;
}
// INSTANCE
private fileArray: Smartfile[] = [];
2020-10-02 13:26:53 +00:00
constructor() {}
public addSmartfiles(smartfileArrayArg: Smartfile[]) {
this.fileArray = this.fileArray.concat(smartfileArrayArg);
}
public async getFileByPath(pathArg: string) {
for (const smartfile of this.fileArray) {
if (smartfile.path === pathArg) {
return smartfile;
}
}
}
2020-10-05 16:20:57 +00:00
public async toVirtualDirTransferableObject(): Promise<plugins.smartfileInterfaces.VirtualDirTransferableObject> {
return {
files: this.fileArray.map(smartfileArg => smartfileArg.foldToJson())
};
}
2020-10-09 15:15:47 +00:00
public async saveToDisk() {
for (const smartfileArg of this.fileArray) {
}
}
2020-10-02 13:26:53 +00:00
// TODO implement root shifting to get subdirectories as new virtual directories
// TODO implement root shifting to combine VirtualDirecotries in a parent virtual directory
2020-10-02 13:29:40 +00:00
}