Skip to content

Commit

Permalink
Use mime-types for extension in download
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed May 1, 2024
1 parent c12b649 commit 82ecf58
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions node/src/handlers/get-file-set-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { apiTokenName } = require("../environment");
const ApiToken = require("../api/api-token");
const axios = require("axios").default;
const cookie = require("cookie");

const mime = require("mime-types");
const opensearchResponse = require("../api/response/opensearch");
const path = require("path");

Expand Down Expand Up @@ -104,14 +104,6 @@ function derivativeKey(doc) {
return "derivatives/" + prefix + "/" + id;
}

function extensionFromMimeType(mimeType) {
const parts = mimeType.split("/");
if (parts.length > 1) {
return parts[1];
}
return "";
}

async function getDownloadLink(doc) {
const clientParams = {};
const bucket = process.env.PYRAMID_BUCKET;
Expand All @@ -122,7 +114,7 @@ async function getDownloadLink(doc) {
Key: key,
ResponseContentDisposition: `attachment; filename=${
doc._source.label
}.${extensionFromMimeType(doc._source.mime_type)}`,
}.${mime.extension(doc._source.mime_type)}`,
};

const client = new S3Client(clientParams);
Expand Down

0 comments on commit 82ecf58

Please sign in to comment.