From f12f215dedb8cc32634c0414b33524258793e120 Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Sat, 22 Jul 2023 12:46:45 +0200 Subject: [PATCH] feat(getDownloadFileName): handle server bundles The 2anki server can send a zip file with multiple APKG files or one APKG file. --- src/pages/DownloadsPage/helpers/getDownloadFileName.ts | 4 +++- src/pages/DownloadsPage/helpers/isServerBundle.test.ts | 9 +++++++++ src/pages/DownloadsPage/helpers/isServerBundle.ts | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/pages/DownloadsPage/helpers/isServerBundle.test.ts create mode 100644 src/pages/DownloadsPage/helpers/isServerBundle.ts 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');