-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kévin Commaille
committed
Feb 22, 2021
1 parent
312ffbe
commit 593b6d6
Showing
15 changed files
with
429 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as Etebase from "etebase"; | ||
import * as IntentLauncher from "expo-intent-launcher"; | ||
import RNFS from "react-native-fs"; | ||
import { getItemsZip } from "./utils"; | ||
|
||
export function canExport() { | ||
return true; | ||
} | ||
|
||
export async function exportItems(items: Etebase.Item[]) { | ||
const content = await getItemsZip(items, "base64"); | ||
const result = await IntentLauncher.startActivityAsync("android.intent.action.CREATE_DOCUMENT", { | ||
type: "application/zip", | ||
category: "android.intent.category.OPENABLE", | ||
extra: { "android.intent.extra.TITLE": "etesync-notes-export.zip" }, | ||
}); | ||
if (result.resultCode === IntentLauncher.ResultCode.Success && result?.data) { | ||
await RNFS.writeFile(result.data, content, "base64"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as Etebase from "etebase"; | ||
import Share from "react-native-share"; | ||
import { getItemsZip } from "./utils"; | ||
|
||
export function canExport() { | ||
return true; | ||
} | ||
|
||
export async function exportItems(items: Etebase.Item[]) { | ||
const content = await getItemsZip(items, "base64"); | ||
|
||
await Share.open({ | ||
url: `data:application/zip;base64,${content}`, | ||
type: "application/zip", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as Etebase from "etebase"; | ||
|
||
export function canExport() { | ||
return false; | ||
} | ||
|
||
export async function exportItems(items: Etebase.Item[]) { | ||
throw Error(`Cannot export ${items.length} items. Exporting is not implemented on this Platform`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as Etebase from "etebase"; | ||
import FileSaver from "file-saver"; | ||
import { getItemsZip } from "./utils"; | ||
|
||
export function canExport() { | ||
try { | ||
const canBlob = !!new Blob; | ||
return canBlob; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
export async function exportItems(items: Etebase.Item[]) { | ||
const blob = await getItemsZip(items, "blob"); | ||
FileSaver.saveAs(blob, "etesync-notes-export.zip"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./export"; | ||
export * from "./share"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import * as Etebase from "etebase"; | ||
import YAML from "js-yaml"; | ||
import JSZip from "jszip"; | ||
|
||
export async function getItemData(item: Etebase.Item) { | ||
const { name } = item.getMeta(); | ||
const content = await item.getContent(Etebase.OutputFormat.String); | ||
return { | ||
name, | ||
content, | ||
export async function getItemData(item: Etebase.Item, format = "") { | ||
const data = { | ||
name: item.getMeta().name, | ||
content: "", | ||
}; | ||
const content = await item.getContent(Etebase.OutputFormat.String); | ||
|
||
switch (format) { | ||
case "export": { | ||
const frontmatter = YAML.dump({ title: data.name }); | ||
data.content = `---\n${frontmatter}---\n\n${content}`; | ||
break; | ||
} | ||
default: { | ||
data.content = `# ${data.name}\n\n${content}`; | ||
} | ||
} | ||
return data; | ||
} | ||
|
||
export async function getItemsZip<T extends JSZip.OutputType>(items: Etebase.Item[], format: T) { | ||
const zip = new JSZip(); | ||
|
||
for (const item of items) { | ||
const itemData = await getItemData(item, "export"); | ||
zip.file(`${itemData.name?.replace(/[/\\]/g, "-")}.md`, itemData.content); | ||
} | ||
return zip.generateAsync<T>({ type: format }); | ||
} |
Oops, something went wrong.