disconnect long uploads if they are failing
Massimo Melina committed
Apr 25, 2024 at 12:53 UTC
90d6d576880030d238772aa63c01937bd8dc5c86
1 file changed
+8
-2
src/upload.ts
+8
-2
@@ -12,7 +12,7 @@ import { Callback, dirTraversal, escapeHTML, loadFileAttr, storeFileAttr, try_ }
12
import { notifyClient } from './frontEndApis'
13
import { defineConfig } from './config'
14
import { getDiskSpaceSync } from './util-os'
15
-import { updateConnection, updateConnectionForCtx } from './connections'
15
+import { disconnect, updateConnection, updateConnectionForCtx } from './connections'
16
import { roundSpeed } from './throttler'
17
import { getCurrentUsername } from './auth'
18
import { setCommentFor } from './comments'
@@ -41,8 +41,14 @@ const cache: any = {}
41
export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
42
if (dirTraversal(path))
43
return fail(HTTP_FOOL)
44
- if (statusCodeForMissingPerm(base, 'can_upload', ctx))
44
+ if (statusCodeForMissingPerm(base, 'can_upload', ctx)) {
45
+ if (!ctx.get('x-hfs-wait')) { // you can disable the following behavior
46
+ // avoid waiting hours for just an error
47
+ const t = setTimeout(() => disconnect(ctx), 30_000)
48
+ ctx.res.on('finish', () => clearTimeout(t))
49
+ }
50
return fail()
51
+ }
52
const fullPath = join(base.source!, path)
53
const dir = dirname(fullPath)
54
const min = minAvailableMb.get() * (1 << 20)