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 ( import (
"regexp" "regexp"
"strconv"
"strings" "strings"
"github.com/alist-org/alist/v3/internal/conf" "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, ",") conf.SlicesMap[conf.IgnoreDirectLinkParams] = strings.Split(item.Value, ",")
return nil 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) { func RegisterSettingItemHook(key string, hook SettingItemHook) {

View File

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