feat: add delete cookies functionality for login reset (#275)

This commit is contained in:
Ctrlz
2025-11-02 19:01:48 +08:00
committed by GitHub
parent 7cf35fc4ae
commit 11a937b84f
6 changed files with 88 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ import (
type Cookier interface {
LoadCookies() ([]byte, error)
SaveCookies(data []byte) error
DeleteCookies() error
}
type localCookie struct {
@@ -42,6 +43,15 @@ func (c *localCookie) SaveCookies(data []byte) error {
return os.WriteFile(c.path, data, 0644)
}
// DeleteCookies 删除 cookies 文件。
func (c *localCookie) DeleteCookies() error {
if _, err := os.Stat(c.path); os.IsNotExist(err) {
// 文件不存在,返回 nil认为已经删除
return nil
}
return os.Remove(c.path)
}
// GetCookiesFilePath 获取 cookies 文件路径。
// 为了向后兼容,如果旧路径 /tmp/cookies.json 存在,则继续使用;
// 否则使用当前目录下的 cookies.json