Files
t5de-hub/apps/web/app/console/actions.ts
T
dhkatzandClaude Opus 5.5 7a06ba49c3
CI / test (push) Successful in 30s
Rebuild the hub on Bun: Elysia API, Better Auth, Drizzle, Next.js website
The hub becomes a Bun monorepo: apps/api (Elysia, Better Auth for accounts, roles, bans, proxy device
sign-in and JWT keys; tagline linking, presence and the console as before), packages/db (Drizzle; Postgres in
production, PGlite in development and tests), and the Next.js website from apps/web. Self-hostable with
docker compose; the website deploys to Vercel-style hosts, the API to any that runs Bun or containers. The
first version, in Go, is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 05:03:54 -07:00

45 lines
1.6 KiB
TypeScript

"use server";
import { revalidatePath } from "next/cache";
import { api, unwrap } from "@/lib/api";
import { attempt, field, type ActionState } from "@/lib/actions";
const roles = ["user", "moderator", "admin"] as const;
/** Runs a change to a person from the console, then shows their page again. */
async function onPerson(form: FormData, change: (id: string) => Promise<string | void>): Promise<ActionState> {
const id = field(form, "id");
return attempt(async () => {
const notice = await change(id);
revalidatePath(`/console/people/${id}`);
return notice;
});
}
export async function setLinkCap(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
const linkCap = Number(field(form, "linkCap"));
const { person } = unwrap(await api.console.people({ id })["link-cap"].post({ linkCap }));
return `Link cap set to ${person.linkCap}.`;
});
}
export async function ban(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
unwrap(await api.console.people({ id }).ban.post({ reason: field(form, "reason") }));
});
}
export async function unban(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
unwrap(await api.console.people({ id }).unban.post());
});
}
export async function setRole(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
const role = roles.find((r) => r === field(form, "role")) ?? "user";
const { person } = unwrap(await api.console.people({ id }).role.post({ role }));
return `Role set to ${person.role}.`;
});
}