Source
This app’s code and revision history are public. Download a copy or explore the files below.
Public
The app’s code and revision history are public.
Run it yourself
Take the whole tree and run it on your own machine. The download needs no account. Cloning needs a sign-in.
Download .zip
bounded clone 4ce232ee856d7de1ba5f2b6d
A copy you download is not bounded. The guarantees this app runs under - declared egress, proven invariants, writes that fail closed - live in the runtime serving this page, not in the files. What you get is auditable source you can read and run, with no runtime guarantees attached.
src/lib/mine.ts
// The pages this browser owns (handle -> owner key), and becoming an owner with a key.
import { get, setMany, serverTimestamp } from "@bounded-sh/client";
import { me } from "./bounded";
import type { PageDoc } from "../../functions/lib/bio";
export interface Saved { handle: string; key: string }
const STORE = "bio:mine";
export function savedPages(): Saved[] {
try {
const list = JSON.parse(localStorage.getItem(STORE) || "[]");
return Array.isArray(list) ? list.filter((s) => s && typeof s.handle === "string" && typeof s.key === "string") : [];
} catch {
return [];
}
}
export const savedKey = (handle: string) => savedPages().find((s) => s.handle === handle)?.key ?? null;
/** Remembers a page newest first, replacing an older key for it. */
export function savePage(handle: string, key: string) {
const list = savedPages();
if (list.some((s) => s.handle === handle && s.key === key)) return;
localStorage.setItem(STORE, JSON.stringify([{ handle, key }, ...list.filter((s) => s.handle !== handle)]));
window.dispatchEvent(new Event("bio:saved"));
}
/** Makes this browser an owner of the page, presenting the key if it is not one yet. Resolves to the page as stored. */
export async function claimPage(handle: string, key: string): Promise<PageDoc | "badkey" | "missing"> {
const uid = await me();
const [owner, doc] = await Promise.all([get(`pages/${handle}/owners/${uid}`), get(`pages/${handle}`)]);
if (!doc) return "missing";
if (!owner) {
try {
await setMany([
{ path: `pageclaims/${handle}/c/${uid}`, document: { key } },
{ path: `pages/${handle}/owners/${uid}`, document: { at: serverTimestamp() } },
]);
} catch {
return "badkey";
}
}
return doc as PageDoc;
}
Change history
Quality pass: reorder, hide links, headers, QR share, 15 social icons, API docs
Bounded source sync
Bounded source sync
Bounded source sync
Bounded source sync
Bounded source sync
Bounded source sync