feat: 添加获取系列列表的 API 路由
This commit is contained in:
1 parent
e68739f8be
commit
cd44f337ab
1 file changed
+20
@@ -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 series ORDER BY name ASC')
|
||||||
|
.all();
|
||||||
|
|
||||||
|
return json({
|
||||||
|
data: results
|
||||||
|
});
|
||||||
|
} catch (err: unknown) {
|
||||||
|
console.error('Failed to get series', err);
|
||||||
|
return json({ error: 'Failed to retrieve series' }, { status: 500 });
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user