♻️ refactor: Refactor chat links

This commit is contained in:
Martial BE
2024-04-27 20:50:36 +08:00
parent c6a0c87ad1
commit 801b98d6fc
18 changed files with 574 additions and 41 deletions

View File

@@ -70,6 +70,7 @@ func InitOptionMap() {
common.OptionMap["GroupRatio"] = common.GroupRatio2JSONString()
common.OptionMap["TopUpLink"] = common.TopUpLink
common.OptionMap["ChatLink"] = common.ChatLink
common.OptionMap["ChatLinks"] = common.ChatLinks
common.OptionMap["QuotaPerUnit"] = strconv.FormatFloat(common.QuotaPerUnit, 'f', -1, 64)
common.OptionMap["RetryTimes"] = strconv.Itoa(common.RetryTimes)
common.OptionMap["RetryCooldownSeconds"] = strconv.Itoa(common.RetryCooldownSeconds)
@@ -166,6 +167,7 @@ var optionStringMap = map[string]*string{
"TurnstileSecretKey": &common.TurnstileSecretKey,
"TopUpLink": &common.TopUpLink,
"ChatLink": &common.ChatLink,
"ChatLinks": &common.ChatLinks,
"LarkClientId": &common.LarkClientId,
"LarkClientSecret": &common.LarkClientSecret,
}

View File

@@ -115,6 +115,16 @@ func GetTokenById(id int) (*Token, error) {
return &token, err
}
func GetTokenByName(name string) (*Token, error) {
if name == "" {
return nil, errors.New("name 为空!")
}
token := Token{Name: name}
var err error = nil
err = DB.First(&token, "name = ?", name).Error
return &token, err
}
func (token *Token) Insert() error {
if token.ChatCache && !common.ChatCacheEnabled {
token.ChatCache = false