This commit is contained in:
1 parent
1d036172d6
commit
ebccc82757
11 files changed
+28
-28
No files matched your search
@@ -9,7 +9,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
const { aliases } = await parent();
|
||||
|
||||
if (!db) {
|
||||
throw error(500, '数据库未连接');
|
||||
error(500, '数据库未连接');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -29,7 +29,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
}>();
|
||||
|
||||
if (!page) {
|
||||
throw error(404, `该${aliases?.page || '页面'}不存在`);
|
||||
error(404, `该${aliases?.page || '页面'}不存在`);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -38,6 +38,6 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
} catch (err: unknown) {
|
||||
if ((err as any)?.status === 404) throw err;
|
||||
console.error('Error loading page:', err);
|
||||
throw error(500, '读取详情失败');
|
||||
error(500, '读取详情失败');
|
||||
}
|
||||
};
|
||||
@@ -9,7 +9,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
const { aliases } = await parent();
|
||||
|
||||
if (!db) {
|
||||
throw error(500, '数据库未连接');
|
||||
error(500, '数据库未连接');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -19,7 +19,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
.first<{ id: number; title: string; slug: string; content: string }>();
|
||||
|
||||
if (!page) {
|
||||
throw error(404, `该${aliases?.page || '页面'}不存在`);
|
||||
error(404, `该${aliases?.page || '页面'}不存在`);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -28,7 +28,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
} catch (err: unknown) {
|
||||
if ((err as any)?.status === 404) throw err;
|
||||
console.error('Error loading page for edit:', err);
|
||||
throw error(500, '读取详情失败');
|
||||
error(500, '读取详情失败');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,6 +69,6 @@ export const actions: Actions = {
|
||||
return fail(500, { error: '保存修改失败' });
|
||||
}
|
||||
|
||||
throw redirect(303, '/admin/pages');
|
||||
redirect(303, '/admin/pages');
|
||||
}
|
||||
};
|
||||
@@ -41,6 +41,6 @@ export const actions: Actions = {
|
||||
return fail(500, { error: '保存失败' });
|
||||
}
|
||||
|
||||
throw redirect(303, '/admin/pages');
|
||||
redirect(303, '/admin/pages');
|
||||
}
|
||||
};
|
||||
@@ -15,7 +15,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
const { aliases } = await parent();
|
||||
|
||||
if (!db) {
|
||||
throw error(500, '数据库未连接');
|
||||
error(500, '数据库未连接');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -38,7 +38,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
}>();
|
||||
|
||||
if (!post) {
|
||||
throw error(404, `该${aliases?.post || '文章'}不存在`);
|
||||
error(404, `该${aliases?.post || '文章'}不存在`);
|
||||
}
|
||||
|
||||
const { results: allTags } = await db
|
||||
@@ -67,7 +67,7 @@ export const load: PageServerLoad = async ({ params, platform, parent }) => {
|
||||
} catch (err: unknown) {
|
||||
if (isHttpError(err, 404)) throw err;
|
||||
console.error('Error loading post for edit:', err);
|
||||
throw error(500, '读取详情失败');
|
||||
error(500, '读取详情失败');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -176,6 +176,6 @@ export const actions: Actions = {
|
||||
return fail(500, { error: '保存修改失败' });
|
||||
}
|
||||
|
||||
throw redirect(303, '/admin/posts');
|
||||
redirect(303, '/admin/posts');
|
||||
}
|
||||
};
|
||||
@@ -116,6 +116,6 @@ export const actions: Actions = {
|
||||
return fail(500, { error: '保存失败' });
|
||||
}
|
||||
|
||||
throw redirect(303, '/admin/posts');
|
||||
redirect(303, '/admin/posts');
|
||||
}
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import { error } from '@sveltejs/kit';
|
||||
export const load: PageServerLoad = async ({ platform }) => {
|
||||
const db = platform?.env?.DB;
|
||||
if (!db) {
|
||||
throw error(500, '数据库未连接');
|
||||
error(500, '数据库未连接');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -43,6 +43,6 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
};
|
||||
} catch (err: unknown) {
|
||||
console.error('Error fetching archives:', err);
|
||||
throw error(500, '读取列表失败');
|
||||
error(500, '读取列表失败');
|
||||
}
|
||||
};
|
||||
@@ -5,7 +5,7 @@ import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ platform }) => {
|
||||
const db = platform?.env?.DB;
|
||||
if (!db) throw error(500, '数据库未连接');
|
||||
if (!db) error(500, '数据库未连接');
|
||||
try {
|
||||
const { results } = await db
|
||||
.prepare(
|
||||
@@ -26,6 +26,6 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
};
|
||||
} catch (err: any) {
|
||||
console.error('Error fetching public categories list:', err);
|
||||
throw error(500, '读取列表失败');
|
||||
error(500, '读取列表失败');
|
||||
}
|
||||
};
|
||||
@@ -16,14 +16,14 @@ type CategoryPostRow = {
|
||||
export const load: PageServerLoad = async ({ platform, params, url, parent }) => {
|
||||
const db = platform?.env.DB;
|
||||
const { aliases } = await parent();
|
||||
if (!db) throw error(500, '数据库未连接');
|
||||
if (!db) error(500, '数据库未连接');
|
||||
|
||||
try {
|
||||
const category = await db
|
||||
.prepare('SELECT id, name, slug FROM categories WHERE slug = ? COLLATE NOCASE')
|
||||
.bind(params.slug)
|
||||
.first<{ id: number; name: string; slug: string }>();
|
||||
if (!category) throw error(404, `该${aliases?.category || '分类'}不存在`);
|
||||
if (!category) error(404, `该${aliases?.category || '分类'}不存在`);
|
||||
|
||||
const countResult = await db
|
||||
.prepare('SELECT COUNT(*) AS total FROM posts WHERE category_id = ?')
|
||||
@@ -84,6 +84,6 @@ export const load: PageServerLoad = async ({ platform, params, url, parent }) =>
|
||||
} catch (cause) {
|
||||
if (isHttpError(cause, 404)) throw cause;
|
||||
console.error('Error loading category posts:', cause);
|
||||
throw error(500, '读取列表失败');
|
||||
error(500, '读取列表失败');
|
||||
}
|
||||
};
|
||||
@@ -5,7 +5,7 @@ import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ platform }) => {
|
||||
const db = platform?.env?.DB;
|
||||
if (!db) throw error(500, '数据库未连接');
|
||||
if (!db) error(500, '数据库未连接');
|
||||
try {
|
||||
const { results } = await db
|
||||
.prepare(
|
||||
@@ -26,6 +26,6 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
};
|
||||
} catch (err: any) {
|
||||
console.error('Error fetching public series list:', err);
|
||||
throw error(500, '读取列表失败');
|
||||
error(500, '读取列表失败');
|
||||
}
|
||||
};
|
||||
@@ -4,13 +4,13 @@ import type { PageServerLoad } from './$types';
|
||||
export const load: PageServerLoad = async ({ platform, params, parent }) => {
|
||||
const db = platform?.env?.DB;
|
||||
const { aliases } = await parent();
|
||||
if (!db) throw error(500, '数据库未连接');
|
||||
if (!db) error(500, '数据库未连接');
|
||||
try {
|
||||
const series = await db
|
||||
.prepare('SELECT id, name, slug FROM series WHERE slug = ?')
|
||||
.bind(params.slug)
|
||||
.first<{ id: number; name: string; slug: string }>();
|
||||
if (!series) throw error(404, `${aliases?.series || '系列'}不存在`);
|
||||
if (!series) error(404, `${aliases?.series || '系列'}不存在`);
|
||||
const { results } = await db
|
||||
.prepare(
|
||||
`SELECT id, slug, title, series_weight, published_at
|
||||
@@ -34,6 +34,6 @@ export const load: PageServerLoad = async ({ platform, params, parent }) => {
|
||||
} catch (err: unknown) {
|
||||
if (isHttpError(err, 404)) throw err;
|
||||
console.error('Error fetching series detail:', err);
|
||||
throw error(500, '读取详情失败');
|
||||
error(500, '读取详情失败');
|
||||
}
|
||||
};
|
||||
@@ -16,14 +16,14 @@ type TagPostRow = {
|
||||
export const load: PageServerLoad = async ({ platform, params, url, parent }) => {
|
||||
const db = platform?.env.DB;
|
||||
const { aliases } = await parent();
|
||||
if (!db) throw error(500, '数据库还未成功相连');
|
||||
if (!db) error(500, '数据库还未成功相连');
|
||||
|
||||
try {
|
||||
const tag = await db
|
||||
.prepare('SELECT id, name FROM tags WHERE name = ? COLLATE NOCASE')
|
||||
.bind(params.tag)
|
||||
.first<{ id: number; name: string }>();
|
||||
if (!tag) throw error(404, `未找到该${aliases?.tag || '标签'}`);
|
||||
if (!tag) error(404, `未找到该${aliases?.tag || '标签'}`);
|
||||
|
||||
const countResult = await db
|
||||
.prepare('SELECT COUNT(*) AS total FROM post_tags WHERE tag_id = ?')
|
||||
@@ -85,6 +85,6 @@ export const load: PageServerLoad = async ({ platform, params, url, parent }) =>
|
||||
} catch (cause) {
|
||||
if (isHttpError(cause, 404)) throw cause;
|
||||
console.error('Error loading tag posts:', cause);
|
||||
throw error(500, '读取列表失败');
|
||||
error(500, '读取列表失败');
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user