mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 15:13:30 +00:00
fix(backend): adjust view count decrement logic in VaildateShare to prevent multiple decrements during concurrent downloads
This commit is contained in:
@@ -42,14 +42,8 @@ func DownloadShare(c echo.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
models.SetRedisShareInfo(claims.ShareId, models.RedisShareInfo{
|
||||
ViewNum: shareInfo.ViewNum - 1,
|
||||
})
|
||||
return cc.Attachment(fmt.Sprintf("%s/%s", uploadPath, utils.GetFileId(fileInfo.FileHash, fileInfo.FileSize)), shareInfo.FileName)
|
||||
}
|
||||
models.SetRedisShareInfo(claims.ShareId, models.RedisShareInfo{
|
||||
ViewNum: shareInfo.ViewNum - 1,
|
||||
})
|
||||
return utils.HTTPSuccessHandler(c, map[string]any{
|
||||
"data": shareInfo.Data,
|
||||
})
|
||||
@@ -105,6 +99,17 @@ func VaildateShare(c echo.Context) error {
|
||||
if fileInfo.FileType != models.FileTypeUpload {
|
||||
return utils.HTTPErrorHandler(c, errors.New("分享文件状态错误"))
|
||||
}
|
||||
}
|
||||
// download_nums 必须放在创建token的时候减掉,不然多线程下载会导致多次减掉
|
||||
latestViewNum := shareInfo.ViewNum - 1
|
||||
// 如果下载次数为0,则设置为-1 防止空值问题
|
||||
if latestViewNum < 1 {
|
||||
latestViewNum = -1
|
||||
}
|
||||
models.SetRedisShareInfo(r.ShareId, models.RedisShareInfo{
|
||||
ViewNum: latestViewNum,
|
||||
})
|
||||
if shareInfo.Type == models.ShareTypeFile {
|
||||
return utils.HTTPSuccessHandler(c, map[string]any{
|
||||
"token": downloadToken,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user