refactor(server/utils): merge sanitizeFilenameForHeader into getContentDisposition

sanitizeFilenameForHeader is not used anywhere else and is tiny, so let's merge it
This commit is contained in:
Panagiotis Papadopoulos 2025-01-31 08:33:59 +01:00
parent 29b1befd60
commit fedaec6c79

View File

@ -117,15 +117,10 @@ export async function crash() {
} }
} }
export function sanitizeFilenameForHeader(filename: string) {
const sanitizedFilename = sanitize(filename).trim() || "file";
return encodeURIComponent(sanitizedFilename);
}
export function getContentDisposition(filename: string) { export function getContentDisposition(filename: string) {
const sanitizedFilename = sanitizeFilenameForHeader(filename); const sanitizedFilename = sanitize(filename).trim() || "file";
const uriEncodedFilename = encodeURIComponent(sanitizedFilename);
return `file; filename="${sanitizedFilename}"; filename*=UTF-8''${sanitizedFilename}`; return `file; filename="${uriEncodedFilename}"; filename*=UTF-8''${uriEncodedFilename}`;
} }
// render and book are string note in the sense that they are expected to contain empty string // render and book are string note in the sense that they are expected to contain empty string
@ -325,7 +320,6 @@ export default {
removeDiacritic, removeDiacritic,
removeTextFileExtension, removeTextFileExtension,
replaceAll, replaceAll,
sanitizeFilenameForHeader,
sanitizeSqlIdentifier, sanitizeSqlIdentifier,
stripTags, stripTags,
timeLimit, timeLimit,