The book/topic field was really always a general-purpose tag, and now that notes can come from more than just books (camera-scanned pages, free text), "book" was misleading in the UI as well as the code. Renames files, functions, variables, the API route (/api/books -> /api/topics), the note payload field, and the cache TTL env var (BOOK_CACHE_TTL_MS -> TOPIC_CACHE_TTL_MS) for consistency. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C3DGg1pvmvf81zXs4pk1J7
27 lines
927 B
TypeScript
27 lines
927 B
TypeScript
import { Router } from "express";
|
|
import { noteInputSchema } from "@notes/shared";
|
|
import { getOrCreateTopicPage } from "../nextcloud/topicCache.js";
|
|
import { appendEntry } from "../nextcloud/webdavClient.js";
|
|
import { formatEntry } from "../nextcloud/noteFormatter.js";
|
|
|
|
export const notesRoutes = Router();
|
|
|
|
notesRoutes.post("/", async (req, res) => {
|
|
const parsed = noteInputSchema.safeParse(req.body);
|
|
if (!parsed.success) {
|
|
res.status(400).json({ error: "Invalid note payload", details: parsed.error.flatten() });
|
|
return;
|
|
}
|
|
|
|
const { topic, page, text } = parsed.data;
|
|
|
|
try {
|
|
const targetPage = await getOrCreateTopicPage(topic);
|
|
const entry = formatEntry(text, page);
|
|
await appendEntry(targetPage, entry);
|
|
res.status(201).json({ ok: true });
|
|
} catch (err) {
|
|
console.error("Failed to save note", err);
|
|
res.status(502).json({ error: "Failed to save note to Nextcloud" });
|
|
}
|
|
});
|