mobile: conform to new image loading api

This commit is contained in:
ammarahm-ed
2023-03-22 10:42:41 +05:00
committed by Abdullah Atta
parent 763a108abb
commit 2befa03cd2
4 changed files with 18 additions and 7 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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 })})`
);
};

View File

@@ -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
});