Skip to content

Commit

Permalink
增加评论字数限制
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry committed Apr 23, 2024
1 parent 0b267d4 commit d27d245
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions components/FriendsCommentInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,22 @@ const saveComment = async () => {
toast.warning('先填写评论')
return
}
if(content.value.length >120){
toast.warning('评论超长')
return
}
if (!info.value.username) {
toast.warning('用户名必填')
return
}
if(info.value.username.length >10){
toast.warning('用户名')
return
}
if(info.value.website.length >30){
toast.warning('网站地址超长')
return
}
pending.value = true
const res = await $fetch('/api/comment/save', {
method: 'POST',
Expand Down
11 changes: 11 additions & 0 deletions server/api/comment/save.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ export default defineEventHandler(async (event) => {
const { memoId, content, replyTo, username, email, website } =
(await readBody(event)) as SaveCommentReq;
const userId = event.context.userId;

if(content.length >120){
return {success:false}
}
if(username.length >10){
return {success:false}
}
if(website && website.length >30){
return {success:false}
}

await prisma.comment.create({
data: {
content,
Expand Down

0 comments on commit d27d245

Please sign in to comment.