refactor: deprecate int32 (#7025)

* refactor: deprecate int32

* fix(db): reject legacy user quota schemas at startup

* fix(quota): enforce wallet bounds and saturating billing conversions

* fix(rate-limit): keep count*duration from wrapping int64

* fix: error message
This commit is contained in:
Seefs
2026-08-26 20:57:54 +08:00
committed by GitHub
parent 2d8e50bf36
commit a073f74b38
35 changed files with 445 additions and 116 deletions
+13 -1
View File
@@ -175,7 +175,7 @@ func Redeem(key string, userId int) (quota int, err error) {
if result.RowsAffected == 0 {
return errors.New("该兑换码已被使用")
}
return tx.Model(&User{}).Where("id = ?", userId).Update("quota", gorm.Expr("quota + ?", redemption.Quota)).Error
return creditTopUpQuota(tx, userId, redemption.Quota, nil)
})
if err != nil {
common.SysError("redemption failed: " + err.Error())
@@ -187,6 +187,12 @@ func Redeem(key string, userId int) (quota int, err error) {
}
func (redemption *Redemption) Insert() error {
if redemption.Quota <= 0 {
return errors.New("redemption quota must be positive")
}
if err := common.ValidateWalletQuota(redemption.Quota); err != nil {
return err
}
var err error
err = DB.Create(redemption).Error
return err
@@ -199,6 +205,12 @@ func (redemption *Redemption) SelectUpdate() error {
// Update Make sure your token's fields is completed, because this will update non-zero values
func (redemption *Redemption) Update() error {
if redemption.Quota <= 0 {
return errors.New("redemption quota must be positive")
}
if err := common.ValidateWalletQuota(redemption.Quota); err != nil {
return err
}
var err error
err = DB.Model(redemption).Select("name", "status", "quota", "redeemed_time", "expired_time").Updates(redemption).Error
return err