fix(client): Add reason to unregistration to skip persistence

This commit is contained in:
hkfires
2025-09-18 20:58:43 +08:00
parent 8f0a345e2a
commit d9f8129a32
5 changed files with 70 additions and 15 deletions

View File

@@ -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)
}