paste-free.openapps.xyz

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.
Owned app · rev 01fdb2b1f66e
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 6eca480d6447d873e2e5eed9
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.
← All files
src/lib/store.ts
// Writes and owner reads through the Bounded SDK. Loaded only when someone makes or manages a paste,
// so opening a paste never loads the SDK.
import { get, set, setMany, serverTimestamp } from "@bounded-sh/client";
import { me } from "./bounded";
import { randomId, randomKey } from "../../functions/lib/paste";

export interface Paste { content: string; title: string; language: string; ttl: number; burn: boolean; encrypted: boolean; createdAt: number }
export interface NewPaste { content: string; title: string; language: string; ttl: number; burn: boolean; encrypted: boolean }

/** Starts the guest session early, while someone is still typing. */
export const warm = () => me().then(() => {});

/** Saves a paste with this browser as its owner, in one batch with its owner key. */
export async function createPaste(paste: NewPaste): Promise<{ id: string; key: string }> {
  const uid = await me();
  const id = randomId();
  const key = randomKey();
  await setMany([
    { path: `pastes/${id}`, document: { ...paste, opened: false, createdBy: uid, createdAt: serverTimestamp() } },
    { path: `pastes/${id}/owners/${uid}`, document: { at: serverTimestamp() } },
    { path: `pastekeys/${id}`, document: { key } },
  ]);
  return { id, key };
}

async function read(id: string): Promise<Paste | null> {
  try {
    return ((await get(`pastes/${id}`)) as Paste | null) ?? null;
  } catch {
    return null;
  }
}

/** Reads a paste as its owner, first becoming one with the key if this browser is not yet. Null when it is gone or the key does not work. */
export async function openPaste(id: string, key: string): Promise<Paste | null> {
  const uid = await me();
  const paste = await read(id);
  if (paste) return paste;
  try {
    await setMany([
      { path: `pasteclaims/${id}/c/${uid}`, document: { key } },
      { path: `pastes/${id}/owners/${uid}`, document: { at: serverTimestamp() } },
    ]);
  } catch {
    return null;
  }
  return read(id);
}

export const updatePaste = (id: string, patch: Partial<Pick<Paste, "content" | "title" | "language">>) => set(`pastes/${id}`, patch);
export const deletePaste = (id: string) => set(`pastes/${id}`, null);

Change history

Quality pass: password lock, year expiry, line links, text/plain API
01fdb2b1f6 · 4 hours ago
Bounded source sync
fe5788c2d2 · 1 day ago
Bounded source sync
ac6f7dbc95 · 1 day ago
Bounded source sync
0a45926293 · 1 day ago