Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889// Stories API for false.work builds// GET: Fetch all stories// POST: Save a new story// Requires password authentication via Authorization header
import { connect } from "../../backend/database.mjs";import { respond } from "../../backend/http.mjs";
const BUILDS_PASSWORD = process.env.BUILDS_PASSWORD;
export async function handler(event, context) { if (event.httpMethod === "OPTIONS") { return respond(204, ""); }
// Verify password const authHeader = event.headers.authorization || event.headers.Authorization; const password = authHeader?.replace("Bearer ", "");
if (!password || password !== BUILDS_PASSWORD) { return respond(401, { error: "Unauthorized" }); }
try { const database = await connect(); // Keep using false.work-reports collection for backwards compatibility const stories = database.db.collection("false.work-reports");
// GET - Fetch all stories if (event.httpMethod === "GET") { const allStories = await stories .find({}) .sort({ createdAt: -1 }) .toArray();
await database.disconnect(); return respond(200, { stories: allStories }); }
// POST - Save a new story if (event.httpMethod === "POST") { const body = JSON.parse(event.body); const { buildPlatform, buildVersion, tester, summary, lowHangingFruit, onTheSide, biggerThoughts } = body;
if (!buildPlatform || !buildVersion) { await database.disconnect(); return respond(400, { error: "Missing buildPlatform or buildVersion" }); }
const story = { buildPlatform, buildVersion, tester: tester || "Anonymous", summary: summary || "", lowHangingFruit: lowHangingFruit || [], onTheSide: onTheSide || [], biggerThoughts: biggerThoughts || [], createdAt: new Date(), updatedAt: new Date(), deleted: false };
const result = await stories.insertOne(story); await database.disconnect();
return respond(201, { success: true, storyId: result.insertedId, story }); }
await database.disconnect(); return respond(405, { error: "Method not allowed" });
} catch (err) { console.error("Stories API error:", err); return respond(500, { error: "Failed to process request" }); }}