510d7ca4ec
Primo passo della separazione sito / piattaforme decisa da Adriano il 03/09: due applicazioni autosufficienti, senza workspace di root, cosi' che ognuna resti un progetto Astro completo ed estraibile. Qui non cambia niente del codice: solo la radice. I pattern del .gitignore che avevano una barra erano ancorati alla radice e dopo lo spostamento non avrebbero piu' coperto niente (data/*.db*, uploads/*): resi validi a qualunque profondita'. Suite: 45 file, 347 test verdi prima e dopo lo spostamento. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EndnceRA5WnA6rvA5iV9WL
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import type { APIRoute } from 'astro';
|
|
import { getDb } from '../../../../lib/db';
|
|
import { seedByTag } from '../../../../data/content-seed';
|
|
export const prerender = false;
|
|
|
|
const json = (status: number, body: object) =>
|
|
new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } });
|
|
|
|
export const GET: APIRoute = () => {
|
|
const rows = getDb().prepare(
|
|
'SELECT tag, type, value, styles, updated_at, updated_by FROM content_blocks ORDER BY tag'
|
|
).all() as { tag: string; type: string; value: string; styles: string; updated_at: string; updated_by: string | null }[];
|
|
const items = rows.map((r) => {
|
|
let styles: Record<string, string> = {};
|
|
try { styles = JSON.parse(r.styles); } catch { /* styles corrotto: si ignora */ }
|
|
if (typeof styles !== 'object' || styles === null) styles = {};
|
|
return {
|
|
tag: r.tag,
|
|
type: r.type,
|
|
value: r.value,
|
|
styles,
|
|
styleOptions: seedByTag.get(r.tag)?.styleOptions ?? [],
|
|
updatedAt: r.updated_at,
|
|
updatedBy: r.updated_by,
|
|
};
|
|
});
|
|
return json(200, { items });
|
|
};
|