Players get a fast TTL-backed homepage (local profile / Cloudflare D1) with dense UI polish; login unlocks /home without blocking on every OpenDota refresh. Co-authored-by: Cursor <cursoragent@cursor.com>
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
/**
|
|
* GET /api/players/:account_id — public or self profile from D1.
|
|
*/
|
|
import { sessionFromRequest } from "../auth/_steam_common.js";
|
|
import { jsonResponse, loadPlayerBundle } from "./_db.js";
|
|
|
|
export async function onRequestGet(context) {
|
|
try {
|
|
const env = context.env || {};
|
|
if (!env.DB) return jsonResponse({ error: "database not configured" }, 503);
|
|
const accountId = Number(context.params && context.params.account_id);
|
|
if (!Number.isFinite(accountId) || accountId <= 0) {
|
|
return jsonResponse({ error: "bad account_id" }, 400);
|
|
}
|
|
const session = await sessionFromRequest(context);
|
|
const self = session && Number(session.account_id) === accountId;
|
|
const bundle = await loadPlayerBundle(env.DB, accountId);
|
|
if (!bundle) return jsonResponse({ error: "not found" }, 404);
|
|
if (!self && !bundle.public_share) {
|
|
return jsonResponse({ error: "private" }, 404);
|
|
}
|
|
return jsonResponse(bundle);
|
|
} catch (e) {
|
|
return jsonResponse(
|
|
{ error: "player get failed", detail: String((e && e.message) || e) },
|
|
500
|
|
);
|
|
}
|
|
}
|