门禁兼容修复

This commit is contained in:
andy committed 2026-09-05 17:36:23 +08:00
1 parent f60b416949
commit 801c0af692
18 files changed
+257 -87

No files matched your search

+10 -9
View File
@@ -32,11 +32,12 @@ type ChatUseCase interface {
// ChatOptions contains the independently authenticated user-facing transport settings.
type ChatOptions struct {
AuthToken string
AllowedOrigins []string
MaxBodyBytes int64
RunTimeout time.Duration
Logger *log.Logger
AuthToken string
AllowLegacyShortToken bool
AllowedOrigins []string
MaxBodyBytes int64
RunTimeout time.Duration
Logger *log.Logger
}
// ChatHandler exposes a bounded SSE chat API without exposing provider credentials or sessions.
@@ -54,8 +55,8 @@ func NewChatHandler(chat ChatUseCase, options ChatOptions) (*ChatHandler, error)
if chat == nil {
return nil, errors.New("chat service is required")
}
if !validChatToken(options.AuthToken) {
return nil, errors.New("chat auth token must contain at least 32 printable ASCII characters")
if !validChatToken(options.AuthToken, options.AllowLegacyShortToken) {
return nil, errors.New("chat auth token is outside the configured printable ASCII length policy")
}
if options.MaxBodyBytes <= 0 || options.MaxBodyBytes > maximumChatBodyBytes {
return nil, errors.New("chat max body bytes is outside the supported range")
@@ -389,8 +390,8 @@ func publicChatError(err error) (int, string, string) {
}
}
func validChatToken(value string) bool {
if len(value) < 32 || len(value) > 4096 {
func validChatToken(value string, allowLegacyShortToken bool) bool {
if value == "" || len(value) > 4096 || (!allowLegacyShortToken && len(value) < 32) {
return false
}
for _, character := range value {