From 2befa03cd2bd65688b6bd7f0713f2c7e8e6d31fc Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 22 Mar 2023 10:42:41 +0500 Subject: [PATCH] mobile: conform to new image loading api --- apps/mobile/app/common/filesystem/index.js | 6 ++++-- apps/mobile/app/common/filesystem/io.js | 15 ++++++++++++--- apps/mobile/app/screens/editor/tiptap/commands.ts | 2 +- apps/mobile/app/screens/editor/tiptap/picker.js | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/mobile/app/common/filesystem/index.js b/apps/mobile/app/common/filesystem/index.js index 00dc719b8..b137446a3 100644 --- a/apps/mobile/app/common/filesystem/index.js +++ b/apps/mobile/app/common/filesystem/index.js @@ -23,14 +23,16 @@ import { deleteFile, exists, readEncrypted, - writeEncrypted + writeEncryptedBase64, + hashBase64 } from "./io"; import { uploadFile } from "./upload"; import { cancelable } from "./utils"; export default { readEncrypted, - writeEncrypted, + writeEncryptedBase64, + hashBase64, uploadFile: cancelable(uploadFile), downloadFile: cancelable(downloadFile), deleteFile, diff --git a/apps/mobile/app/common/filesystem/io.js b/apps/mobile/app/common/filesystem/io.js index 16ebc464f..54593dc10 100644 --- a/apps/mobile/app/common/filesystem/io.js +++ b/apps/mobile/app/common/filesystem/io.js @@ -63,8 +63,18 @@ export async function readEncrypted(filename, key, cipherData) { } } -export async function writeEncrypted(filename, { data, type, key }) { - console.log("file input: ", { type, key }); +export async function hashBase64(data) { + return { + hash: await Sodium.hashFile({ + type: "base64", + data, + uri: "" + }), + type: "xxh64" + }; +} + +export async function writeEncryptedBase64({ data, key }) { let filepath = cacheDir + `/${getRandomId("imagecache_")}`; console.log(filepath); await RNFetchBlob.fs.writeFile(filepath, data, "base64"); @@ -73,7 +83,6 @@ export async function writeEncrypted(filename, { data, type, key }) { type: "url" }); RNFetchBlob.fs.unlink(filepath).catch(console.log); - console.log("encrypted file output: ", output); return { ...output, diff --git a/apps/mobile/app/screens/editor/tiptap/commands.ts b/apps/mobile/app/screens/editor/tiptap/commands.ts index c9c0303d8..c90e362c3 100644 --- a/apps/mobile/app/screens/editor/tiptap/commands.ts +++ b/apps/mobile/app/screens/editor/tiptap/commands.ts @@ -229,7 +229,7 @@ typeof globalThis.statusBar !== "undefined" && statusBar.current.set({date:"",sa await this.doAsync( `editor && editor.commands.updateImage(${JSON.stringify({ hash - })},${JSON.stringify({ src, hash, preventUpdate: true })})` + })},${JSON.stringify({ dataurl: src, hash, preventUpdate: true })})` ); }; diff --git a/apps/mobile/app/screens/editor/tiptap/picker.js b/apps/mobile/app/screens/editor/tiptap/picker.js index 6dea3c8b2..1a66068e0 100644 --- a/apps/mobile/app/screens/editor/tiptap/picker.js +++ b/apps/mobile/app/screens/editor/tiptap/picker.js @@ -257,7 +257,7 @@ const handleImageResponse = async (response, options) => { hash: hash, type: image.type, title: fileName, - src: b64, + dataurl: b64, size: image.fileSize, filename: fileName });