Skip to content

Commit 84f6a85

Browse files
xpzouyingclaude
andauthored
优化 cookies 路径管理策略 (#127)
* feat: 优化 cookies 路径管理策略 1. 实现向后兼容的路径迁移逻辑: - 优先使用旧路径 /tmp/cookies.json(如果存在) - 否则使用当前目录 ./cookies.json 2. 移除不必要的目录创建逻辑 - 删除 NewLoadCookie 中的 MkdirAll 调用 - 避免相对路径可能导致的权限问题 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * feat: 添加 cookies.json 到 .gitignore - 避免将包含敏感登录信息的 cookies 文件提交到版本控制 - 保护用户隐私和安全 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent e1d43d2 commit 84f6a85

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ xiaohongshu-mcp
3737

3838
# Test scripts
3939
test_*.sh
40+
41+
# Cookies files (contain sensitive login information)
42+
cookies.json

cookies/cookies.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ func NewLoadCookie(path string) Cookier {
2121
panic("path is required")
2222
}
2323

24-
if err := os.MkdirAll(filepath.Dir(path), 0644); err != nil {
25-
panic(err)
26-
}
27-
2824
return &localCookie{
2925
path: path,
3026
}
@@ -47,8 +43,19 @@ func (c *localCookie) SaveCookies(data []byte) error {
4743
}
4844

4945
// GetCookiesFilePath 获取 cookies 文件路径。
46+
// 为了向后兼容,如果旧路径 /tmp/cookies.json 存在,则继续使用;
47+
// 否则使用当前目录下的 cookies.json
5048
func GetCookiesFilePath() string {
49+
// 旧路径:/tmp/cookies.json
5150
tmpDir := os.TempDir()
52-
filePath := filepath.Join(tmpDir, "cookies.json")
53-
return filePath
51+
oldPath := filepath.Join(tmpDir, "cookies.json")
52+
53+
// 检查旧路径文件是否存在
54+
if _, err := os.Stat(oldPath); err == nil {
55+
// 文件存在,使用旧路径(向后兼容)
56+
return oldPath
57+
}
58+
59+
// 文件不存在,使用新路径(当前目录)
60+
return "cookies.json"
5461
}

0 commit comments

Comments
 (0)