Skip to content

Commit 6b21a16

Browse files
authored
feat: 新增评论审核功能 (#15)
1 parent ec76f67 commit 6b21a16

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/client/i18n/cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"sendError": "评论失败~",
2121
"more": "更多评论",
2222
"notComments": "没有评论",
23+
"commentsAudit": "您的评论可能需要通过审核后才能显示",
2324
"commentsError": "获取评论失败~",
2425
"settingMsg": "正在加载管理面板...",
2526
"refreshMsg": "正在刷新评论...",

src/client/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"sendError": "Comment failed~",
2121
"more": "More",
2222
"notComments": "Not Comments",
23+
"commentsAudit": "Your comment may need to be moderated before it can be displayed",
2324
"commentsError": "Failed to get comments~",
2425
"settingMsg": "Loading admin panel...",
2526
"refreshMsg": "Refreshing comments...",

src/client/view/submit.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@
239239
$msg({ type: 'error', text: translate('pleaseLogin') })
240240
}
241241
242-
if (result.data instanceof Array) {
242+
if (Array.isArray(result.data)) {
243+
if (!result.data.length) $msg({ type: 'success', duration: 5000, text: translate('commentsAudit') })
244+
243245
dispatch('submitComment', { comment: result.data, pid })
244246
metas.content.value = ''
245247
SaveInfo()

src/server/router/comment.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const {
1313
} = require('../utils/commentUtils')
1414
const { IndexHandler, DeepClone, VerifyParams, akismet } = require('../utils')
1515

16+
const { D_AUDIT } = process.env
17+
1618
/* eslint-disable max-statements */
1719
// 获取评论
1820
async function GetComment(params) {
@@ -111,8 +113,8 @@ async function CommitComment(params) {
111113
useragent: params.ua
112114
}
113115
params.status = await akismet(config.akismet, config.siteUrl, akismetData)
116+
if (D_AUDIT) params.status = 'audit'
114117
}
115-
116118
const data = await CommitCommentHandler(params)
117119

118120
// 保存评论
@@ -126,8 +128,9 @@ async function CommitComment(params) {
126128
delete data.token
127129
delete data.type
128130

131+
if (params.status === 'audit') return []
129132
if (result) return CommentHandler([result])
130-
return false
133+
return []
131134
}
132135
/* eslint-enable max-statements */
133136

0 commit comments

Comments
 (0)