fix: reply chain uses reply_to_id (UUID) instead of reply_to_username

- reply_to_id UUID FK: precise parent tracking (username was ambiguous
  when same user wrote multiple replies in a chain)
- GET /api/replies: JOIN replies + users to return reply_to_username
- POST /api/replies: accept reply_to_id (UUID) instead of reply_to_username
- Frontend depth calc: follow reply_to_id chain (not username)
- Preview bar: resolve username from local replies by ID
- Indicator scroll: target by data-reply-id
This commit is contained in:
lezi-fun committed 2026-08-11 21:38:45 +08:00
1 parent 59d5fb89c0
commit 6c100ff3a1
3 files changed
+22 -18

No files matched your search

+6 -5
View File
@@ -8,10 +8,11 @@ export async function GET(req, { params }) {
try {
const r = await pool.query(
`SELECT r.*, u.username, u.avatar_url,
rt.username AS reply_to_username
ru.username AS reply_to_username
FROM replies r
JOIN users u ON r.user_id = u.id
LEFT JOIN users rt ON r.reply_to_username = rt.username
LEFT JOIN replies rt ON r.reply_to_id = rt.id
LEFT JOIN users ru ON rt.user_id = ru.id
WHERE r.post_id = $1
ORDER BY r.created_at ASC`,
[(await params).id]
@@ -27,7 +28,7 @@ export async function POST(req, { params }) {
if (!user) {
return Response.json({ error: '请先登录' }, { status: 401 });
}
const { content, captcha_id, captcha_answer, captcha_sig, reply_to_username } = await req.json();
const { content, captcha_id, captcha_answer, captcha_sig, reply_to_id } = await req.json();
if (!content || content.trim().length === 0) {
return Response.json({ error: '请填写回复内容' }, { status: 400 });
}
@@ -37,10 +38,10 @@ export async function POST(req, { params }) {
}
try {
const r = await pool.query(
`INSERT INTO replies (post_id, user_id, content, reply_to_username)
`INSERT INTO replies (post_id, user_id, content, reply_to_id)
VALUES ($1, $2, $3, $4)
RETURNING *`,
[(await params).id, user.id, content, reply_to_username || null]
[(await params).id, user.id, content, reply_to_id || null]
);
await pool.query('UPDATE posts SET updated_at = NOW() WHERE id = $1', [(await params).id]);
return Response.json(r.rows[0]);