Cotton code
21 lines · 1.8 KB · TypeScriptRaw
/** * The Stop link an SMS carries (TRUSTED RECOVERY BUILD 1; src/recovery_circle.ts): `/v1/recovery/stop/<database id>/<token>` * on the open host, no bearer, no script. GET shows one button; POST stops the request the token names (and only it) * and says so. A token that names nothing waiting is answered the same way as one that stopped something already, so * the page says nothing about an account. Words are drafts for the owner's sheet. */export const STOP_PATH = /^\/v1\/recovery\/stop\/([A-Za-z0-9_-]{1,64})\/([A-Za-z0-9_-]{20,64})$/;const PAGE = (body: string) =>  new Response(    `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Cotton</title><meta name="robots" content="noindex"><style>body{font:17px/1.5 system-ui,sans-serif;max-width:32rem;margin:3rem auto;padding:0 16px;color:#1d1d1f;background:#fbfaf6}button{font:inherit;padding:.6rem 1.2rem;border:0;border-radius:8px;background:#1d1d1f;color:#fff}</style></head><body>${body}</body></html>`,    { headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store", "referrer-policy": "no-referrer", "content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'" } },  );export async function stopPage(request: Request, stop: () => Promise<boolean>): Promise<Response> {  if (request.method === "POST") {    await stop();    return PAGE("<h1>Stopped</h1><p>If someone was getting into a Cotton account on a new phone, they can't now. Nothing was opened.</p>");  }  return PAGE('<h1>Stop getting in on a new phone?</h1><p>Someone asked to open your Cotton on a new phone. If that wasn\'t you, stop it.</p><form method="post"><button type="submit">Stop it</button></form>');}