mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 12:20:52 +08:00
fix(auth): Improve file-based auth handling and consistency
This commit is contained in:
@@ -526,8 +526,14 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
|
|||||||
if email, _ := metadata["email"].(string); email != "" {
|
if email, _ := metadata["email"].(string); email != "" {
|
||||||
label = email
|
label = email
|
||||||
}
|
}
|
||||||
|
// Use relative path under authDir as ID to stay consistent with FileStore
|
||||||
|
id := full
|
||||||
|
if rel, errRel := filepath.Rel(w.authDir, full); errRel == nil && rel != "" {
|
||||||
|
id = rel
|
||||||
|
}
|
||||||
|
|
||||||
a := &coreauth.Auth{
|
a := &coreauth.Auth{
|
||||||
ID: full,
|
ID: id,
|
||||||
Provider: provider,
|
Provider: provider,
|
||||||
Label: label,
|
Label: label,
|
||||||
Status: coreauth.StatusActive,
|
Status: coreauth.StatusActive,
|
||||||
|
|||||||
@@ -64,6 +64,15 @@ func (s *FileStore) Save(ctx context.Context, auth *Auth) error {
|
|||||||
if path == "" {
|
if path == "" {
|
||||||
return fmt.Errorf("auth filestore: missing file path attribute for %s", auth.ID)
|
return fmt.Errorf("auth filestore: missing file path attribute for %s", auth.ID)
|
||||||
}
|
}
|
||||||
|
// If the auth has been disabled and the original file was removed, avoid
|
||||||
|
// recreating it on disk. This lets operators delete auth files explicitly.
|
||||||
|
if auth.Disabled {
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user