diff options
| author | Shulhan <ms@kilabit.info> | 2023-11-22 13:16:21 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-12-01 13:17:30 +0700 |
| commit | a73f0d5d0108e2e10d89f93c7867addbe073add9 (patch) | |
| tree | 042e69e2c1d10d836a006abca37417af02bba826 /_wui | |
| parent | a9701f66c2e38a3a7f3d12deed6ebba5144e208e (diff) | |
| download | awwan-a73f0d5d0108e2e10d89f93c7867addbe073add9.tar.xz | |
all: refactoring HTTP endpoint for Execute
Previously, the Execute endpoint wait for command execution to finish.
In case the command takes longer than proxy or server write timeout, it
will return with an timeout error to client.
In this changes, we generate an execution ID for each request and return
it immediately.
The next commit will implement HTTP endpoint to fetch the latest status
and/or output by execution ID.
References: https://todo.sr.ht/~shulhan/awwan/5
Diffstat (limited to '_wui')
| -rw-r--r-- | _wui/awwan.ts | 30 | ||||
| -rw-r--r-- | _wui/main.js | 14 |
2 files changed, 22 insertions, 22 deletions
diff --git a/_wui/awwan.ts b/_wui/awwan.ts index fb3459c..9a6cc9b 100644 --- a/_wui/awwan.ts +++ b/_wui/awwan.ts @@ -36,13 +36,25 @@ const ID_OUTPUT = "output"; const MAX_FILE_SIZE = 1000000; // 1MiB -interface RequestInterface { +interface ExecRequestInterface { mode: string; script: string; content: string; line_range: string; } +interface ExecResponseInterface { + mode: string; + script: string; + line_range: string; + + id: string; + begin_at: string; + end_at: string; + error: string; + output: string[]; +} + interface encryptResponse { path: string; path_vault: string; @@ -126,7 +138,7 @@ export class Awwan { private comOutput!: HTMLElement; private comOutputWrapper!: HTMLElement; private currentNode: WuiVfsNodeInterface | null = null; - private request: RequestInterface = { + private request: ExecRequestInterface = { mode: "local", script: "", content: "", @@ -592,17 +604,11 @@ export class Awwan { return; } - if (res.data.output) { - this.comOutput.innerText = atob(res.data.output); - } + const execRes = res.data as ExecResponseInterface; - if (res.data.error) { - this.notif.error(res.data.error); - } else { - this.notif.info( - `Successfully execute ${this.request.script} on ${mode}.`, - ); - } + this.notif.info( + `Execute submitted ${execRes.script} on ${execRes.mode} with ID=${execRes.id}`, + ); } private async newNode(isDir: boolean) { diff --git a/_wui/main.js b/_wui/main.js index 7c243ab..925dd67 100644 --- a/_wui/main.js +++ b/_wui/main.js @@ -923,16 +923,10 @@ var awwan = (() => { this.notif.error(`Execute failed: ${res.message}`); return; } - if (res.data.output) { - this.comOutput.innerText = atob(res.data.output); - } - if (res.data.error) { - this.notif.error(res.data.error); - } else { - this.notif.info( - `Successfully execute ${this.request.script} on ${mode}.` - ); - } + const execRes = res.data; + this.notif.info( + `Execute submitted ${execRes.script} on ${execRes.mode} with ID=${execRes.id}` + ); } async newNode(isDir) { if (!this.currentNode) { |
