feat: name export file with meaningful title instead of id (#379)

This commit is contained in:
kimatata
2026-01-10 19:31:47 +09:00
committed by GitHub
parent 475fa1ced7
commit ab348fc4e5
8 changed files with 71 additions and 8 deletions

View 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}`;
}