diff --git a/.changeset/cold-sloths-worry.md b/.changeset/cold-sloths-worry.md new file mode 100644 index 00000000..39dba7ee --- /dev/null +++ b/.changeset/cold-sloths-worry.md @@ -0,0 +1,6 @@ +--- +"@yd/extension": minor +"@yd/web": minor +--- + +feat: save files in .<extension> format diff --git a/apps/extension/src/lib/context-service.ts b/apps/extension/src/lib/context-service.ts index 38decc3e..fcf59e40 100644 --- a/apps/extension/src/lib/context-service.ts +++ b/apps/extension/src/lib/context-service.ts @@ -185,7 +185,7 @@ class ContextService { const blob = await DownloadsService.getDownloadFile({ downloadId: id }); const download = this.#downloads[id]; - const filename = `${download.video.title} - ${download.video.channel.name}.${download.options.format}`; + const filename = `${download.video.title}.${download.options.format}`; try { await saveAs(blob, filename); } catch (e) { diff --git a/apps/extension/src/lib/files.ts b/apps/extension/src/lib/files.ts index 2cc2ed57..a0aabcf9 100644 --- a/apps/extension/src/lib/files.ts +++ b/apps/extension/src/lib/files.ts @@ -8,7 +8,7 @@ export async function saveAs(blob: Blob, name: string): Promise<number> { return await browser.downloads.download({ // Blob type and base64 data for download. url: `data:${blob.type};base64,${base64}`, - filename: cleanFilename(name), + filename: name, saveAs: false, conflictAction: 'uniquify' }); @@ -33,12 +33,3 @@ async function blobToBase64(blob: Blob): Promise<string> { reader.readAsDataURL(blob); }); } - -/** - * Clean a string to prevent browser download throwing invalid naming. - * @param name - name to clean - * @returns string - cleaned filename - */ -function cleanFilename(name: string): string { - return name.replace(/[^a-z0-9]/gi, '_'); -} diff --git a/apps/web/src/lib/stores/downloads.ts b/apps/web/src/lib/stores/downloads.ts index ba858ce1..437ea179 100644 --- a/apps/web/src/lib/stores/downloads.ts +++ b/apps/web/src/lib/stores/downloads.ts @@ -85,7 +85,7 @@ function createDownloadsStore() { try { const blob = await DownloadsService.getDownloadFile({ downloadId: id }); const download = get(DOWNLOADS)[id]; - const filename = `${download.video.title} - ${download.video.channel.name}.${download.options.format}`; + const filename = `${download.video.title}.${download.options.format}`; saveAs(blob, filename); } catch (err) { handleError(id, 'Failed to get file for download.', err);