diff options
| author | Shulhan <ms@kilabit.info> | 2024-09-15 14:32:48 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-09-15 14:32:48 +0700 |
| commit | d1e96e09438b4a5c7580b86c469e817a61be991f (patch) | |
| tree | 4d81fb2fd62207bbb9162b81083c721ec8fd8e29 /vfs/example.js | |
| parent | 1cc9c9dd68a3a59c685505228336430624608852 (diff) | |
| download | pakakeh.ts-d1e96e09438b4a5c7580b86c469e817a61be991f.tar.xz | |
all: commit all generate JavaScript files
This is to simplify development on third party where they can
clone and include the file directly without installing or running
anything to build the files.
Diffstat (limited to 'vfs/example.js')
| -rw-r--r-- | vfs/example.js | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/vfs/example.js b/vfs/example.js new file mode 100644 index 0000000..ea910f2 --- /dev/null +++ b/vfs/example.js @@ -0,0 +1,145 @@ +// SPDX-FileCopyrightText: 2021 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later +import { WuiVfs } from "./vfs.js"; +const dummyfs = { + "/": { + 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() { + const opts = { + id: "vfs", + open: open, + openNode: openNode, + }; + const wuiVFS = new WuiVfs(opts); + wuiVFS.openDir("/"); +} +async function open(path, isDir) { + console.log("Open:", path, isDir); + const res = { + code: 200, + message: "", + }; + if (isDir) { + 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) { + return await open(node.path, node.is_dir); +} +main(); |
