From e68739f8be7107ee66a66ab8032765a7e751c7f5 Mon Sep 17 00:00:00 2001 From: seaHi Date: Tue, 22 Sep 2026 20:09:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=88=97=E8=A1=A8=E7=9A=84=20API=20=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/api/v1/categories/+server.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/routes/api/v1/categories/+server.ts diff --git a/src/routes/api/v1/categories/+server.ts b/src/routes/api/v1/categories/+server.ts new file mode 100644 index 0000000..79c0c4a --- /dev/null +++ b/src/routes/api/v1/categories/+server.ts @@ -0,0 +1,20 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; + +export const GET: RequestHandler = async ({ platform }) => { + const db = platform?.env.DB; + if (!db) return json({ error: 'Database not connected' }, { status: 500 }); + + try { + const { results } = await db + .prepare('SELECT id, name, slug FROM categories ORDER BY name ASC') + .all(); + + return json({ + data: results + }); + } catch (err: unknown) { + console.error('Failed to get categories', err); + return json({ error: 'Failed to retrieve categories' }, { status: 500 }); + } +};