优化结构

This commit is contained in:
Yvan
2026-08-28 16:23:52 +08:00
parent 9b1daaf3f6
commit 295ee5c49e
24 changed files with 128 additions and 145 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ package handler
import (
"errors"
"kra/internal/biz/system"
"kra/internal/service/dto"
systemservice "kra/internal/service/system"
"net/http"
@@ -16,7 +17,7 @@ func NewMedia(service *systemservice.MediaService) *Media { return &Media{servic
func (h *Media) limitMultipartBody(c *gin.Context) int64 {
limit := h.service.MediaConfig().EffectiveMaxFileSize()
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, limit+(1<<20))
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, limit+system.UploadBodyOverhead)
return limit
}
+1 -6
View File
@@ -45,7 +45,7 @@ func Fail(c *gin.Context, message string) { Write(c, CodeError, gin.H{}, message
func sanitizeFailureMessage(message string) string {
message = strings.TrimSpace(message)
lower := strings.ToLower(message)
for _, marker := range []string{"gorm", "sql:", "redis", "mysql", "mongo", "dial ", "connection", "provider", "sdk", "json:", "serialize", "timeout", "http 4", "http 5", "tls:"} {
for _, marker := range []string{"gorm", "sql:", "redis", "mysql", "mongo", "dial ", "connection", "provider", "sdk", "json:", "serialize", "timeout", "http 4", "http 5", "tls:", "record not found", "error 1062"} {
if strings.Contains(lower, marker) {
return "操作失败"
}
@@ -53,11 +53,6 @@ func sanitizeFailureMessage(message string) string {
if strings.Contains(message, "失败:") {
return strings.TrimSpace(strings.SplitN(message, "失败:", 2)[0]) + "失败"
}
for _, marker := range []string{"参数", "不能为空", "无效", "不存在", "权限", "未登录", "验证码", "密码", "重复", "不支持", "超出", "分片", "上传", "文件", "名称", "令牌", "token"} {
if strings.Contains(message, marker) {
return message
}
}
return message
}
+1 -1
View File
@@ -44,7 +44,7 @@ func AccessLog(runtime *config.Store, logger *slog.Logger, version string) gin.H
if admin != nil && admin.Media != nil {
mediaSettings.MaxFileSize = admin.Media.MaxFileSize
}
bodyLimit = mediaSettings.EffectiveMaxFileSize() + (1 << 20)
bodyLimit = mediaSettings.EffectiveMaxFileSize() + system.UploadBodyOverhead
}
bytesIn := c.Request.ContentLength
logLimit := 1024