Files
ai-taxonomy-literature-anal…/pages/api/blocks/index.ts
T
claude-bot 5407bf4dff
Deploy / deploy (push) Successful in 8m0s
Page blocks: papers and content pages as flat lists of story blocks in the database
A page is now an ordered list of independent blocks (analysis.page_block), no sections and no
headings; every block has an id shown on the page so it can be pointed at. Paper detail pages
use page "paper/<conf>/<ext_id>", analysis pages on /contents use "content/<node id>".

- /api/blocks (list, replace a page, add) and /api/blocks/:id (get, patch, move, delete)
- dynamic block types (stats, tool-table, paper-table, benchmark-table) are filled from the
  database at render time; the two content pages are rendered from their blocks (seeded with
  defaults on first view)
- one-time migration copies the legacy articles into blocks (section titles dropped, links
  become a links block); legacy tables are kept untouched
- old /api/articles, ArticleView and PaperGroup removed

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbMbJPadPzVwvt9rU9GBNo
2026-10-23 22:51:54 +08:00

21 lines
1.1 KiB
TypeScript

import { route, bodyObject, HttpError } from '../../../lib/api';
import { addBlock, getBlocks, listPages, replacePage } from '../../../lib/block-store';
export const config = { api: { bodyParser: { sizeLimit: '8mb' } } };
const page = (req: { query: Record<string, string | string[] | undefined> }) => {
const p = req.query.page;
if (typeof p !== 'string' || !p) throw new HttpError(400, 'add ?page=paper/<conf>/<ext_id> or ?page=content/<node id>');
return p;
};
// GET /api/blocks pages that have blocks
// GET /api/blocks?page=KEY the blocks of one page, in order (each has an id: that is what you point at)
// PUT /api/blocks?page=KEY replace all blocks of the page: {"blocks":[{"type","data"}, ...]}
// POST /api/blocks?page=KEY add one block: {"type","data","after"?: id,"before"?: id} (default: at the end)
export default route({
GET: async (req) => (req.query.page ? { page: page(req), blocks: await getBlocks(page(req)) } : { pages: await listPages() }),
PUT: (req) => replacePage(page(req), bodyObject(req).blocks),
POST: (req) => addBlock(page(req), bodyObject(req)),
});