feat: name export file with meaningful title instead of id (#379)
This commit is contained in:
16
backend/config/contentDisposition.js
Normal file
16
backend/config/contentDisposition.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export function toSafeFileName(fileName) {
|
||||
const s = String(fileName ?? '')
|
||||
// eslint-disable-next-line no-control-regex
|
||||
.replace(/[\u0000-\u001F\u007F]/g, '')
|
||||
.replace(/[<>:"/\\|?*]/g, '_')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
export function contentDisposition(filename) {
|
||||
const fallback = filename.replace(/[^\x20-\x7E]/g, '_').replace(/"/g, "'");
|
||||
const encoded = encodeURIComponent(filename);
|
||||
return `attachment; filename="${fallback}"; filename*=UTF-8''${encoded}`;
|
||||
}
|
||||
Reference in New Issue
Block a user