feat: add partly returning statements and remove DecryptionResult
This commit is contained in:
parent
6bb11e60b7
commit
99774ea523
3 changed files with 39 additions and 54 deletions
|
@ -6,7 +6,8 @@ import { db } from "./db";
|
|||
export async function decryptBackup(
|
||||
file: File,
|
||||
passphrase: string,
|
||||
progressCallback: (progres: number) => void,
|
||||
progressCallback: (progress: number) => void,
|
||||
statementsCallback?: (statements: string[]) => void,
|
||||
) {
|
||||
const fileSize = file.size;
|
||||
console.log("Starting decryption of file size:", fileSize);
|
||||
|
@ -30,53 +31,30 @@ export async function decryptBackup(
|
|||
while (!done) {
|
||||
try {
|
||||
done = decryptor.process_chunk(passphrase);
|
||||
} catch (e) {
|
||||
console.error("Error processing chunk:", e);
|
||||
throw e;
|
||||
} catch (error) {
|
||||
console.error("Error processing chunk:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
statementsCallback?.(decryptor.get_new_decrypted_statements());
|
||||
|
||||
offset += chunkSize;
|
||||
// console.log(`Completed chunk, new offset: ${offset}`);
|
||||
// if (performance.memory) {
|
||||
// const memoryInfo = performance.memory;
|
||||
// console.log(`Total JS Heap Size: ${memoryInfo.totalJSHeapSize} bytes`);
|
||||
// console.log(`Used JS Heap Size: ${memoryInfo.usedJSHeapSize} bytes`);
|
||||
// console.log(`JS Heap Size Limit: ${memoryInfo.jsHeapSizeLimit} bytes`);
|
||||
// } else {
|
||||
// console.log("Memory information is not available in this environment.");
|
||||
// }
|
||||
}
|
||||
|
||||
// console.log("All chunks processed, finishing up");
|
||||
const result = decryptor.finish();
|
||||
|
||||
// decryptor.free();
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error("Decryption failed:", e);
|
||||
throw e;
|
||||
} catch (error) {
|
||||
console.error("Decryption failed:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function decrypt(file: File, passphrase: string) {
|
||||
try {
|
||||
const result = await decryptBackup(file, passphrase, console.info);
|
||||
|
||||
// console.log(result, result.database_bytes);
|
||||
|
||||
// console.log("Database bytes length:", result.databaseBytes.length);
|
||||
// console.log(
|
||||
// "Database bytes as string (partly)",
|
||||
// new TextDecoder().decode(result.database_bytes.slice(0, 1024 * 50)),
|
||||
// );
|
||||
|
||||
// console.log(result.database_statements);
|
||||
|
||||
return result;
|
||||
// console.log("Preferences:", result.preferences);
|
||||
// console.log("Key values:", result.keyValues);
|
||||
} catch (error) {
|
||||
console.error("Decryption failed:", error);
|
||||
}
|
||||
|
@ -86,14 +64,19 @@ const App: Component = () => {
|
|||
const [passphrase, setPassphrase] = createSignal("");
|
||||
const [backupFile, setBackupFile] = createSignal<File>();
|
||||
|
||||
let executed = 0;
|
||||
|
||||
createEffect(
|
||||
on(
|
||||
backupFile,
|
||||
(currentBackupFile) => {
|
||||
if (currentBackupFile) {
|
||||
decrypt(currentBackupFile, passphrase()).then((result) => {
|
||||
if (result) {
|
||||
for (const statement of result.database_statements) {
|
||||
decryptBackup(
|
||||
currentBackupFile,
|
||||
passphrase(),
|
||||
console.info,
|
||||
(statements) => {
|
||||
for (const statement of statements) {
|
||||
try {
|
||||
console.log("executing");
|
||||
db.exec(statement);
|
||||
|
@ -104,7 +87,11 @@ const App: Component = () => {
|
|||
}
|
||||
}
|
||||
|
||||
console.log("All statements executed");
|
||||
executed += statements.length;
|
||||
},
|
||||
).then((result) => {
|
||||
if (result) {
|
||||
console.log("All statements executed: ", result.length, executed);
|
||||
|
||||
console.log(
|
||||
db.exec("SELECT * from message", {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue