mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
mobile: fix exporter errors
This commit is contained in:
@@ -28,10 +28,12 @@ import { presentSheet, ToastEvent } from "../../../services/event-manager";
|
||||
import Exporter from "../../../services/exporter";
|
||||
import PremiumService from "../../../services/premium";
|
||||
import { useThemeStore } from "../../../stores/use-theme-store";
|
||||
import { useUserStore } from "../../../stores/use-user-store";
|
||||
import { getElevation } from "../../../utils";
|
||||
import { ph, pv, SIZE } from "../../../utils/size";
|
||||
import { sleep } from "../../../utils/time";
|
||||
import DialogHeader from "../../dialog/dialog-header";
|
||||
import { ProTag } from "../../premium/pro-tag";
|
||||
import { Button } from "../../ui/button";
|
||||
import { IconButton } from "../../ui/icon-button";
|
||||
import { PressableButton } from "../../ui/pressable";
|
||||
@@ -45,6 +47,7 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
const [complete, setComplete] = useState(false);
|
||||
const [result, setResult] = useState({});
|
||||
const [status, setStatus] = useState(null);
|
||||
const premium = useUserStore((state) => state.premium);
|
||||
|
||||
const save = async (type) => {
|
||||
if (exporting) return;
|
||||
@@ -58,7 +61,9 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
result = await Exporter.exportNote(notes[0], type);
|
||||
await sleep(1000);
|
||||
}
|
||||
if (!result) return setExporting(false);
|
||||
if (!result) {
|
||||
return setExporting(false);
|
||||
}
|
||||
|
||||
setResult(result);
|
||||
setComplete(true);
|
||||
@@ -72,8 +77,9 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
await save("pdf");
|
||||
},
|
||||
icon: "file-pdf-box",
|
||||
desc: "Can be opened in a pdf reader like Adobe or Foxit Reader",
|
||||
id: notesnook.ids.dialogs.export.pdf
|
||||
desc: "View in any pdf reader app",
|
||||
id: notesnook.ids.dialogs.export.pdf,
|
||||
pro: premium
|
||||
},
|
||||
{
|
||||
title: "Markdown",
|
||||
@@ -81,8 +87,9 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
await save("md");
|
||||
},
|
||||
icon: "language-markdown",
|
||||
desc: "Can be opened in any text or markdown editor",
|
||||
id: notesnook.ids.dialogs.export.md
|
||||
desc: "View in any text or markdown editor",
|
||||
id: notesnook.ids.dialogs.export.md,
|
||||
pro: premium
|
||||
},
|
||||
{
|
||||
title: "Plain Text",
|
||||
@@ -90,8 +97,9 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
await save("txt");
|
||||
},
|
||||
icon: "card-text",
|
||||
desc: "Can be opened in any text editor",
|
||||
id: notesnook.ids.dialogs.export.text
|
||||
desc: "View in any text editor",
|
||||
id: notesnook.ids.dialogs.export.text,
|
||||
pro: true
|
||||
},
|
||||
{
|
||||
title: "HTML",
|
||||
@@ -99,8 +107,9 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
await save("html");
|
||||
},
|
||||
icon: "language-html5",
|
||||
desc: "Can be opened in any web browser",
|
||||
id: notesnook.ids.dialogs.export.html
|
||||
desc: "View in any web browser & html reader",
|
||||
id: notesnook.ids.dialogs.export.html,
|
||||
pro: premium
|
||||
}
|
||||
];
|
||||
|
||||
@@ -147,7 +156,8 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
paddingVertical: 10,
|
||||
justifyContent: "flex-start",
|
||||
borderRadius: 0,
|
||||
paddingHorizontal: 12
|
||||
paddingHorizontal: 12,
|
||||
opacity: item.pro ? 1 : 0.5
|
||||
}}
|
||||
>
|
||||
<View
|
||||
@@ -162,7 +172,7 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
>
|
||||
<Icon
|
||||
name={item.icon}
|
||||
color={colors.accent}
|
||||
color={item.pro ? colors.accent : colors.icon}
|
||||
size={SIZE.xxxl + 10}
|
||||
/>
|
||||
</View>
|
||||
@@ -171,6 +181,7 @@ const ExportNotesSheet = ({ notes }) => {
|
||||
flexShrink: 1
|
||||
}}
|
||||
>
|
||||
{!item.pro ? <ProTag size={12} /> : null}
|
||||
<Heading style={{ marginLeft: 10 }} size={SIZE.md}>
|
||||
{item.title}
|
||||
</Heading>
|
||||
|
||||
@@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { decode, EntityLevel } from "entities";
|
||||
import { zip } from "fflate";
|
||||
import { zipSync } from "fflate";
|
||||
import { Platform } from "react-native";
|
||||
import RNHTMLtoPDF from "react-native-html-to-pdf-lite";
|
||||
import * as ScopedStorage from "react-native-scoped-storage";
|
||||
import RNFetchBlob from "rn-fetch-blob";
|
||||
import { db } from "../common/database/index";
|
||||
import { DatabaseLogger, db } from "../common/database/index";
|
||||
import Storage from "../common/database/storage";
|
||||
import { toTXT } from "../utils";
|
||||
import { sanitizeFilename } from "../utils/sanitizer";
|
||||
@@ -419,13 +419,11 @@ async function makeHtml(note) {
|
||||
* @param {"txt" | "pdf" | "md" | "html"} type
|
||||
*/
|
||||
async function exportAs(type, note, bulk) {
|
||||
console.log(type, "type");
|
||||
let data;
|
||||
switch (type) {
|
||||
case "html":
|
||||
{
|
||||
data = await makeHtml(note);
|
||||
console.log("html created", data);
|
||||
}
|
||||
break;
|
||||
case "md":
|
||||
@@ -474,7 +472,7 @@ async function exportNote(note, type) {
|
||||
let path = await getPath(FolderNames[type]);
|
||||
if (!path) return;
|
||||
let result = await exportAs(type, note);
|
||||
|
||||
if (!result) return null;
|
||||
let fileName = sanitizeFilename(note.title + Date.now(), {
|
||||
replacement: "_"
|
||||
});
|
||||
@@ -501,12 +499,9 @@ function copyFileAsync(source, dest) {
|
||||
});
|
||||
}
|
||||
|
||||
function zipAsync(results) {
|
||||
return new Promise((resolve) => {
|
||||
zip(results, (err, data) => {
|
||||
resolve(Buffer.from(data.buffer).toString("base64"));
|
||||
});
|
||||
});
|
||||
function zipsync(results) {
|
||||
let data = zipSync(results);
|
||||
return Buffer.from(data.buffer).toString("base64");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -519,25 +514,34 @@ async function bulkExport(notes, type, callback) {
|
||||
|
||||
const results = {};
|
||||
for (var i = 0; i < notes.length; i++) {
|
||||
await sleep(1);
|
||||
let note = notes[i];
|
||||
let result = await exportAs(type, note);
|
||||
let fileName = sanitizeFilename(note.title + Date.now(), {
|
||||
replacement: "_"
|
||||
});
|
||||
results[fileName + `.${type}`] = Buffer.from(
|
||||
result,
|
||||
type === "pdf" ? "base64" : "utf-8"
|
||||
);
|
||||
callback(`${i + 1}/${notes.length}`);
|
||||
try {
|
||||
await sleep(1);
|
||||
let note = notes[i];
|
||||
if (note.locked) continue;
|
||||
let result = await exportAs(type, note);
|
||||
let fileName = sanitizeFilename(note.title + Date.now(), {
|
||||
replacement: "_"
|
||||
});
|
||||
if (result) {
|
||||
results[fileName + `.${type}`] = Buffer.from(
|
||||
result,
|
||||
type === "pdf" ? "base64" : "utf-8"
|
||||
);
|
||||
}
|
||||
callback(`${i + 1}/${notes.length}`);
|
||||
} catch (e) {
|
||||
DatabaseLogger.error(e);
|
||||
}
|
||||
}
|
||||
callback("zipping");
|
||||
await sleep(1);
|
||||
const zipped = await zipAsync(results);
|
||||
const fileName = `nn-export-${notes.length}-${type}-${Date.now()}.zip`;
|
||||
callback("saving to disk");
|
||||
await sleep(1);
|
||||
|
||||
try {
|
||||
callback("zipping");
|
||||
await sleep(1);
|
||||
const zipped = zipsync(results);
|
||||
callback("saving to disk");
|
||||
await sleep(1);
|
||||
|
||||
if (Platform.OS === "ios") {
|
||||
RNFetchBlob.fs.writeFile(path + `/${fileName}`, zipped, "base64");
|
||||
} else {
|
||||
@@ -554,14 +558,15 @@ async function bulkExport(notes, type, callback) {
|
||||
callback();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e, "error");
|
||||
DatabaseLogger.error(e);
|
||||
}
|
||||
|
||||
return {
|
||||
filePath: path,
|
||||
type: "application/zip",
|
||||
name: "zip",
|
||||
fileName: fileName
|
||||
fileName: fileName,
|
||||
count: results?.length || 0
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
361
apps/mobile/package-lock.json
generated
361
apps/mobile/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,8 @@
|
||||
"@notesnook/core": "*",
|
||||
"@notesnook/editor": "*",
|
||||
"@notesnook/editor-mobile": "*",
|
||||
"fflate": "^0.7.3",
|
||||
"react-native-actions-shortcuts": "^1.0.1",
|
||||
"react-native-fingerprint-scanner": "https://github.com/ammarahm-ed/react-native-fingerprint-scanner.git",
|
||||
"fflate": "^0.7.3"
|
||||
"react-native-fingerprint-scanner": "https://github.com/ammarahm-ed/react-native-fingerprint-scanner.git"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
packages/core/package-lock.json
generated
13
packages/core/package-lock.json
generated
@@ -8147,7 +8147,7 @@
|
||||
},
|
||||
"node_modules/showdown": {
|
||||
"version": "3.0.0-alpha",
|
||||
"resolved": "git+ssh://git@github.com/thecodrr/showdown.git#687b153e66561a6786359bda5ab449e7ac8c99fc",
|
||||
"resolved": "git+ssh://git@github.com/thecodrr/showdown.git#296d5af5cd2e06bc86f2377653ddaa2f4a1a36a5",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"showdown": "bin/showdown.js"
|
||||
@@ -13263,8 +13263,7 @@
|
||||
},
|
||||
"jest-pnp-resolver": {
|
||||
"version": "1.2.2",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
},
|
||||
"jest-regex-util": {
|
||||
"version": "28.0.2",
|
||||
@@ -13807,8 +13806,7 @@
|
||||
"dependencies": {
|
||||
"ws": {
|
||||
"version": "8.8.1",
|
||||
"dev": true,
|
||||
"requires": {}
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -14372,7 +14370,7 @@
|
||||
"dev": true
|
||||
},
|
||||
"showdown": {
|
||||
"version": "git+ssh://git@github.com/thecodrr/showdown.git#687b153e66561a6786359bda5ab449e7ac8c99fc",
|
||||
"version": "git+ssh://git@github.com/thecodrr/showdown.git#296d5af5cd2e06bc86f2377653ddaa2f4a1a36a5",
|
||||
"from": "showdown@github:thecodrr/showdown"
|
||||
},
|
||||
"signal-exit": {
|
||||
@@ -14731,8 +14729,7 @@
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.5.9",
|
||||
"requires": {}
|
||||
"version": "7.5.9"
|
||||
},
|
||||
"xml-name-validator": {
|
||||
"version": "4.0.0",
|
||||
|
||||
Reference in New Issue
Block a user