@samitouri / QOSami-HFS / commits / 193d71bc

better logging

Massimo Melina committed Apr 30, 2025 at 12:58 UTC 193d71bc5a42346f1e12665105d55cd6edbfc7c8
3 files changed +11 -7
src/middlewares.ts
+4 -1
@@ -134,7 +134,10 @@ export function failAllowNet(ctx: Koa.Context, a: Account | undefined) {
134 const mask = cached ?? getFromAccount(a || '', a => a.allow_net)
135 if (!cached && mask && ctx.session?.username)
136 ctx.session.allowNet = mask // must be deleted on logout by setLoggedIn
137 - return mask && !netMatches(ctx.ip, mask, true)
137 + const ret = mask && !netMatches(ctx.ip, mask, true)
138 + if (ret)
139 + console.debug("login failed: allow_net")
140 + return ret
141 }
142
143 declare module "koa" {
src/upload.ts
+5 -5
@@ -225,6 +225,7 @@ export function uploadWriter(base: VfsNode, baseUri: string, path: string, ctx:
225 void setCommentFor(dest, String(ctx.query.comment))
226 obj.uri = enforceFinal('/', baseUri) + pathEncode(basename(dest))
227 events.emit('uploadFinished', obj)
228 + console.debug("upload finished", dest)
229 if (resEvent) for (const cb of resEvent)
230 if (_.isFunction(cb))
231 cb(obj)
@@ -307,14 +308,13 @@ export function uploadWriter(base: VfsNode, baseUri: string, path: string, ctx:
308 uploadingFiles.delete(fullPath)
309 }
310
310 - function fail(status?: number, msg?: string) {
311 - console.debug('upload failed', status||'', msg||'')
311 + function fail(status=ctx.status, msg?: string) {
312 + console.debug('upload failed', status, msg||'')
313 releaseFile()
313 - if (status)
314 - ctx.status = status
314 + ctx.status = status
315 if (msg)
316 ctx.body = msg
317 - notifyClient(ctx, UPLOAD_REQUEST_STATUS, { [path]: ctx.status }) // allow browsers to detect failure while still sending body
317 + notifyClient(ctx, UPLOAD_REQUEST_STATUS, { [path]: status }) // allow browsers to detect failure while still sending body
318 }
319 }
320
tests/test.ts
+2 -1
@@ -131,8 +131,9 @@ describe('basics', () => {
131 test('upload.need account', reqUpload( UPLOAD_DEST, 401))
132 test('upload.post', () => // this is also testing basic-auth
133 promisify(exec)(`curl -u ${username}:${password} -F upload=@${SAMPLE_FILE_PATH} ${BASE_URL}${UPLOAD_ROOT}`).then(x => {
134 - const fn = resolve(__dirname, basename(decodeURI(tryJson(x.stdout)?.uris?.[0])))
134 + let fn = tryJson(x.stdout)?.uris?.[0]
135 if (!fn) throw "unexpected output " + (x.stdout || x.stderr)
136 + fn = resolve(__dirname, basename(decodeURI(fn)))
137 const stats = statSync(fn)
138 rm(fn).catch(() => {}) // clear
139 if (stats?.size !== statSync(SAMPLE_FILE_PATH).size)