Fix upload metadata missing when behind nginx

This commit is contained in:
Zaid Abdulla committed 2021-08-11 13:08:27 -07:00
1 parent 088e25cbb0
commit 359eca7bbc
2 files changed
+17 -11

No files matched your search

+4 -4
View File
@@ -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);
+13 -7
View File
@@ -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
);