mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 10:34:20 +00:00
- Add configurable per-user token creation limit (max_user_tokens) - Sanitize search input patterns to prevent expensive queries - Add per-user search rate limiting (by user ID) - Add pagination to search endpoint with strict page size cap - Skip empty search fields instead of matching nothing - Hide internal errors from API responses - Fix Interface2String float64 formatting causing config parse failures - Add float-string fallback in config system for int/uint fields
29 lines
679 B
Go
29 lines
679 B
Go
package operation_setting
|
|
|
|
import "github.com/QuantumNous/new-api/setting/config"
|
|
|
|
// TokenSetting 令牌相关配置
|
|
type TokenSetting struct {
|
|
MaxUserTokens int `json:"max_user_tokens"` // 每用户最大令牌数量
|
|
}
|
|
|
|
// 默认配置
|
|
var tokenSetting = TokenSetting{
|
|
MaxUserTokens: 1000, // 默认每用户最多 1000 个令牌
|
|
}
|
|
|
|
func init() {
|
|
// 注册到全局配置管理器
|
|
config.GlobalConfig.Register("token_setting", &tokenSetting)
|
|
}
|
|
|
|
// GetTokenSetting 获取令牌配置
|
|
func GetTokenSetting() *TokenSetting {
|
|
return &tokenSetting
|
|
}
|
|
|
|
// GetMaxUserTokens 获取每用户最大令牌数量
|
|
func GetMaxUserTokens() int {
|
|
return GetTokenSetting().MaxUserTokens
|
|
}
|