feat: edit post images (upload/remove) + fix captcha input in dark mode

- PostDetail edit modal: show existing images with delete button, upload
  new images (multi-file, 5MB limit), save replaces image list
- API PUT /posts/:id accepts images array; omitting keeps original
- lib/api updatePost passes images
- NewPost/ReplyList captcha answer input: use CSS vars (was hardcoded
  #e2e8f0 border with white bg — glaring in dark mode)
This commit is contained in:
lezi-fun committed 2026-08-10 17:41:46 +08:00
1 parent ebc5201569
commit 4a30e79269
5 files changed
+60 -12

No files matched your search

+5 -4
View File
@@ -33,19 +33,20 @@ export async function PUT(req, { params }) {
if (!user) {
return Response.json({ error: '请先登录' }, { status: 401 });
}
const { title, content } = await req.json();
const { title, content, images } = await req.json();
if (!content || content.trim().length === 0) {
return Response.json({ error: '请填写内容' }, { status: 400 });
}
try {
const post = await pool.query('SELECT user_id FROM posts WHERE id = $1', [params.id]);
const post = await pool.query('SELECT user_id, images FROM posts WHERE id = $1', [params.id]);
if (post.rows.length === 0) return invalidId();
if (post.rows[0].user_id !== user.id) {
return Response.json({ error: '无权限编辑此帖子' }, { status: 403 });
}
// images: 可选,传入完整图片 URL 数组(编辑时替换全部图片);不传则保留原图
const r = await pool.query(
`UPDATE posts SET title = $1, content = $2, edited_at = NOW() WHERE id = $3 RETURNING *`,
[title || '无标题', content, params.id]
`UPDATE posts SET title = $1, content = $2, images = $3, edited_at = NOW() WHERE id = $4 RETURNING *`,
[title || '无标题', content, Array.isArray(images) ? images : post.rows[0].images || [], params.id]
);
return Response.json(r.rows[0]);
} catch {