mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-03-09 15:25:17 +00:00
- 在 BackgroundRefresher 中添加 onTokenRefreshed 回调函数和并发安全锁 - 实现 WithOnTokenRefreshed 选项函数用于设置刷新成功回调 - 在 RefreshManager 中添加 SetOnTokenRefreshed 方法支持运行时更新回调 - 为 KiroExecutor 添加 reloadAuthFromFile 方法实现文件重新加载回退机制 - 在 Watcher 中实现 NotifyTokenRefreshed 方法处理刷新通知并更新内存Auth对象 - 通过 Service.GetWatcher 连接刷新器回调到 Watcher 通知链路 - 添加方案A和方案B双重保障解决后台刷新与内存对象时间差问题
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package cliproxy
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/watcher"
|
|
coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/config"
|
|
)
|
|
|
|
func defaultWatcherFactory(configPath, authDir string, reload func(*config.Config)) (*WatcherWrapper, error) {
|
|
w, err := watcher.NewWatcher(configPath, authDir, reload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &WatcherWrapper{
|
|
start: func(ctx context.Context) error {
|
|
return w.Start(ctx)
|
|
},
|
|
stop: func() error {
|
|
return w.Stop()
|
|
},
|
|
setConfig: func(cfg *config.Config) {
|
|
w.SetConfig(cfg)
|
|
},
|
|
snapshotAuths: func() []*coreauth.Auth { return w.SnapshotCoreAuths() },
|
|
setUpdateQueue: func(queue chan<- watcher.AuthUpdate) {
|
|
w.SetAuthUpdateQueue(queue)
|
|
},
|
|
dispatchRuntimeUpdate: func(update watcher.AuthUpdate) bool {
|
|
return w.DispatchRuntimeAuthUpdate(update)
|
|
},
|
|
notifyTokenRefreshed: func(tokenID, accessToken, refreshToken, expiresAt string) {
|
|
w.NotifyTokenRefreshed(tokenID, accessToken, refreshToken, expiresAt)
|
|
},
|
|
}, nil
|
|
}
|