From 5ab4b95e3cf4b5fccfcd471c8b59b0c3b369be5b Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 21 Jun 2021 14:54:56 +0200 Subject: [PATCH] Support non-standard zip mime types in save upload Browser like Chrome doesn't use the application/zip mime type when uploading .zip files. Add support for application/x-zip-compressed to the save upload endpoint. --- packages/master/src/routes.js | 9 +++++++-- test/master/routes.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/master/src/routes.js b/packages/master/src/routes.js index 0843f79a..b6d7f741 100644 --- a/packages/master/src/routes.js +++ b/packages/master/src/routes.js @@ -259,6 +259,11 @@ async function getStream(req, res) { } +const zipMimes = [ + "application/zip", + "application/x-zip-compressed", +]; + async function uploadSave(req, res) { try { res.locals.user.checkPermission("core.instance.save.upload"); @@ -319,7 +324,7 @@ async function uploadSave(req, res) { requestErrors.push("instance_id must come before files uploaded"); } - if (fileMime !== "application/zip") { + if (!zipMimes.includes(fileMime)) { requestErrors.push("invalid file Content-Type"); } @@ -350,7 +355,7 @@ async function uploadSave(req, res) { req.pipe(busboy); }); - } else if (mimeType === "application/zip") { + } else if (zipMimes.includes(mimeType)) { let filename = req.query.filename; if (typeof filename !== "string") { requestErrors.push("Missing or invalid filename parameter"); diff --git a/test/master/routes.js b/test/master/routes.js index 7037be75..cca2c3b7 100644 --- a/test/master/routes.js +++ b/test/master/routes.js @@ -325,5 +325,25 @@ describe("master/src/routes", function() { assert.deepEqual(JSON.parse(response.body), { saves: ["test.zip"] }); assert.equal(response.statusCode, 200); }); + it("should complete a valid transfer with non-standerd mime type", async function() { + master.forwardRequestToInstance = async (request, data) => { + let stream = await phin({ + url: `http://localhost:${port}/api/stream/${data.stream_id}`, + }); + assert.equal(stream.body.toString(), "totally a zip file"); + return { save: data.filename }; + }; + let response; + response = await phin({ + url: `http://localhost:${port}/api/upload-save?instance_id=123&filename=test.zip`, method: "POST", + headers: { + "X-Access-Token": testToken, + "Content-Type": "application/x-zip-compressed", + }, + data: "totally a zip file", + }); + assert.deepEqual(JSON.parse(response.body), { saves: ["test.zip"] }); + assert.equal(response.statusCode, 200); + }); }); });