refactor: 移除全局单例、修复分层违规、统一错误与响应
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"carrotskin/internal/container"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -233,9 +234,12 @@ func (h *CustomSkinHandler) GetTexture(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 增加下载计数(异步)
|
||||
// 增加下载计数(异步,使用独立 ctx 避免请求取消时丢失计数)
|
||||
go func() {
|
||||
_ = h.container.TextureRepo.IncrementDownloadCount(ctx, texture.ID)
|
||||
// 复制 ctx 但不传播取消,配合超时防止 Redis 永久阻塞
|
||||
asyncCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = h.container.TextureService.IncrementDownload(asyncCtx, texture.ID)
|
||||
}()
|
||||
|
||||
// 流式传输文件内容
|
||||
|
||||
Reference in New Issue
Block a user