Skip to content

Commit 495cdfe

Browse files
committed
fix: refactor PDF filename generation for consistency
1 parent 61f2d67 commit 495cdfe

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/routes/+page.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
};
146146
};
147147
148+
const getFileName = () =>
149+
`${issuerName}〔${issueDate.year}〕${refNo}号 ${docTitle.replaceAll('\n', '')}.pdf`;
150+
148151
const generatePDF = async () => {
149152
isGenerating = true;
150153
try {
@@ -166,8 +169,7 @@
166169
pdfBlob = blob;
167170
pdf = URL.createObjectURL(blob);
168171
169-
const filename = `${issuerName}〔${issueDate.year}〕${refNo}号 ${docTitle.replaceAll('\n', '')}.pdf`;
170-
const file = new File([blob], filename, { type: 'application/pdf' });
172+
const file = new File([blob], getFileName(), { type: 'application/pdf' });
171173
if (typeof navigator !== 'undefined' && 'canShare' in navigator) {
172174
try {
173175
canShare = navigator.canShare({ files: [file] });
@@ -190,10 +192,9 @@
190192
191193
const handleShare = async () => {
192194
if (!pdfBlob || !canShare) return;
193-
const filename = `${issuerName}〔${issueDate.year}〕${refNo}号 ${docTitle.replaceAll('\n', '')}.pdf`;
194-
const file = new File([pdfBlob], filename, { type: 'application/pdf' });
195+
const file = new File([pdfBlob], getFileName(), { type: 'application/pdf' });
195196
try {
196-
await navigator.share({ files: [file], title: filename });
197+
await navigator.share({ files: [file] });
197198
} catch (e) {
198199
if (e instanceof Error && e.name === 'AbortError') return;
199200
console.error('Error sharing:', e);
@@ -202,8 +203,7 @@
202203
203204
const handleDownload = () => {
204205
if (!pdf) return;
205-
const filename = `${issuerName}〔${issueDate.year}〕${refNo}号 ${docTitle.replaceAll('\n', '')}.pdf`;
206-
triggerDownload(pdf, filename);
206+
triggerDownload(pdf, getFileName());
207207
};
208208
209209
$effect(() => {

0 commit comments

Comments
 (0)