Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 2fa015e

Browse files
feat: export file type
Signed-off-by: peterpeterparker <[email protected]>
1 parent 6094d35 commit 2fa015e

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
### Providers: New
66

77
- offline: v0.0.6 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/main/providers/offline/CHANGELOG.md))
8-
- sync: v0.0.19 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/main/providers/offline/CHANGELOG.md))
8+
- sync: v0.0.20 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/main/providers/offline/CHANGELOG.md))
99

1010
### Providers
1111

providers/sync/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.0.20 (2022-04-03)
2+
3+
### Features
4+
5+
- export file type
6+
17
# 0.0.19 (2022-04-02)
28

39
### Features

providers/sync/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deckdeckgo/sync",
3-
"version": "0.0.19",
3+
"version": "0.0.20",
44
"author": "David Dal Busco",
55
"description": "Sync data and auth providers for DeckDeckGo editors.",
66
"license": "AGPL-3.0-or-later",

providers/sync/src/services/file-system.service.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,18 @@ export const importData = async (file: File): Promise<'doc' | 'deck'> => {
3030
return result;
3131
};
3232

33-
export const exportData = async () => {
33+
export const exportData = async ({
34+
types = [
35+
{
36+
description: 'DeckDeckGo Files',
37+
accept: {
38+
'application/octet-stream': ['.ddg']
39+
}
40+
}
41+
]
42+
}: {
43+
types: FilePickerAcceptType[];
44+
}) => {
3445
if (!isDeckEdited() && !isDocEdited()) {
3546
throw new Error('No deck or doc found');
3647
}
@@ -73,7 +84,8 @@ export const exportData = async () => {
7384

7485
await save({
7586
filename: DeckStore.getInstance().get()?.data?.name || DocStore.getInstance().get()?.data?.name,
76-
blob
87+
blob,
88+
types
7789
});
7890
};
7991

providers/sync/src/utils/file-system.utils.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
export const save = (data: {filename: string | undefined; blob: Blob}): Promise<void> => {
1+
export const save = (data: {filename: string | undefined; blob: Blob; types: FilePickerAcceptType[]}): Promise<void> => {
22
if ('showSaveFilePicker' in window) {
33
return exportNativeFileSystem(data);
44
}
55

66
return download(data);
77
};
88

9-
const exportNativeFileSystem = async ({blob, filename}: {blob: Blob; filename: string}) => {
10-
const fileHandle: FileSystemFileHandle = await getNewFileHandle({filename});
9+
const exportNativeFileSystem = async ({blob, filename, types}: {blob: Blob; filename: string; types: FilePickerAcceptType[]}) => {
10+
const fileHandle: FileSystemFileHandle = await getNewFileHandle({filename, types});
1111

1212
if (!fileHandle) {
1313
throw new Error('Cannot access filesystem');
@@ -16,17 +16,10 @@ const exportNativeFileSystem = async ({blob, filename}: {blob: Blob; filename: s
1616
await writeFile({fileHandle, blob});
1717
};
1818

19-
const getNewFileHandle = ({filename}: {filename: string}): Promise<FileSystemFileHandle> => {
19+
const getNewFileHandle = ({filename, types}: {filename: string; types: FilePickerAcceptType[]}): Promise<FileSystemFileHandle> => {
2020
const opts: SaveFilePickerOptions = {
2121
suggestedName: filename,
22-
types: [
23-
{
24-
description: 'DeckDeckGo Files',
25-
accept: {
26-
'application/octet-stream': ['.ddg']
27-
}
28-
}
29-
]
22+
types
3023
};
3124

3225
return showSaveFilePicker(opts);

0 commit comments

Comments
 (0)