From 359eca7bbc667310d7e5642e928971e497afeaa3 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 11 Aug 2021 13:08:27 -0700 Subject: [PATCH] Fix upload metadata missing when behind nginx --- lib/ui/api.ts | 8 ++++---- ui/files-page.ts | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/ui/api.ts b/lib/ui/api.ts index 3629805..8d279c2 100644 --- a/lib/ui/api.ts +++ b/lib/ui/api.ts @@ -509,11 +509,11 @@ router.put("/files/:id", async (ctx) => { } const metadata = { - fileType: singleParam(ctx.request.headers["metadata.filetype"]) || "", - oui: singleParam(ctx.request.headers["metadata.oui"]) || "", + fileType: singleParam(ctx.request.headers["metadata-filetype"]) || "", + oui: singleParam(ctx.request.headers["metadata-oui"]) || "", productClass: - singleParam(ctx.request.headers["metadata.productclass"]) || "", - version: singleParam(ctx.request.headers["metadata.version"]) || "", + singleParam(ctx.request.headers["metadata-productclass"]) || "", + version: singleParam(ctx.request.headers["metadata-version"]) || "", }; const validate = authorizer.getValidator(resource, metadata); diff --git a/ui/files-page.ts b/ui/files-page.ts index 88c9f2b..37ae82b 100644 --- a/ui/files-page.ts +++ b/ui/files-page.ts @@ -204,14 +204,20 @@ export const component: ClosureComponent = (): Component => { putFormComponent, Object.assign( { - actionHandler: async (action, _object) => { + actionHandler: async (action, obj) => { if (action !== "save") throw new Error("Undefined action"); - const object = Object.assign({}, _object); - const file = object["file"] - ? object["file"][0] - : null; - delete object["file"]; + const file = obj["file"] ? obj["file"][0] : null; + + // nginx strips out headers with dot, so replace with dash + const headers = { + "metadata-fileType": obj["metadata.fileType"] || "", + "metadata-oui": obj["metadata.oui"] || "", + "metadata-productclass": + obj["metadata.productClass"] || "", + "metadata-version": obj["metadata.version"] || "", + }; + if (!file) { notifications.push("error", "File not selected"); return; @@ -232,7 +238,7 @@ export const component: ClosureComponent = (): Component => { try { await upload( file, - object, + headers, abortController.signal, progressListener );