refactor: 移除全局单例、修复分层违规、统一错误与响应
Some checks failed
Build / build (push) Successful in 7m52s
Build / build-docker (push) Has been cancelled

This commit is contained in:
lafay
2026-06-15 16:40:36 +08:00
parent d9de39a0a3
commit 7d1c78f965
55 changed files with 593 additions and 1744 deletions

View File

@@ -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)
}()
// 流式传输文件内容