Close the web-feasible 100% gaps: REST write/token API, tickets, draw-badge, /me, sanitisation, dusk, radio SSE
Final parity push (web-tier only): - REST API write + token auth: POST /api/tokens (issue a personal_access_token for the session user), Bearer auth via src/lib/api-auth.ts, POST /api/articles/[slug]/comment, GET/DELETE /api/me/tokens, full tickets API (/api/tickets +[id] +[id]/reply), radio current-dj/points/points-leaderboard/ embed-config + POST shouts, and a real-time /api/radio/stream (SSE). 31 public API routes total. - Pages: /draw-badge (buy a custom profile badge → credits + RCON), /me dashboard (stats + online friends + referral claim). Wired into the nav. - HTML sanitisation (sanitize-html) — the HTMLPurifier equivalent — applied to writeable boxes + article bodies before dangerouslySetInnerHTML. - "Dusk" dark theme preset + a default-dark site option honoured by the no-flash boot script. Verified live (prod, amx_test): token issue → Bearer endpoint 200, no-token 401; /api/me/tokens lists it; current-dj/leaderboard JSON; /me + /draw-badge 200; reverted the test user + tokens. tsc 0, vitest 49/49, next build 0.
This commit is contained in:
1 parent
8cedf5614e
commit
f7b3845131
30 files changed
+1734
-10
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// Public REST API — post a comment on an article as the Bearer-authed user.
|
||||
//
|
||||
// POST /api/articles/:slug/comment — looks up the website_article by slug for
|
||||
// its id, then inserts a website_article_comments row owned by the user behind
|
||||
// the Authorization: Bearer token. Comment is required, non-empty, max 255
|
||||
// chars (matches the VARCHAR(255) column). Fails soft — never returns a 500 for
|
||||
// DB issues, just a generic error envelope.
|
||||
|
||||
import { apiError, apiJson } from "@/lib/api";
|
||||
import { bearerUserId } from "@/lib/api-auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(
|
||||
req: Request,
|
||||
{ params }: { params: Promise<{ slug: string }> },
|
||||
) {
|
||||
const uid = await bearerUserId(req);
|
||||
if (!uid) return apiError("Unauthorized", 401);
|
||||
|
||||
const { slug } = await params;
|
||||
|
||||
const body = (await req.json().catch(() => ({}))) as { comment?: unknown };
|
||||
const comment = typeof body.comment === "string" ? body.comment.trim() : "";
|
||||
if (!comment) {
|
||||
return apiError("Comment is required", 422);
|
||||
}
|
||||
if (comment.length > 255) {
|
||||
return apiError("Comment may not be longer than 255 characters", 422);
|
||||
}
|
||||
|
||||
try {
|
||||
const article = await prisma.websiteArticles.findUnique({
|
||||
where: { slug },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!article) {
|
||||
return apiError("Article not found", 404);
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
await prisma.websiteArticleComments.create({
|
||||
data: {
|
||||
articleId: article.id,
|
||||
userId: uid,
|
||||
comment,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
return apiJson({ ok: true });
|
||||
} catch {
|
||||
return apiError("Could not post comment", 400);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user