mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-23 19:49:56 +01:00
mobile: add readAttachment function
This commit is contained in:
committed by
Abdullah Atta
parent
47dcbba522
commit
58a17f620b
@@ -21,7 +21,7 @@ import { Platform } from "react-native";
|
||||
import "react-native-get-random-values";
|
||||
import * as Keychain from "react-native-keychain";
|
||||
import { generateSecureRandom } from "react-native-securerandom";
|
||||
import Sodium from "react-native-sodium";
|
||||
import Sodium from "@ammarahmed/react-native-sodium";
|
||||
|
||||
const KEYSTORE_CONFIG = Platform.select({
|
||||
ios: {
|
||||
|
||||
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import React from "react";
|
||||
import { Platform } from "react-native";
|
||||
import * as ScopedStorage from "react-native-scoped-storage";
|
||||
import Sodium from "react-native-sodium";
|
||||
import Sodium from "@ammarahmed/react-native-sodium";
|
||||
import RNFetchBlob from "rn-fetch-blob";
|
||||
import { ShareComponent } from "../../components/sheets/export-notes/share";
|
||||
import { presentSheet, ToastEvent } from "../../services/event-manager";
|
||||
@@ -68,7 +68,7 @@ export default async function downloadAttachment(hash, global = true) {
|
||||
chunkSize: attachment.chunkSize
|
||||
};
|
||||
|
||||
let fileUri = await Sodium.decryptFile(key, info, false);
|
||||
let fileUri = await Sodium.decryptFile(key, info, "file");
|
||||
ToastEvent.show({
|
||||
heading: "Download successful",
|
||||
message: attachment.metadata.filename + " downloaded",
|
||||
@@ -114,3 +114,44 @@ export default async function downloadAttachment(hash, global = true) {
|
||||
useAttachmentStore.getState().remove(attachment.metadata.hash);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default async function readAttachment(hash) {
|
||||
let attachment = db.attachments.attachment(hash);
|
||||
if (!attachment) {
|
||||
console.log("attachment not found");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await db.fs.downloadFile(
|
||||
attachment.metadata.hash,
|
||||
attachment.metadata.hash
|
||||
);
|
||||
if (
|
||||
!(await RNFetchBlob.fs.exists(`${cacheDir}/${attachment.metadata.hash}`))
|
||||
)
|
||||
return;
|
||||
|
||||
let key = await db.attachments.decryptKey(attachment.key);
|
||||
let info = {
|
||||
iv: attachment.iv,
|
||||
salt: attachment.salt,
|
||||
length: attachment.length,
|
||||
alg: attachment.alg,
|
||||
hash: attachment.metadata.hash,
|
||||
hashType: attachment.metadata.hashType,
|
||||
mime: attachment.metadata.type,
|
||||
fileName: attachment.metadata.filename,
|
||||
chunkSize: attachment.chunkSize
|
||||
};
|
||||
return await Sodium.decryptFile(key, info, "text");
|
||||
} catch (e) {
|
||||
console.log("download attachment error: ", e);
|
||||
if (attachment.dateUploaded) {
|
||||
RNFetchBlob.fs
|
||||
.unlink(RNFetchBlob.fs.dirs.CacheDir + `/${attachment.metadata.hash}`)
|
||||
.catch(console.log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Platform } from "react-native";
|
||||
import Sodium from "react-native-sodium";
|
||||
import Sodium from "@ammarahmed/react-native-sodium";
|
||||
import RNFetchBlob from "rn-fetch-blob";
|
||||
import { cacheDir, getRandomId } from "./utils";
|
||||
|
||||
@@ -36,7 +36,7 @@ export async function readEncrypted(filename, key, cipherData) {
|
||||
...cipherData,
|
||||
hash: filename
|
||||
},
|
||||
true
|
||||
"base64"
|
||||
);
|
||||
return output;
|
||||
} catch (e) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import React from "react";
|
||||
import { Platform, View } from "react-native";
|
||||
import DocumentPicker from "react-native-document-picker";
|
||||
import { launchCamera, launchImageLibrary } from "react-native-image-picker";
|
||||
import Sodium from "react-native-sodium";
|
||||
import Sodium from "@ammarahmed/react-native-sodium";
|
||||
import RNFetchBlob from "rn-fetch-blob";
|
||||
import { db } from "../../../common/database";
|
||||
import { AttachmentItem } from "../../../components/attachments/attachment-item";
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
"react-native-screens": "^3.13.1",
|
||||
"react-native-securerandom": "^1.0.1",
|
||||
"react-native-share": "^7.2.0",
|
||||
"react-native-sodium": "github:ammarahm-ed/react-native-sodium",
|
||||
"@ammarahmed/react-native-sodium": "1.0.0",
|
||||
"react-native-svg": "^12.3.0",
|
||||
"react-native-tooltips": "^1.0.3",
|
||||
"react-native-vector-icons": "^9.0.0",
|
||||
|
||||
23
apps/mobile/package-lock.json
generated
23
apps/mobile/package-lock.json
generated
@@ -58,6 +58,7 @@
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@ammarahmed/react-native-sodium": "1.0.0",
|
||||
"@callstack/repack": "^3.0.0",
|
||||
"@react-native-clipboard/clipboard": "^1.9.0",
|
||||
"@react-native-community/checkbox": "^0.5.8",
|
||||
@@ -100,7 +101,6 @@
|
||||
"react-native-screens": "^3.13.1",
|
||||
"react-native-securerandom": "^1.0.1",
|
||||
"react-native-share": "^7.2.0",
|
||||
"react-native-sodium": "github:ammarahm-ed/react-native-sodium",
|
||||
"react-native-svg": "^12.3.0",
|
||||
"react-native-tooltips": "^1.0.3",
|
||||
"react-native-vector-icons": "^9.0.0",
|
||||
@@ -149,6 +149,11 @@
|
||||
"webpack": "^5.74.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@ammarahmed/react-native-sodium": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@ammarahmed/react-native-sodium/-/react-native-sodium-1.0.0.tgz",
|
||||
"integrity": "sha512-eXUIFplL4/a2Ed1HJLpkNyQ6DGbHl9fQnLKprY6pz2sSA/E3QVEiigvQMdNr5A0lUaq+b3uDT234OBsUVibxwQ=="
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz",
|
||||
@@ -18455,11 +18460,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-native-share/-/react-native-share-7.9.1.tgz",
|
||||
"integrity": "sha512-v4b6lD4YsiCJB14kjXons+d5cvvxgLv8OdBF0aP58X8Qqbcj81QNv1icAxiNmhxFx5OFYsu/E6v+o8S0GSaneQ=="
|
||||
},
|
||||
"node_modules/react-native-sodium": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "git+ssh://git@github.com/ammarahm-ed/react-native-sodium.git#42a2c38fd13584bf13950cb5024a15370446ecc2",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/react-native-svg": {
|
||||
"version": "12.4.4",
|
||||
"resolved": "https://registry.npmjs.org/react-native-svg/-/react-native-svg-12.4.4.tgz",
|
||||
@@ -21415,6 +21415,11 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@ammarahmed/react-native-sodium": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@ammarahmed/react-native-sodium/-/react-native-sodium-1.0.0.tgz",
|
||||
"integrity": "sha512-eXUIFplL4/a2Ed1HJLpkNyQ6DGbHl9fQnLKprY6pz2sSA/E3QVEiigvQMdNr5A0lUaq+b3uDT234OBsUVibxwQ=="
|
||||
},
|
||||
"@ampproject/remapping": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz",
|
||||
@@ -24205,6 +24210,7 @@
|
||||
"@notesnook/mobile-native": {
|
||||
"version": "file:native",
|
||||
"requires": {
|
||||
"@ammarahmed/react-native-sodium": "1.0.0",
|
||||
"@babel/core": "^7.12.9",
|
||||
"@babel/eslint-parser": "^7.16.5",
|
||||
"@babel/plugin-transform-named-capturing-groups-regex": "^7.16.5",
|
||||
@@ -24281,7 +24287,6 @@
|
||||
"react-native-screens": "^3.13.1",
|
||||
"react-native-securerandom": "^1.0.1",
|
||||
"react-native-share": "^7.2.0",
|
||||
"react-native-sodium": "github:ammarahm-ed/react-native-sodium",
|
||||
"react-native-svg": "^12.3.0",
|
||||
"react-native-tooltips": "^1.0.3",
|
||||
"react-native-vector-icons": "^9.0.0",
|
||||
@@ -35060,10 +35065,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-native-share/-/react-native-share-7.9.1.tgz",
|
||||
"integrity": "sha512-v4b6lD4YsiCJB14kjXons+d5cvvxgLv8OdBF0aP58X8Qqbcj81QNv1icAxiNmhxFx5OFYsu/E6v+o8S0GSaneQ=="
|
||||
},
|
||||
"react-native-sodium": {
|
||||
"version": "git+ssh://git@github.com/ammarahm-ed/react-native-sodium.git#42a2c38fd13584bf13950cb5024a15370446ecc2",
|
||||
"from": "react-native-sodium@github:ammarahm-ed/react-native-sodium"
|
||||
},
|
||||
"react-native-svg": {
|
||||
"version": "12.4.4",
|
||||
"resolved": "https://registry.npmjs.org/react-native-svg/-/react-native-svg-12.4.4.tgz",
|
||||
|
||||
1
extensions/web-clipper/package-lock.json
generated
1
extensions/web-clipper/package-lock.json
generated
@@ -7,6 +7,7 @@
|
||||
"": {
|
||||
"name": "@notesnook/web-clipper",
|
||||
"version": "0.1.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.10.0",
|
||||
"@hot-loader/react-dom": "^17.0.2",
|
||||
|
||||
2001
packages/clipper/package-lock.json
generated
2001
packages/clipper/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user