feat(register-and-statistics): improve role handling logic

pull/9277/head
okatu-loli 2025-08-18 15:39:35 +08:00
parent 94a7790d61
commit 7fe2f9a7eb
2 changed files with 14 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package op
import (
"regexp"
"strconv"
"strings"
"github.com/alist-org/alist/v3/internal/conf"
@ -82,6 +83,18 @@ var settingItemHooks = map[string]SettingItemHook{
conf.SlicesMap[conf.IgnoreDirectLinkParams] = strings.Split(item.Value, ",")
return nil
},
conf.DefaultRole: func(item *model.SettingItem) error {
v := strings.TrimSpace(item.Value)
if v == "" {
return nil
}
r, err := GetRoleByName(v)
if err != nil {
return err
}
item.Value = strconv.Itoa(int(r.ID))
return nil
},
}
func RegisterSettingItemHook(key string, hook SettingItemHook) {

View File

@ -117,12 +117,7 @@ func Register(c *gin.Context) {
common.ErrorResp(c, err, 500, true)
return
}
token, err := common.GenerateToken(user)
if err != nil {
common.ErrorResp(c, err, 500, true)
return
}
common.SuccessResp(c, gin.H{"token": token})
common.SuccessResp(c)
}
type UserResp struct {