Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(getDownloadFileName): handle server bundles #443

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');