mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 05:37:48 +01:00
* Owner: one page that always says the next step; counts come from the pack /owner never answers 404: it says whether you are signed out, signed in with another address, unconfirmed, or the owner, and what to do. The check asks whether the address is the owner's before asking if it is confirmed. The investor room's question and review counts and the warm-up's promised length are tied to the content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtfseicWGK2CMC2U5r * Team QR poster, the visitor's path counted, care page follows the pack The team invite shows a QR code and opens a printable poster for the staff room. Anonymous totals now count the visitor's path from home page to answer, and from organisations page to pilot request; /owner lists them. The care page lists every care scene the pack has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmtfseicWGK2CMC2U5r --------- Co-authored-by: Claude <noreply@anthropic.com>
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
import { dbConfigured } from "../../../lib/db/index.ts";
|
|
import { run } from "../../../lib/db/run.ts";
|
|
import { allow, usage as usageLimit } from "../../../lib/domain/limits.ts";
|
|
import { PACK_ITEMS } from "../../../lib/domain/practice/published.ts";
|
|
import { SECTORS } from "../../../lib/config/sectors.ts";
|
|
import { RUN_SCENES } from "../../../lib/domain/situations/scenes.ts";
|
|
import { countUsage } from "../../../lib/domain/usage/count.ts";
|
|
import { usageKey, type Known } from "../../../lib/domain/usage/keys.ts";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
/** What this deployment has, so a key can only name something real. Built once. */
|
|
const KNOWN: Known = {
|
|
scenes: new Map(RUN_SCENES.map((scene) => [scene.id, scene.parts.length])),
|
|
items: new Set(PACK_ITEMS.map((item) => item.id)),
|
|
sectors: new Set(SECTORS.map((sector) => sector.id)),
|
|
};
|
|
|
|
/**
|
|
* POST /api/usage: raise one anonymous total by one (`usage/keys.ts`).
|
|
*
|
|
* ALWAYS 204, whatever happened: a key that was refused, a spent rate limit,
|
|
* no database. The page that sent it does nothing with the answer, and a
|
|
* status that distinguished them would only tell a script which keys exist.
|
|
* Nothing about the caller is read except what the rate limit needs, and
|
|
* that is not stored with the count.
|
|
*/
|
|
export async function POST(request: Request) {
|
|
const done = new Response(null, { status: 204, headers: { "cache-control": "no-store" } });
|
|
if (!dbConfigured()) return done;
|
|
if (!(await allow(usageLimit, request, "usage")).allowed) return done;
|
|
let body: unknown;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return done;
|
|
}
|
|
const key = usageKey((body as { key?: unknown } | null)?.key, KNOWN);
|
|
if (!key) return done;
|
|
try {
|
|
await countUsage(run, key, new Date());
|
|
} catch {
|
|
// A total that could not be written is a total that is one short.
|
|
}
|
|
return done;
|
|
}
|