Skip to content

Commit

Permalink
fix mixed content
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelPull committed Oct 9, 2024
1 parent da58fc1 commit 9d85552
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
53 changes: 30 additions & 23 deletions api/src/handlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,44 @@ export const parseMultiPartFile = async (part: MultipartFile): Promise<any> => {

export const parseMultiPartRequest = async (request: AuthenticatedRequest): Promise<any> => {
let data = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let uploadedDocuments: any[] = [];
const parts = request.parts();
for await (const part of parts) {
if (part.type === "file") {
uploadedDocuments.push(await parseMultiPartFile(part));
} else {
// TODO if there is a mix of binary files and links, both with comments, this fails
if (part.fieldname.includes("comment_")) {
const index = parseInt(part.fieldname.split("_")[1]);
uploadedDocuments[index].comment = part.value;
continue;
}
if (part.fieldname === "apiVersion") {
continue;
} else if (part.fieldname === "tags") {
if (part.value === "") {
data[part.fieldname] = [];
} else {
data[part.fieldname] = (part.value as string).split(",");
switch (true) {
case part.fieldname.includes("link"): {
uploadedDocuments.push(JSON.parse(part.value as string));
break;
}
continue;
}
if (part.value === "null") {
data[part.fieldname] = undefined;
continue;
}
if (part.value === "undefined") {
data[part.fieldname] = undefined;
continue;
case part.fieldname.includes("comment_"): {
const index = parseInt(part.fieldname.split("_")[1]);
uploadedDocuments[index].comment = part.value;
break;
}
case part.fieldname === "apiVersion": {
break;
}
case part.fieldname === "tags": {
if (part.value === "") {
data[part.fieldname] = [];
} else {
data[part.fieldname] = (part.value as string).split(",");
}
break;
}
case part.value === "null":
data[part.fieldname] = undefined;
break;
case part.value === "undefined":
data[part.fieldname] = undefined;
break;
default:
data[part.fieldname] = part.value;
break;
}
data[part.fieldname] = part.value;
}
}
data["documents"] = uploadedDocuments;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ class Api {
const blob = base64ToBlob(documents[i].base64, documents[i].type); // data in redux store needs to be serializable, so we store base64 string
formData.append("documents", blob, documents[i].fileName);
formData.append(`comment_${i}`, documents[i].comment);
} else if (documents[i].link) {
formData.append(
`link_${i}`,
JSON.stringify({ link: documents[i].link, fileName: documents[i].fileName, comment: documents[i].comment })
);
}
}
}
Expand Down

0 comments on commit 9d85552

Please sign in to comment.