diff --git a/CLAUDE.md b/CLAUDE.md index cb28d19..518e29d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,3 +1,7 @@ +Do not style anything for now + +Do not add libraries without asking first or giving me the option to choose a different library + ## Commands - `deno task dev`: dev server (Vite) diff --git a/VCES.md b/VCES.md new file mode 100644 index 0000000..fdcba5a --- /dev/null +++ b/VCES.md @@ -0,0 +1,15 @@ +This will be an end to end encrypted file service + +The flow for a new user will go as follows: + +- Basically empty page with a text input, they will type in a code and the server will verify that code +- If the code is not verified, give an error +- If the code verifies, they will be taken to a second screen where they will choose between generating a new + cryptographic key or importing one from another session +- Choosing one of the 2 will take the user to the main hub of the service where they will be able to see their files, + upload new ones and such + +There will be no database file, just a json file at DATABASE_PATH that will store the few users we have and such + +Users will be an dictionary in the database file with a "users" key, the users dictionary will be a +`Record` where the key to that is a `monotonicUlid()` diff --git a/deno.json b/deno.json index 503db1f..1a0070f 100644 --- a/deno.json +++ b/deno.json @@ -20,6 +20,8 @@ ], "imports": { "@/": "./", + "@std/ulid": "jsr:@std/ulid@^1.0.0", + "@zod/zod": "jsr:@zod/zod@^4.6.7", "fresh": "jsr:@fresh/core@^2.3.3", "preact": "npm:preact@^10.29.1", "@preact/signals": "npm:@preact/signals@^2.9.0", diff --git a/deno.lock b/deno.lock index 788f506..a126be1 100644 --- a/deno.lock +++ b/deno.lock @@ -5,6 +5,7 @@ "jsr:@deno/loader@0.4": "0.4.0", "jsr:@deno/loader@~0.3.10": "0.3.14", "jsr:@fresh/build-id@1": "1.0.1", + "jsr:@fresh/core@*": "2.3.3", "jsr:@fresh/core@2": "2.3.3", "jsr:@fresh/core@^2.3.3": "2.3.3", "jsr:@fresh/plugin-vite@^1.1.2": "1.1.2", @@ -27,7 +28,9 @@ "jsr:@std/path@^1.1.2": "1.1.6", "jsr:@std/path@^1.1.5": "1.1.6", "jsr:@std/semver@^1.0.6": "1.0.8", + "jsr:@std/ulid@1": "1.0.0", "jsr:@std/uuid@^1.0.9": "1.1.1", + "jsr:@zod/zod@^4.6.7": "4.6.7", "npm:@babel/core@^7.28.0": "7.29.7", "npm:@babel/preset-react@^7.27.1": "7.29.7_@babel+core@7.29.7", "npm:@opentelemetry/api@^1.9.0": "1.9.1", @@ -36,6 +39,7 @@ "npm:@prefresh/vite@^2.4.8": "2.4.12_preact@10.29.8_vite@7.3.6_preact-render-to-string@6.7.0", "npm:@remix-run/node-fetch-server@0.12": "0.12.0", "npm:@tailwindcss/vite@^4.1.12": "4.3.3_vite@7.3.6", + "npm:@types/babel__core@^7.20.5": "7.20.5", "npm:esbuild-wasm@~0.25.11": "0.25.12", "npm:esbuild@0.25.7": "0.25.7", "npm:esbuild@~0.25.5": "0.25.12", @@ -107,6 +111,7 @@ "npm:@babel/preset-react", "npm:@prefresh/vite", "npm:@remix-run/node-fetch-server", + "npm:@types/babel__core", "npm:rollup", "npm:vite@^7.1.4" ] @@ -165,11 +170,17 @@ "@std/semver@1.0.8": { "integrity": "dc830e8b8b6a380c895d53fbfd1258dc253704ca57bbe1629ac65fd7830179b7" }, + "@std/ulid@1.0.0": { + "integrity": "d41c3d27a907714413649fee864b7cde8d42ee68437d22b79d5de4f81d808780" + }, "@std/uuid@1.1.1": { "integrity": "7b49060282d90f72fec64952f8c7a2914cbe6fdba3eca665f8cedc90830154a7", "dependencies": [ "jsr:@std/bytes" ] + }, + "@zod/zod@4.6.7": { + "integrity": "6706868ce1e1907362e1bf008e298e482723345f0ba4125c43e5b9fd7960b186" } }, "npm": { @@ -1480,6 +1491,8 @@ "dependencies": [ "jsr:@fresh/core@^2.3.3", "jsr:@fresh/plugin-vite@^1.1.2", + "jsr:@std/ulid@1", + "jsr:@zod/zod@^4.6.7", "npm:@preact/signals@^2.9.0", "npm:@tailwindcss/vite@^4.1.12", "npm:preact@^10.29.1", diff --git a/islands/AskCode.tsx b/islands/AskCode.tsx new file mode 100644 index 0000000..d52231e --- /dev/null +++ b/islands/AskCode.tsx @@ -0,0 +1,20 @@ +import Form from "@/islands/Form.tsx"; +import { Signal } from "@preact/signals"; + +interface AskCodeProps { + page: Signal; +} + +export default function AskCode({ page }: AskCodeProps) { + const on_success = (data: { code: string }) => { + localStorage.setItem("code", data.code); + page.value = "keys"; + }; + + return ( +
+ + +
+ ); +} diff --git a/islands/Form.tsx b/islands/Form.tsx new file mode 100644 index 0000000..8ae9a89 --- /dev/null +++ b/islands/Form.tsx @@ -0,0 +1,60 @@ +import type { ComponentChildren } from "preact"; +import { useSignal } from "@preact/signals"; + +interface FormProps { + action: string; + on_success: (data: T) => void; + on_error?: (message: string) => void; + class?: string; + method?: string; + children: ComponentChildren; +} + +// Posts the form's named fields as a JSON object of strings +export default function Form(props: FormProps) { + const submitting = useSignal(false); + const error = useSignal(""); + + async function submit(event: SubmitEvent) { + event.preventDefault(); + if (submitting.value) { + return; + } + + const form = event.currentTarget as HTMLFormElement; + const body = Object.fromEntries(new FormData(form)); + + submitting.value = true; + error.value = ""; + try { + const method = props.method ?? "POST"; + const response = await fetch( + props.action, + method.toUpperCase() === "GET" ? { method } : { + method, + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body), + }, + ); + const data = response.status === 204 ? undefined : await response.json().catch(() => undefined); + + if (!response.ok) { + throw new Error(data?.error ?? `Request failed with status ${response.status}`); + } + props.on_success(data as T); + } catch (err) { + const message = err instanceof Error ? err.message : String(err); + if (props.on_error) props.on_error(message); + else error.value = message; + } finally { + submitting.value = false; + } + } + + return ( +
+
{props.children}
+ {error.value &&

{error.value}

} +
+ ); +} diff --git a/islands/MainIsland.tsx b/islands/MainIsland.tsx new file mode 100644 index 0000000..66eda2d --- /dev/null +++ b/islands/MainIsland.tsx @@ -0,0 +1,15 @@ +import { useSignal } from "@preact/signals"; + +import AskCode from "./AskCode.tsx"; + +export default function MainIsland() { + const page = useSignal("askcode"); + + if (page.value === "askcode") { + return ; + } else if (page.value === "keys") { + return localStorage.getItem("code"); + } else { + return "Error"; + } +} diff --git a/main.ts b/main.ts index b70c032..d7eed22 100644 --- a/main.ts +++ b/main.ts @@ -1,30 +1,16 @@ -import { App, staticFiles } from "fresh"; +import { App, csp, csrf, staticFiles } from "fresh"; import { define, type State } from "./utils.ts"; export const app = new App(); +// Vite's dev client injects CSS through