import { useNavigate, type RouteSectionProps } from "@solidjs/router"; import { createSignal, type JSX, Show, type Component } from "solid-js"; import { Title } from "@solidjs/meta"; import { Portal } from "solid-js/web"; import { Flex } from "~/components/ui/flex"; import { Progress, ProgressLabel, ProgressValueLabel } from "~/components/ui/progress"; import { loadDb } from "~/db"; import { decryptBackup } from "~/lib/decryptor"; import { createDropzone, createFileUploader } from "@solid-primitives/upload"; import { Button } from "~/components/ui/button"; import { TextField, TextFieldInput, TextFieldLabel } from "~/components/ui/text-field"; export const Home: Component = () => { const navigate = useNavigate(); const fileUploader = createFileUploader({ accept: ".backup", multiple: false, }); const dropzone = createDropzone({ onDrop: (files) => { const file = files.at(0); if (file?.name.endsWith(".backup")) { setBackupFile(file.file); } }, }); const [passphrase, setPassphrase] = createSignal(""); const [backupFile, setBackupFile] = createSignal(); const [decryptionProgress, setDecryptionProgress] = createSignal(); const [loadingProgress, setLoadingProgress] = createSignal(); // const [isLoadingDatabase, setIsLoadingDatabase] = createSignal(false); const onSubmit: JSX.EventHandler = (event) => { event.preventDefault(); const currentBackupFile = backupFile(); const currentPassphrase = passphrase(); if (currentBackupFile && currentPassphrase) { // const hashChunk = await currentBackupFile.slice(-1000).text(); // const hash = hashString(hashChunk); // if (hash === dbHash()) { // return; // } // setDbHash(hash); decryptBackup(currentBackupFile, currentPassphrase, setDecryptionProgress) .then(async (decrypted) => { umami.track("Decrypt backup"); setDecryptionProgress(undefined); // setIsLoadingDatabase(true); setLoadingProgress(0); await loadDb(decrypted.database_statements, setLoadingProgress); umami.track("Load database"); // setIsLoadingDatabase(false); setLoadingProgress(undefined); navigate("/overview"); }) .catch((error) => { console.error("Decryption failed:", error); }); } }; return ( <>

Decrypting backup

`${value}%`} class="w-[300px] space-y-1" >
Processing...
{/*

Loading database

This can take some time

*/}

Loading database

`${value}%`} class="w-[300px] space-y-1" >
Loading...
Signal stats
setPassphrase(value)}> Passphrase {backupFile() ? backupFile()?.name : "or drop the file here"}
); }; export default Home;