A WordPress-inspired CMS whose entire backend is PiCloud Rhai scripts deployed with pic apply, plus a SvelteKit frontend. Built to dogfood the project tool, CLI, and SDK; exercises docs/kv/files/users, docs+queue+cron +pubsub triggers, the transactional-outbox notification chain, a docs before-interceptor, set_if CAS, SSE, per-app CORS, env overlays, and a durable Workflow (validate -> enrich || seo -> publish -> finalize) started with workflow::start and polled with workflow::run_status, visualized live with Svelte Flow. FINDINGS.md / SECURITY.md capture every gap, surprise, and security issue found (each tagged [PiCloud] vs [CMS]); the platform fixes for the actionable ones ship in the preceding commit. Also folds in the read-only `pic` allowlist entries added to .claude/settings.json during the session (fewer-permission-prompts). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
25 lines
951 B
Plaintext
25 lines
951 B
Plaintext
// GET /cms/posts/:slug — public single published post (by slug).
|
|
// Resolves slug -> id via the kv slug index, increments a CAS view counter.
|
|
import "util" as util;
|
|
let slug = ctx.request.params.slug;
|
|
if slug == () { return #{ statusCode: 400, body: #{ error: "missing slug" } }; }
|
|
|
|
let idx = kv::collection("slugs");
|
|
let id = idx.get("post:" + slug);
|
|
if id == () { return #{ statusCode: 404, body: #{ error: "not found" } }; }
|
|
|
|
let posts = docs::collection("posts");
|
|
let doc = posts.get(id);
|
|
if doc == () { return #{ statusCode: 404, body: #{ error: "not found" } }; }
|
|
|
|
let p = util::shape_doc(doc);
|
|
// A public reader may only see PUBLISHED posts — never a draft/scheduled one,
|
|
// even if they guess the slug. (No platform per-row authz; enforced here.)
|
|
if p.status != "published" {
|
|
return #{ statusCode: 404, body: #{ error: "not found" } };
|
|
}
|
|
|
|
let views = util::incr("views", "post:" + id);
|
|
p.views = views;
|
|
#{ statusCode: 200, body: p }
|