aboutsummaryrefslogtreecommitdiff
path: root/vfs/example.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vfs/example.ts')
-rw-r--r--vfs/example.ts159
1 files changed, 159 insertions, 0 deletions
diff --git a/vfs/example.ts b/vfs/example.ts
new file mode 100644
index 0000000..bc8d37d
--- /dev/null
+++ b/vfs/example.ts
@@ -0,0 +1,159 @@
+import { WuiVfs, WuiVfsNodeInterface } from "./vfs.js"
+import { WuiResponseInterface } from "../response.js"
+
+interface PathNodeInterface {
+ [key: string]: WuiVfsNodeInterface
+}
+
+let dummyfs: PathNodeInterface = {
+ "/": {
+ name: "/",
+ path: "/",
+ is_dir: true,
+ content: "",
+ childs: [
+ {
+ name: "Dir 1",
+ path: "/Dir 1",
+ is_dir: true,
+ content: "",
+ childs: [
+ {
+ name: "File 1.1",
+ path: "/Dir 1/File 1.1",
+ is_dir: false,
+ content: "This is the content of File 1.1",
+ },
+ {
+ name: `File 1.2`,
+ path: "/Dir 1/File 1.2",
+ is_dir: false,
+ content: "This is the content of File 1.2",
+ },
+ ],
+ },
+ {
+ name: "Dir 2",
+ path: "/Dir 2",
+ is_dir: true,
+ content: "",
+ childs: [
+ {
+ name: "File 2.1",
+ path: "/Dir 2/File 2.1",
+ is_dir: false,
+ content: "This is the content of File 2.1",
+ },
+ {
+ name: "File 2.2",
+ path: "/Dir 2/File 2.2",
+ is_dir: false,
+ content: "This is the content of File 2.2",
+ },
+ ],
+ },
+ ],
+ },
+ "/Dir 1": {
+ name: "Dir 1",
+ path: "/Dir 1",
+ is_dir: true,
+ content: "",
+ childs: [
+ {
+ name: "File 1.1",
+ path: "/Dir 1/File 1.1",
+ is_dir: false,
+ content: "This is the content of File 1.1",
+ },
+ {
+ name: "File 1.2",
+ path: "/Dir 1/File 1.2",
+ is_dir: false,
+ content: "This is the content of File 1.2",
+ },
+ ],
+ },
+ "/Dir 2": {
+ name: "Dir 2",
+ path: "/Dir 2",
+ is_dir: true,
+ content: "",
+ childs: [
+ {
+ name: "File 2.1",
+ path: "/Dir 2/File 2.1",
+ is_dir: false,
+ content: "This is the content of File 2.1",
+ },
+ {
+ name: "File 2.2",
+ path: "/Dir 2/File 2.2",
+ is_dir: false,
+ content: "This is the content of File 2.2",
+ },
+ ],
+ }
+}
+
+async function main() {
+ let opts = {
+ id: "vfs",
+ Open: Open,
+ OpenNode: OpenNode,
+ }
+
+ let wui_vfs = new WuiVfs(opts)
+ wui_vfs.OpenDir("/")
+}
+
+async function Open(path: string, is_dir: boolean): Promise<WuiResponseInterface> {
+ console.log("Open:", path, is_dir)
+ let res: WuiResponseInterface = {
+ code: 200,
+ message: "",
+ }
+
+ if (is_dir) {
+ res.data = dummyfs[path]
+ return res
+ }
+
+ res.data = {
+ name: "",
+ path: path,
+ content: "",
+ }
+
+ switch (path) {
+ case "/Dir 1/File 1.1":
+ res.data.name = "File 1.1"
+ res.data.content = "This is the content of " + res.data.name
+ break
+ case "/Dir 1/File 1.2":
+ res.data.name = "File 1.2"
+ res.data.content = "This is the content of " + res.data.name
+ break
+ case "/Dir 2/File 2.1":
+ res.data.name = "File 2.1"
+ res.data.content = "This is the content of " + res.data.name
+ break
+ case "/Dir 2/File 2.2":
+ res.data.name = "File 2.1"
+ res.data.content = "This is the content of " + res.data.name
+ break
+ default:
+ res.code = 404
+ res.message = "path not found"
+ }
+
+ console.log("Open:", res)
+
+ return res
+}
+
+async function OpenNode(node: WuiVfsNodeInterface): Promise<WuiResponseInterface> {
+ return await Open(node.path, node.is_dir)
+}
+
+main()