aboutsummaryrefslogtreecommitdiff
path: root/vfs/vfs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vfs/vfs.ts')
-rw-r--r--vfs/vfs.ts31
1 files changed, 20 insertions, 11 deletions
diff --git a/vfs/vfs.ts b/vfs/vfs.ts
index 7372166..331a22b 100644
--- a/vfs/vfs.ts
+++ b/vfs/vfs.ts
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import { WuiResponseInterface } from "../response"
+
export interface WuiVfsNodeInterface {
name: string
path: string
@@ -15,22 +17,26 @@ export interface WuiVfsNodeInterface {
content?: string
}
-export interface WuiVfsResponseInterface {
- code: number
- message?: string
- data?: WuiVfsNodeInterface | WuiPathNodeInterface
-}
-
export interface WuiVfsOptions {
id: string
- ListNodes: () => WuiPathNodeInterface
+ ListNodes: () => WuiResponseInterface
// OnClickNode define an handler that will be called everytime a node is
// clicked. The is_dir will be true, if the node is a directory.
OnClickNode(path: string, is_dir: boolean): void
}
+export async function NewWuiVfs(opts: WuiVfsOptions): Promise<WuiResponseInterface> {
+ let vfs = new WuiVfs(opts)
+ let res = await vfs.init()
+ if (res.code != 200) {
+ return res
+ }
+ res.data = vfs
+ return res
+}
+
export class WuiVfs {
private el!: HTMLElement
private com_path!: WuiVfsPath
@@ -52,13 +58,14 @@ export class WuiVfs {
// (2) Create the WuiVfsList
// (3) Open the root "/"
//
- private async init() {
+ async init(): Promise<WuiResponseInterface> {
// (0)
- let res_path_node = await this.opts.ListNodes()
- if (!res_path_node) {
- return
+ let res = await this.opts.ListNodes()
+ if (res.code != 200) {
+ return res
}
+ let res_path_node = res.data as WuiPathNodeInterface
for (const key in res_path_node) {
const value = res_path_node[key] as WuiVfsNodeInterface
const node = new WuiVfsNode(value, (node: WuiVfsNode) => {
@@ -86,6 +93,8 @@ export class WuiVfs {
// (3)
this.open(this.path_node["/"])
+
+ return res
}
private open(node: WuiVfsNode) {