Skip to content

Commit

Permalink
feat(getDownloadFileName): handle server bundles
Browse files Browse the repository at this point in the history
The 2anki server can send a zip file with multiple APKG files or one
APKG file.
  • Loading branch information
aalemayhu committed Jul 22, 2023
1 parent edec309 commit 06448b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pages/DownloadsPage/helpers/getDownloadFileName.ts
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down
9 changes: 9 additions & 0 deletions src/pages/DownloadsPage/helpers/isServerBundle.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
8 changes: 8 additions & 0 deletions src/pages/DownloadsPage/helpers/isServerBundle.ts
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 06448b7

Please sign in to comment.