diff --git a/src/routes/admin/+page.server.ts b/src/routes/admin/+page.server.ts new file mode 100644 index 0000000..bb27b87 --- /dev/null +++ b/src/routes/admin/+page.server.ts @@ -0,0 +1,25 @@ +import type { PageServerLoad } from './$types'; + +export const load: PageServerLoad = async ({ platform }) => { + const db = platform?.env?.DB; + + let postCount = 0; + let tagCount = 0; + + if (db) { + try { + const postResult = await db.prepare('SELECT COUNT(*) as count FROM posts').first(); + const tagResult = await db.prepare('SELECT COUNT(*) as count FROM tags').first(); + + postCount = (postResult?.count as number) || 0; + tagCount = (tagResult?.count as number) || 0; + } catch (err) { + console.error('Error fetching admin dashboard stats:', err); + } + } + + return { + postCount, + tagCount + }; +}; diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte new file mode 100644 index 0000000..83f710b --- /dev/null +++ b/src/routes/admin/+page.svelte @@ -0,0 +1,86 @@ + + +
欢迎回来,{data.user?.email || '管理员'}!这是您的后台概览。
+ + +