mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
Merge pull request #1170 from BianBianY/main
feat: optimization enable/disable auth files
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -48,3 +48,5 @@ _bmad-output/*
|
|||||||
# macOS
|
# macOS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
._*
|
._*
|
||||||
|
/.idea/
|
||||||
|
/data/
|
||||||
|
|||||||
@@ -86,12 +86,19 @@ func (s *FileSynthesizer) Synthesize(ctx *SynthesisContext) ([]*coreauth.Auth, e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disabled, _ := metadata["disabled"].(bool)
|
||||||
|
status := coreauth.StatusActive
|
||||||
|
if disabled {
|
||||||
|
status = coreauth.StatusDisabled
|
||||||
|
}
|
||||||
|
|
||||||
a := &coreauth.Auth{
|
a := &coreauth.Auth{
|
||||||
ID: id,
|
ID: id,
|
||||||
Provider: provider,
|
Provider: provider,
|
||||||
Label: label,
|
Label: label,
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
Status: coreauth.StatusActive,
|
Status: status,
|
||||||
|
Disabled: disabled,
|
||||||
Attributes: map[string]string{
|
Attributes: map[string]string{
|
||||||
"source": full,
|
"source": full,
|
||||||
"path": full,
|
"path": full,
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ func (s *FileTokenStore) Save(ctx context.Context, auth *cliproxyauth.Auth) (str
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
case auth.Metadata != nil:
|
case auth.Metadata != nil:
|
||||||
|
auth.Metadata["disabled"] = auth.Disabled
|
||||||
raw, errMarshal := json.Marshal(auth.Metadata)
|
raw, errMarshal := json.Marshal(auth.Metadata)
|
||||||
if errMarshal != nil {
|
if errMarshal != nil {
|
||||||
return "", fmt.Errorf("auth filestore: marshal metadata failed: %w", errMarshal)
|
return "", fmt.Errorf("auth filestore: marshal metadata failed: %w", errMarshal)
|
||||||
@@ -214,12 +215,18 @@ func (s *FileTokenStore) readAuthFile(path, baseDir string) (*cliproxyauth.Auth,
|
|||||||
return nil, fmt.Errorf("stat file: %w", err)
|
return nil, fmt.Errorf("stat file: %w", err)
|
||||||
}
|
}
|
||||||
id := s.idFor(path, baseDir)
|
id := s.idFor(path, baseDir)
|
||||||
|
disabled, _ := metadata["disabled"].(bool)
|
||||||
|
status := cliproxyauth.StatusActive
|
||||||
|
if disabled {
|
||||||
|
status = cliproxyauth.StatusDisabled
|
||||||
|
}
|
||||||
auth := &cliproxyauth.Auth{
|
auth := &cliproxyauth.Auth{
|
||||||
ID: id,
|
ID: id,
|
||||||
Provider: provider,
|
Provider: provider,
|
||||||
FileName: id,
|
FileName: id,
|
||||||
Label: s.labelFor(metadata),
|
Label: s.labelFor(metadata),
|
||||||
Status: cliproxyauth.StatusActive,
|
Status: status,
|
||||||
|
Disabled: disabled,
|
||||||
Attributes: map[string]string{"path": path},
|
Attributes: map[string]string{"path": path},
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
CreatedAt: info.ModTime(),
|
CreatedAt: info.ModTime(),
|
||||||
|
|||||||
@@ -681,6 +681,10 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
|||||||
if a == nil || a.ID == "" {
|
if a == nil || a.ID == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if a.Disabled {
|
||||||
|
GlobalModelRegistry().UnregisterClient(a.ID)
|
||||||
|
return
|
||||||
|
}
|
||||||
authKind := strings.ToLower(strings.TrimSpace(a.Attributes["auth_kind"]))
|
authKind := strings.ToLower(strings.TrimSpace(a.Attributes["auth_kind"]))
|
||||||
if authKind == "" {
|
if authKind == "" {
|
||||||
if kind, _ := a.AccountInfo(); strings.EqualFold(kind, "api_key") {
|
if kind, _ := a.AccountInfo(); strings.EqualFold(kind, "api_key") {
|
||||||
|
|||||||
Reference in New Issue
Block a user