logo和配置修改

This commit is contained in:
谢宇宁
2026-09-23 16:50:34 +07:00
parent bef9f8b4ed
commit 0db8087765
163 changed files with 393 additions and 20366 deletions
-228
View File
@@ -3,11 +3,8 @@ package web
import (
"net/http"
"strconv"
"strings"
"unicode/utf8"
"videoweb/app/service/commentser"
"videoweb/pub/common/log"
"videoweb/pub/common/useragent"
"github.com/gin-gonic/gin"
)
@@ -55,228 +52,3 @@ func CommentList(c *gin.Context) {
"data": data,
})
}
type commentSendBody struct {
ObjectID int64 `json:"objectId"`
ObjectType int `json:"objectType"`
Text string `json:"text"`
ParentsID int64 `json:"parentsId"`
ReplyCommentID int64 `json:"replyCommentId"`
}
// CommentSend 代理上游 POST /api/app/comment/send。
// parentsId=0 一级评论;parentsId>0 二级评论;replyCommentId 为实际被回复评论。
func CommentSend(c *gin.Context) {
if useragent.TokenFromRequest(c.Request) == "" {
c.JSON(http.StatusOK, gin.H{
"code": 401,
"msg": "unauthorized",
"tip": "请先登录后再发表评论",
"data": nil,
})
return
}
var body commentSendBody
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "参数错误",
"data": nil,
})
return
}
body.Text = strings.TrimSpace(body.Text)
if body.ObjectID <= 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "缺少 objectId",
"data": nil,
})
return
}
if body.ObjectType != commentser.ObjectTypeChapter {
body.ObjectType = commentser.ObjectTypePlaylet
}
if body.Text == "" {
c.JSON(http.StatusOK, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "请输入评论内容",
"data": nil,
})
return
}
if utf8.RuneCountInString(body.Text) > 200 {
c.JSON(http.StatusOK, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "评论最多 200 字",
"data": nil,
})
return
}
if body.ParentsID < 0 {
body.ParentsID = 0
}
if body.ReplyCommentID < 0 {
body.ReplyCommentID = 0
}
env, err := commentser.Send(c, commentser.CommentSendReq{
ObjectID: body.ObjectID,
ObjectType: body.ObjectType,
Text: body.Text,
ParentsID: body.ParentsID,
ReplyCommentID: body.ReplyCommentID,
})
if err != nil {
log.Error("comment send upstream failed", log.E(err))
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "comment send failed",
"tip": "发表失败,请稍后重试",
"data": nil,
})
return
}
if env != nil && TryJSONSessionRecover(c, env.Code) {
env, err = commentser.Send(c, commentser.CommentSendReq{
ObjectID: body.ObjectID,
ObjectType: body.ObjectType,
Text: body.Text,
ParentsID: body.ParentsID,
ReplyCommentID: body.ReplyCommentID,
})
if err != nil {
log.Error("comment send retry failed", log.E(err))
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "comment send failed",
"tip": "发表失败,请稍后重试",
"data": nil,
})
return
}
}
if env == nil || env.Code != 200 {
tip := "发表失败"
msg := ""
code := 500
if env != nil {
code = env.Code
msg = env.Msg
tip = firstNonEmpty(env.Tip, env.Msg, tip)
}
c.JSON(http.StatusOK, gin.H{
"code": code,
"msg": msg,
"tip": tip,
"data": nil,
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"msg": firstNonEmpty(env.Msg, "success"),
"tip": firstNonEmpty(env.Tip, "发表成功"),
"data": env.Data,
})
}
type commentLikeBody struct {
CommentID int64 `json:"commentId"`
IsLike *bool `json:"isLike"`
}
// CommentLikeSet 代理上游 POST /api/app/comment/like/set。
func CommentLikeSet(c *gin.Context) {
if useragent.TokenFromRequest(c.Request) == "" {
c.JSON(http.StatusOK, gin.H{
"code": 401,
"msg": "unauthorized",
"tip": "请先登录后再点赞",
"data": nil,
})
return
}
var body commentLikeBody
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "参数错误",
"data": nil,
})
return
}
if body.CommentID <= 0 || body.IsLike == nil {
c.JSON(http.StatusOK, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "缺少 commentId 或 isLike",
"data": nil,
})
return
}
env, err := commentser.LikeSet(c, commentser.CommentLikeSetReq{
CommentID: body.CommentID,
IsLike: *body.IsLike,
})
if err != nil {
log.Error("comment like set upstream failed", log.E(err))
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "comment like failed",
"tip": "操作失败,请稍后重试",
"data": nil,
})
return
}
if env != nil && TryJSONSessionRecover(c, env.Code) {
env, err = commentser.LikeSet(c, commentser.CommentLikeSetReq{
CommentID: body.CommentID,
IsLike: *body.IsLike,
})
if err != nil {
log.Error("comment like set retry failed", log.E(err))
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "comment like failed",
"tip": "操作失败,请稍后重试",
"data": nil,
})
return
}
}
if env == nil || env.Code != 200 {
tip := "操作失败"
msg := ""
code := 500
if env != nil {
code = env.Code
msg = env.Msg
tip = firstNonEmpty(env.Tip, env.Msg, tip)
}
c.JSON(http.StatusOK, gin.H{
"code": code,
"msg": msg,
"tip": tip,
"data": nil,
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"msg": firstNonEmpty(env.Msg, "success"),
"tip": firstNonEmpty(env.Tip, "成功"),
"data": env.Data,
})
}