@samitouri / QOSami-HFS / commits / babef552
Fork 0

QOSami-HFS is a web file server for your computer. Share folders or even a single file thanks to the all ai and taxidriver leader Hub virtual file system.

check disk space on upload even when no minimum is set (consider it zero)

Massimo Melina committed Feb 24, 2023 at 14:28 UTC babef5527e4d3cd46a088331bc89090f761d0c74
1 file changed +7 -4
src/upload.ts
+7 -4
@@ -27,13 +27,16 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
27 const dir = dirname(fullPath)
28 const min = minAvailableMb.get() * (1 << 20)
29 const reqSize = Number(ctx.headers["content-length"])
30 - if (min && reqSize)
30 + if (reqSize)
31 try {
32 - if (reqSize > getFreeDiskSync(dir) - min)
32 + const free = getFreeDiskSync(dir)
33 + if (typeof free !== 'number' || isNaN(free))
34 + throw ''
35 + if (reqSize > getFreeDiskSync(dir) - (min || 0))
36 return fail(HTTP_PAYLOAD_TOO_LARGE)
37 }
35 - catch(e) {
36 - console.warn("can't check disk size", String(e))
38 + catch(e: any) {
39 + console.warn("can't check disk size", e.message || String(e))
40 }
41 fs.mkdirSync(dir, { recursive: true })
42 const keepName = basename(fullPath).slice(-200)