chore: add debug logging for comments

This commit is contained in:
Tim
2025-08-04 12:06:51 +08:00
parent 9b840ca769
commit 8a2adc5632
5 changed files with 67 additions and 8 deletions

View File

@@ -66,6 +66,7 @@ export default {
const submit = () => {
if (!vditorInstance.value || isDisabled.value) return
const value = vditorInstance.value.getValue()
console.debug('CommentEditor submit', value)
emit('submit', value)
vditorInstance.value.setValue('')
text.value = ''

View File

@@ -144,10 +144,12 @@ const CommentItem = {
toast.error('请先登录')
return
}
console.debug('Deleting comment', props.comment.id)
const res = await fetch(`${API_BASE_URL}/api/comments/${props.comment.id}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${token}` }
})
console.debug('Delete comment response status', res.status)
if (res.ok) {
toast.success('已删除')
emit('deleted', props.comment.id)
@@ -164,14 +166,17 @@ const CommentItem = {
isWaitingForReply.value = false
return
}
console.debug('Submitting reply', { parentId: props.comment.id, text })
try {
const res = await fetch(`${API_BASE_URL}/api/comments/${props.comment.id}/replies`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
body: JSON.stringify({ content: text })
})
console.debug('Submit reply response status', res.status)
if (res.ok) {
const data = await res.json()
console.debug('Submit reply response data', data)
const replyList = props.comment.reply || (props.comment.reply = [])
replyList.push({
id: data.id,
@@ -202,6 +207,7 @@ const CommentItem = {
toast.error('回复失败')
}
} catch (e) {
console.debug('Submit reply error', e)
toast.error('回复失败')
} finally {
isWaitingForReply.value = false

View File

@@ -370,6 +370,7 @@ export default {
const postComment = async (text) => {
if (!text.trim()) return
console.debug('Posting comment', { postId, text })
isWaitingPostingComment.value = true
const token = getToken()
if (!token) {
@@ -383,8 +384,10 @@ export default {
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
body: JSON.stringify({ content: text })
})
console.debug('Post comment response status', res.status)
if (res.ok) {
const data = await res.json()
console.debug('Post comment response data', data)
await fetchComments()
if (data.reward && data.reward > 0) {
toast.success(`评论成功,获得 ${data.reward} 经验值`)
@@ -397,6 +400,7 @@ export default {
toast.error('评论失败')
}
} catch (e) {
console.debug('Post comment error', e)
toast.error('评论失败')
} finally {
isWaitingPostingComment.value = false
@@ -538,20 +542,23 @@ export default {
const fetchComments = async () => {
isFetchingComments.value = true
console.debug('Fetching comments', { postId, sort: commentSort.value })
try {
const token = getToken()
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}/comments?sort=${commentSort.value}`, {
headers: { Authorization: token ? `Bearer ${token}` : '' }
})
console.debug('Fetch comments response status', res.status)
if (res.ok) {
const data = await res.json()
console.debug('Fetched comments count', data.length)
comments.value = data.map(mapComment)
isFetchingComments.value = false
await nextTick()
gatherPostItems()
}
} catch {
// ignore
} catch (e) {
console.debug('Fetch comments error', e)
} finally {
isFetchingComments.value = false
}