mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
refactor(backend): adjust expiration time validation and improve Redis share info storage logic
This commit is contained in:
@@ -20,7 +20,7 @@ type CreateShareProps struct {
|
||||
}
|
||||
|
||||
type ShareConfig struct {
|
||||
ExpireAt int `json:"expire_time"`
|
||||
ExpireAt int `json:"expire_time"` // 分钟
|
||||
ViewNum int64 `json:"download_nums"`
|
||||
HasPassword bool `json:"has_password"`
|
||||
Password string `json:"password"`
|
||||
@@ -36,11 +36,10 @@ func CreateShareInfo(c echo.Context) error {
|
||||
if err := cc.Bind(r); err != nil {
|
||||
return utils.HTTPErrorHandler(c, err)
|
||||
}
|
||||
if r.Config.ExpireAt < 60 {
|
||||
if r.Config.ExpireAt < 1 {
|
||||
return utils.HTTPErrorHandler(c, errors.New("非法的分享过期时间"))
|
||||
}
|
||||
ExpireTime := time.Now().Add(time.Minute * time.Duration(r.Config.ExpireAt))
|
||||
|
||||
ExpireTime := time.Now().Add(time.Duration(r.Config.ExpireAt) * time.Minute)
|
||||
if r.Data == "" || (r.Type != models.ShareTypeFile && r.Type != models.ShareTypeText) || ExpireTime.Before(time.Now()) || r.Config.ViewNum < 1 {
|
||||
return utils.HTTPErrorHandler(c, errors.New("调用接口参数错误"))
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ func SetRedisShareInfo(shareId string, shareInfo RedisShareInfo) error {
|
||||
mergo.Merge(&shareInfo, old_shareInfo)
|
||||
}
|
||||
jsonData, _ := json.Marshal(shareInfo)
|
||||
|
||||
_, err = rdb.Set(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId), string(jsonData), time.Duration(shareInfo.ExpireAt)).Result()
|
||||
_, err = rdb.Set(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId), string(jsonData), time.Until(time.Unix(shareInfo.ExpireAt, 0))).Result()
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user