docs(examples): add the CMS proof-of-concept dogfooding artifact
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>
This commit is contained in:
39
examples/cms-poc/scripts/posts/post_create.rhai
Normal file
39
examples/cms-poc/scripts/posts/post_create.rhai
Normal file
@@ -0,0 +1,39 @@
|
||||
// POST /cms/admin/posts — create a post (author+).
|
||||
import "auth" as auth;
|
||||
import "util" as util;
|
||||
let g = auth::guard(ctx, ["admin", "author"]);
|
||||
if !g.ok { return g.response; }
|
||||
let user = g.user;
|
||||
|
||||
let b = ctx.request.body;
|
||||
if b == () || b.title == () {
|
||||
return #{ statusCode: 400, body: #{ error: "title required" } };
|
||||
}
|
||||
|
||||
let posts = docs::collection("posts");
|
||||
let idx = kv::collection("slugs");
|
||||
let slug = if b.slug == () { util::slugify(b.title) } else { util::slugify(b.slug) };
|
||||
if idx.has("post:" + slug) {
|
||||
slug = slug + "-" + random::string(4).to_lower();
|
||||
}
|
||||
|
||||
let now = time::now();
|
||||
let status = if b.status == () { "draft" } else { b.status };
|
||||
let publish_at = ();
|
||||
if status == "published" { publish_at = now; }
|
||||
else if status == "scheduled" && b.publish_at != () { publish_at = b.publish_at; }
|
||||
|
||||
let data = #{
|
||||
title: b.title,
|
||||
slug: slug,
|
||||
body_md: if b.body_md == () { "" } else { b.body_md },
|
||||
excerpt: if b.excerpt == () { "" } else { b.excerpt },
|
||||
status: status,
|
||||
author_id: user.id,
|
||||
author_name: user.display_name,
|
||||
tags: if b.tags == () { [] } else { b.tags },
|
||||
publish_at: publish_at,
|
||||
};
|
||||
let id = posts.create(data);
|
||||
idx.set("post:" + slug, id);
|
||||
#{ statusCode: 201, body: #{ id: id, slug: slug, status: status } }
|
||||
Reference in New Issue
Block a user