mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 04:10:51 +08:00
fix(client): Add reason to unregistration to skip persistence
This commit is contained in:
@@ -61,13 +61,28 @@ type GeminiWebClient struct {
|
||||
modelsRegistered bool
|
||||
}
|
||||
|
||||
func (c *GeminiWebClient) UnregisterClient() {
|
||||
func (c *GeminiWebClient) UnregisterClient() { c.unregisterClient(false) }
|
||||
|
||||
// UnregisterClientWithReason allows the watcher to avoid recreating deleted auth files.
|
||||
func (c *GeminiWebClient) UnregisterClientWithReason(reason interfaces.UnregisterReason) {
|
||||
skipPersist := reason == interfaces.UnregisterReasonAuthFileRemoved
|
||||
c.unregisterClient(skipPersist)
|
||||
}
|
||||
|
||||
func (c *GeminiWebClient) unregisterClient(skipPersist bool) {
|
||||
if c.cookiePersistCancel != nil {
|
||||
c.cookiePersistCancel()
|
||||
c.cookiePersistCancel = nil
|
||||
}
|
||||
// Flush cookie snapshot to main token file and remove snapshot
|
||||
c.flushCookieSnapshotToMain()
|
||||
if skipPersist {
|
||||
if c.snapshotManager != nil && c.tokenFilePath != "" {
|
||||
log.Debugf("skipping Gemini Web snapshot flush because auth file is missing: %s", filepath.Base(c.tokenFilePath))
|
||||
util.RemoveCookieSnapshots(c.tokenFilePath)
|
||||
}
|
||||
} else {
|
||||
// Flush cookie snapshot to main token file and remove snapshot
|
||||
c.flushCookieSnapshotToMain()
|
||||
}
|
||||
if c.gwc != nil {
|
||||
c.gwc.Close(0)
|
||||
c.gwc = nil
|
||||
|
||||
@@ -507,10 +507,25 @@ func (c *QwenClient) SetUnavailable() {
|
||||
}
|
||||
|
||||
// UnregisterClient flushes cookie snapshot back into the main token file.
|
||||
func (c *QwenClient) UnregisterClient() {
|
||||
func (c *QwenClient) UnregisterClient() { c.unregisterClient(false) }
|
||||
|
||||
// UnregisterClientWithReason allows the watcher to skip persistence when the auth file is removed.
|
||||
func (c *QwenClient) UnregisterClientWithReason(reason interfaces.UnregisterReason) {
|
||||
skipPersist := reason == interfaces.UnregisterReasonAuthFileRemoved
|
||||
c.unregisterClient(skipPersist)
|
||||
}
|
||||
|
||||
func (c *QwenClient) unregisterClient(skipPersist bool) {
|
||||
if c.snapshotManager == nil {
|
||||
return
|
||||
}
|
||||
if skipPersist {
|
||||
if c.tokenFilePath != "" {
|
||||
log.Debugf("skipping Qwen snapshot flush because auth file is missing: %s", filepath.Base(c.tokenFilePath))
|
||||
util.RemoveCookieSnapshots(c.tokenFilePath)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := c.snapshotManager.Flush(); err != nil {
|
||||
log.Errorf("Failed to flush Qwen cookie snapshot to main for %s: %v", filepath.Base(c.tokenFilePath), err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user