Skip to content

Commit

Permalink
fix(Downloader): content-type was taking the precedence over http
Browse files Browse the repository at this point in the history
content-disposition header (Fixes #2664)
  • Loading branch information
panaC committed Nov 18, 2024
1 parent b5d1e74 commit def34e9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main/redux/sagas/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,29 +286,39 @@ function downloadCreateFilename(contentType: string | undefined, contentDisposit

const defExt = "unknown-ext";

let filename = "file." + defExt;
const filename = "file." + defExt;

let contentTypeFilename = "";
// type href link from opds feed take precedence on http header content-type !?!
if (type) {
contentType = type;
}
if (contentType) {
const typeValues = contentType.replace(/\s/g, "").split(";");
const [ext] = typeValues.map((v) => findExtWithMimeType(v)).filter((v) => v);
if (ext) {
filename = "file." + ext;
return filename;
contentTypeFilename = "file." + ext;
}
}

let contentDispositionFilename = "";
if (contentDisposition) {
const res = /filename=(\"(.*)\"|(.*))/g.exec(contentDisposition);
const filenameInCD = res ? res[2] || res[3] || "" : "";
if (acceptedExtension(path.extname(filenameInCD))) {
filename = filenameInCD;
return filename;
contentDispositionFilename = filenameInCD;
}
}

return filename;
if (contentDispositionFilename && contentDispositionFilename &&
path.extname(contentDispositionFilename) === path.extname(contentTypeFilename)
) {
debug("contentType and contentDisposition have the same extension ! Good catch !");
} else {
debug("contentType and contentDisposition does not have the same extension ! Server stream !?!");
}

return contentDispositionFilename || contentTypeFilename || filename;
}

interface IDownloadProgression {
Expand Down

0 comments on commit def34e9

Please sign in to comment.