diff --git a/src/pages/DownloadsPage/helpers/getDownloadFileName.ts b/src/pages/DownloadsPage/helpers/getDownloadFileName.ts index c5a94b3d..51c70c1c 100644 --- a/src/pages/DownloadsPage/helpers/getDownloadFileName.ts +++ b/src/pages/DownloadsPage/helpers/getDownloadFileName.ts @@ -1,5 +1,7 @@ +import { isServerBundle } from './isServerBundle'; + export const getDownloadFileName = (fileName: string) => { - if (fileName.toLowerCase().endsWith('.apkg')) { + if (fileName.toLowerCase().endsWith('.apkg') || isServerBundle(fileName)) { return fileName; } return `${fileName}.apkg`; diff --git a/src/pages/DownloadsPage/helpers/isServerBundle.test.ts b/src/pages/DownloadsPage/helpers/isServerBundle.test.ts new file mode 100644 index 00000000..24c90826 --- /dev/null +++ b/src/pages/DownloadsPage/helpers/isServerBundle.test.ts @@ -0,0 +1,9 @@ +import { isServerBundle } from './isServerBundle'; + +describe('isBundle', () => { + test('server bundle name', () => { + expect( + isServerBundle('Your decks-62a104dc-2c91-4ce8-837e-d2379e523693.zip') + ).toBe(true); + }); +}); diff --git a/src/pages/DownloadsPage/helpers/isServerBundle.ts b/src/pages/DownloadsPage/helpers/isServerBundle.ts new file mode 100644 index 00000000..b9059814 --- /dev/null +++ b/src/pages/DownloadsPage/helpers/isServerBundle.ts @@ -0,0 +1,8 @@ +/** + * isServerBundle returns true if the filename is a server bundle. + * The 2anki server can send a zip file with multiple APKG files or one APKG file. + * @param filename The filename to check. + * @returns boolean + */ +export const isServerBundle = (filename: string) => + filename.startsWith('Your decks') || filename.endsWith('.zip');