Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package commentser
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"unicode/utf8"
|
|
"videoweb/app/service/upstream"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const sendPath = "/api/app/comment/send"
|
|
|
|
// Send 发布评论(一级 / 二级)。
|
|
func Send(c *gin.Context, req CommentSendReq) (*APIEnvelope[any], error) {
|
|
req.Text = strings.TrimSpace(req.Text)
|
|
if req.ObjectID <= 0 {
|
|
return nil, fmt.Errorf("comment send invalid objectId")
|
|
}
|
|
if req.ObjectType != ObjectTypeChapter {
|
|
req.ObjectType = ObjectTypePlaylet
|
|
}
|
|
if req.Text == "" {
|
|
return nil, fmt.Errorf("comment send empty text")
|
|
}
|
|
if utf8.RuneCountInString(req.Text) > 200 {
|
|
return nil, fmt.Errorf("comment send text too long")
|
|
}
|
|
if req.ParentsID < 0 {
|
|
req.ParentsID = 0
|
|
}
|
|
if req.ReplyCommentID < 0 {
|
|
req.ReplyCommentID = 0
|
|
}
|
|
// 二级评论:未显式指定 replyCommentId 时默认回复父评论
|
|
if req.ParentsID > 0 && req.ReplyCommentID <= 0 {
|
|
req.ReplyCommentID = req.ParentsID
|
|
}
|
|
|
|
var env APIEnvelope[any]
|
|
if _, err := upstream.PostJSON(c, sendPath, req, &env); err != nil {
|
|
return nil, err
|
|
}
|
|
return &env, nil
|
|
}
|