Add docs navigation and tighten API request security

This commit is contained in:
2026-10-11 18:53:46 +05:00
parent a54a3e7705
commit 3cc3136762
28 changed files with 915 additions and 29 deletions

23
lib/request-security.ts Normal file
View File

@@ -0,0 +1,23 @@
import { ServiceError } from "./service-error";
/** Device upload tokens cannot authorize staff actions or issue other credentials. */
export async function browserAccount<T extends { id: string }>(
request: Pick<Request, "headers">,
getUser: () => Promise<T | null>,
): Promise<T> {
if (request.headers.has("authorization"))
throw new ServiceError("Use your signed-in account for this action", 403);
const account = await getUser();
if (!account) throw new ServiceError("Sign in to continue", 401);
return account;
}
export async function limitRoomCreation(
accountId: string,
accessHash: string,
limit: (key: string, count: number, seconds: number) => Promise<void>,
) {
// A browser cookie is replaceable. The verified account is the durable limit.
await limit("multiplayer:create:account:" + accountId, 20, 3600);
await limit("multiplayer:create:" + accessHash, 20, 3600);
}