mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 04:20:47 +00:00
fix: passkey rpid detect
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
package system_setting
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"one-api/common"
|
||||
"one-api/setting/config"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PasskeySettings struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
RPDisplayName string `json:"rp_display_name"`
|
||||
RPID string `json:"rp_id"`
|
||||
Origins []string `json:"origins"`
|
||||
AllowInsecureOrigin bool `json:"allow_insecure_origin"`
|
||||
UserVerification string `json:"user_verification"`
|
||||
AttachmentPreference string `json:"attachment_preference"`
|
||||
Enabled bool `json:"enabled"`
|
||||
RPDisplayName string `json:"rp_display_name"`
|
||||
RPID string `json:"rp_id"`
|
||||
Origins string `json:"origins"`
|
||||
AllowInsecureOrigin bool `json:"allow_insecure_origin"`
|
||||
UserVerification string `json:"user_verification"`
|
||||
AttachmentPreference string `json:"attachment_preference"`
|
||||
}
|
||||
|
||||
var defaultPasskeySettings = PasskeySettings{
|
||||
Enabled: false,
|
||||
RPDisplayName: common.SystemName,
|
||||
RPID: "",
|
||||
Origins: []string{},
|
||||
Origins: "",
|
||||
AllowInsecureOrigin: false,
|
||||
UserVerification: "preferred",
|
||||
AttachmentPreference: "",
|
||||
@@ -30,5 +32,15 @@ func init() {
|
||||
}
|
||||
|
||||
func GetPasskeySettings() *PasskeySettings {
|
||||
if defaultPasskeySettings.RPID == "" && ServerAddress != "" {
|
||||
// 从ServerAddress提取域名作为RPID
|
||||
// ServerAddress可能是 "https://newapi.pro" 这种格式
|
||||
serverAddr := strings.TrimSpace(ServerAddress)
|
||||
if parsed, err := url.Parse(serverAddr); err == nil && parsed.Host != "" {
|
||||
defaultPasskeySettings.RPID = parsed.Host
|
||||
} else {
|
||||
defaultPasskeySettings.RPID = serverAddr
|
||||
}
|
||||
}
|
||||
return &defaultPasskeySettings
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user