admin: default timeout of 10 seconds for api calls

Massimo Melina committed Apr 9, 2022 at 12:20 UTC b4e6ea04791ebd560f0f46703d1dc3f1cec91da8
4 files changed +7
.gitignore
+1
@@ -4,6 +4,7 @@ dist
4 #produced by running
5 counters.yaml
6 *.log*
7 +self.*
8 config.yaml
9 accounts.yaml
10 shared/lib
README.md
+1
@@ -35,6 +35,7 @@ As you can see from the list above, we already have some goods that you can't fi
35 - more robust
36 - plugins system
37 - ZIP format for archives instead of TAR
38 +- more flexible permissions
39
40 ### Why you should still stay with HFS 2.x (so far)
41
admin/src/api.ts
+4
@@ -21,9 +21,13 @@ const PREFIX = '/~/api/'
21
22 export function apiCall(cmd: string, params?: Dict) : Promise<any> {
23 params = addCsrf(params)
24 +
25 + const controller = new AbortController()
26 + setTimeout(() => controller.abort(), 10_000)
27 return fetch(PREFIX+cmd, {
28 method: 'POST',
29 headers: { 'content-type': 'application/json' },
30 + signal: controller.signal,
31 body: params && JSON.stringify(params),
32 }).then(async res => {
33 if (res.ok)
tests/config.yaml
+1
@@ -74,6 +74,7 @@ vfs:
74 - name: hi
75 accounts:
76 rejetto:
77 + password: password
78 belongs:
79 - admins
80 admins: