修补bug

This commit is contained in:
李志强 2026-04-09 18:19:23 +08:00
parent f84df652d9
commit 3d1a1c9711
2 changed files with 72 additions and 9 deletions

View File

@ -9,15 +9,59 @@ import (
"time"
"server/models"
"server/services"
"server/pkg/jwtutil"
beego "github.com/beego/beego/v2/server/web"
"github.com/qiniu/go-sdk/v7/auth/qbox"
"github.com/qiniu/go-sdk/v7/storage"
)
// QiniuUploadController 七牛云上传控制器
type QiniuUploadController struct {
BaseController
beego.Controller
}
// platformClaims 获取平台端 JWT claims
func (c *QiniuUploadController) platformClaims() (*jwtutil.Claims, error) {
auth := c.Ctx.Request.Header.Get("Authorization")
if auth == "" {
return nil, fmt.Errorf("未登录")
}
parts := strings.Split(auth, " ")
if len(parts) != 2 || parts[0] != "Bearer" {
return nil, fmt.Errorf("token 格式错误")
}
claims, err := jwtutil.ParseToken(parts[1])
if err != nil {
return nil, fmt.Errorf("token 无效")
}
return claims, nil
}
// effectiveTid 获取有效的租户 ID
func (c *QiniuUploadController) effectiveTid(claims *jwtutil.Claims) uint64 {
if claims.TenantID != nil && *claims.TenantID > 0 {
return *claims.TenantID
}
return 0
}
// jsonErr 返回错误响应
func (c *QiniuUploadController) jsonErr(httpStatus, bizCode int, msg string) {
c.Ctx.Output.SetStatus(httpStatus)
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
_ = c.ServeJSON()
}
// jsonOK 返回成功响应
func (c *QiniuUploadController) jsonOK(data interface{}) {
c.Data["json"] = map[string]interface{}{"code": 200, "data": data}
_ = c.ServeJSON()
}
// ParseJSON 解析 JSON 请求体
func (c *QiniuUploadController) ParseJSON(v interface{}) error {
return c.Ctx.Input.Bind(v)
}
// GetUploadToken 获取上传凭证
@ -143,8 +187,8 @@ func (c *QiniuUploadController) SaveFileRecord() {
}
// 检测文件类型
ext := getFileExt(req.Name)
fileType := detectFileType(ext)
ext := getQiniuFileExt(req.Name)
fileType := detectQiniuFileType(ext)
// 保存文件记录
adminID := uint64(claims.UserID)
@ -177,7 +221,7 @@ func (c *QiniuUploadController) SaveFileRecord() {
// GetStorageConfig 获取存储配置(前端用于判断上传方式)
// GET /platform/storage/config
func (c *QiniuUploadController) GetStorageConfig() {
claims, err := c.platformClaims()
_, err := c.platformClaims()
if err != nil {
c.jsonErr(401, 401, err.Error())
return
@ -219,8 +263,8 @@ func getQiniuUploadURL(region string) string {
}
}
// getFileExt 获取文件扩展名
func getFileExt(filename string) string {
// getQiniuFileExt 获取文件扩展名
func getQiniuFileExt(filename string) string {
parts := strings.Split(filename, ".")
if len(parts) > 1 {
return strings.ToLower(parts[len(parts)-1])
@ -228,8 +272,8 @@ func getFileExt(filename string) string {
return ""
}
// detectFileType 检测文件类型
func detectFileType(ext string) uint8 {
// detectQiniuFileType 检测文件类型
func detectQiniuFileType(ext string) uint8 {
imageExts := map[string]bool{
"jpg": true, "jpeg": true, "png": true, "gif": true, "bmp": true,
"webp": true, "svg": true, "ico": true,

19
scripts/quick-restart.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# 快速重启脚本
echo "停止服务..."
systemctl stop go-api
pkill -f "go run main.go"
echo "启动服务..."
systemctl start go-api
echo "等待服务启动..."
sleep 3
echo "查看服务状态..."
systemctl status go-api --no-pager
echo ""
echo "查看最近日志..."
tail -n 20 /www/wwwroot/api.yunzer.cn/go.log