支持动态更新管理员密码和下载次数逻辑完善,优化相关错误处理和配置更新流程

This commit is contained in:
2026-01-14 19:49:07 +08:00
parent 903d5b865e
commit e456d3a823
6 changed files with 75 additions and 19 deletions

View File

@@ -68,7 +68,9 @@ func (h *PickupHandler) DownloadBatch(c *gin.Context) {
}
// 增加下载次数
h.batchService.IncrementDownloadCount(batch.ID)
if err := h.batchService.IncrementDownloadCount(batch.ID); err != nil {
fmt.Printf("[DownloadBatch] Failed to increment download count for batch %s: %v\n", batch.ID, err)
}
}
type PickupHandler struct {
@@ -106,8 +108,11 @@ func (h *PickupHandler) Pickup(c *gin.Context) {
}
if batch.Type == "text" {
h.batchService.IncrementDownloadCount(batch.ID)
batch.DownloadCount++
if err := h.batchService.IncrementDownloadCount(batch.ID); err != nil {
fmt.Printf("[Pickup] Failed to increment download count for batch %s: %v\n", batch.ID, err)
} else {
batch.DownloadCount++
}
}
c.JSON(http.StatusOK, model.SuccessResponse(PickupResponse{
@@ -163,11 +168,19 @@ func (h *PickupHandler) DownloadFile(c *gin.Context) {
defer reader.Close()
// 增加下载次数
h.batchService.IncrementDownloadCount(batch.ID)
if err := h.batchService.IncrementDownloadCount(batch.ID); err != nil {
// 记录错误但不中断下载过程
fmt.Printf("[Download] Failed to increment download count for batch %s: %v\n", batch.ID, err)
}
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", item.OriginalName))
c.Header("Content-Type", item.MimeType)
c.Header("Content-Length", strconv.FormatInt(item.Size, 10))
// 如果是 HEAD 请求,只返回 Header
if c.Request.Method == http.MethodHead {
return
}
io.Copy(c.Writer, reader)
}