fix: restore dark post view and API revalidation
This commit is contained in:
1 parent
5c554f27ea
commit
0933220c70
12 files changed
+100
-31
No files matched your search
@@ -1,5 +1,6 @@
|
||||
// GET /api/custom-pages/[name] — 公开单个页面
|
||||
import pool from '@/lib/db';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
export async function GET(req, { params }) {
|
||||
try {
|
||||
@@ -10,7 +11,7 @@ export async function GET(req, { params }) {
|
||||
if (r.rows.length === 0) {
|
||||
return Response.json({ error: '页面不存在' }, { status: 404 });
|
||||
}
|
||||
return Response.json(r.rows[0]);
|
||||
return jsonWithEtag(req, r.rows[0]);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// GET /api/custom-pages — 公开页面列表
|
||||
import pool from '@/lib/db';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
export async function GET() {
|
||||
export async function GET(req) {
|
||||
try {
|
||||
const r = await pool.query(
|
||||
'SELECT id, name, title FROM custom_pages WHERE enabled = true ORDER BY created_at'
|
||||
);
|
||||
return Response.json(r.rows);
|
||||
return jsonWithEtag(req, r.rows);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
// GET /api/links, POST /api/links
|
||||
import pool from '@/lib/db';
|
||||
import { getUser, requireAdmin } from '@/lib/auth';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存)
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
|
||||
export async function GET() {
|
||||
export async function GET(req) {
|
||||
try {
|
||||
const r = await pool.query('SELECT * FROM friendly_links ORDER BY sort_order');
|
||||
return Response.json(r.rows);
|
||||
return jsonWithEtag(req, r.rows);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// GET /api/posts/[id]/replies, POST /api/posts/[id]/replies
|
||||
import pool from '@/lib/db';
|
||||
import { getUser } from '@/lib/auth';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
export async function GET(req, { params }) {
|
||||
try {
|
||||
@@ -12,7 +13,7 @@ export async function GET(req, { params }) {
|
||||
ORDER BY r.created_at ASC`,
|
||||
[(await params).id]
|
||||
);
|
||||
return Response.json(r.rows);
|
||||
return jsonWithEtag(req, r.rows);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// GET /api/posts/[id], DELETE /api/posts/[id]
|
||||
import pool from '@/lib/db';
|
||||
import { getUser } from '@/lib/auth';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
@@ -21,7 +22,7 @@ export async function GET(req, { params }) {
|
||||
if (r.rows.length === 0) {
|
||||
return invalidId();
|
||||
}
|
||||
return Response.json(r.rows[0]);
|
||||
return jsonWithEtag(req, r.rows[0]);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// GET /api/posts, POST /api/posts — 支持 ?sort= & ?user_id= & 分页
|
||||
import pool from '@/lib/db';
|
||||
import { getUser } from '@/lib/auth';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存)
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -38,7 +39,7 @@ export async function GET(req) {
|
||||
LIMIT $${(await params).length + 1} OFFSET $${(await params).length + 2}
|
||||
`, [...params, limit, offset]);
|
||||
|
||||
return Response.json({
|
||||
return jsonWithEtag(req, {
|
||||
data: r.rows,
|
||||
pagination: { page, limit, total, totalPages: Math.ceil(total / limit) },
|
||||
});
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
// GET /api/settings, PUT /api/settings
|
||||
import pool from '@/lib/db';
|
||||
import { getUser, requireAdmin } from '@/lib/auth';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
// 避免 GET 被静态优化导致 PUT 405(动态接口,不能缓存)
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET() {
|
||||
export async function GET(req) {
|
||||
try {
|
||||
// 确保 forum_name 始终存在(未设置过则初始化默认值),前端拿到后显示
|
||||
await pool.query(
|
||||
`INSERT INTO settings (key, value) VALUES ('forum_name', 'Forumlify')
|
||||
ON CONFLICT (key) DO NOTHING`
|
||||
);
|
||||
const r = await pool.query('SELECT key, value FROM settings');
|
||||
const r = await pool.query('SELECT key, value FROM settings ORDER BY key');
|
||||
const settings = {};
|
||||
r.rows.forEach((row) => { settings[row.key] = row.value; });
|
||||
// 兜底:即使插入失败也保证返回 forum_name
|
||||
if (!settings.forum_name) settings.forum_name = 'Forumlify';
|
||||
return Response.json(settings);
|
||||
return jsonWithEtag(req, settings);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// GET /api/users/profile/:username — 用户公开信息(无需登录,用于用户主页)
|
||||
import pool from '@/lib/db';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
export async function GET(req, { params }) {
|
||||
const { username } = await params;
|
||||
@@ -14,7 +15,7 @@ export async function GET(req, { params }) {
|
||||
if (r.rows.length === 0) {
|
||||
return Response.json({ error: '用户不存在' }, { status: 404 });
|
||||
}
|
||||
return Response.json(r.rows[0]);
|
||||
return jsonWithEtag(req, r.rows[0]);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user