优化 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 <noreply@anthropic.com> * feat: 添加 cookies.json 到 .gitignore - 避免将包含敏感登录信息的 cookies 文件提交到版本控制 - 保护用户隐私和安全 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -37,3 +37,6 @@ xiaohongshu-mcp
|
|||||||
|
|
||||||
# Test scripts
|
# Test scripts
|
||||||
test_*.sh
|
test_*.sh
|
||||||
|
|
||||||
|
# Cookies files (contain sensitive login information)
|
||||||
|
cookies.json
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ func NewLoadCookie(path string) Cookier {
|
|||||||
panic("path is required")
|
panic("path is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0644); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &localCookie{
|
return &localCookie{
|
||||||
path: path,
|
path: path,
|
||||||
}
|
}
|
||||||
@@ -47,8 +43,19 @@ func (c *localCookie) SaveCookies(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCookiesFilePath 获取 cookies 文件路径。
|
// GetCookiesFilePath 获取 cookies 文件路径。
|
||||||
|
// 为了向后兼容,如果旧路径 /tmp/cookies.json 存在,则继续使用;
|
||||||
|
// 否则使用当前目录下的 cookies.json
|
||||||
func GetCookiesFilePath() string {
|
func GetCookiesFilePath() string {
|
||||||
|
// 旧路径:/tmp/cookies.json
|
||||||
tmpDir := os.TempDir()
|
tmpDir := os.TempDir()
|
||||||
filePath := filepath.Join(tmpDir, "cookies.json")
|
oldPath := filepath.Join(tmpDir, "cookies.json")
|
||||||
return filePath
|
|
||||||
|
// 检查旧路径文件是否存在
|
||||||
|
if _, err := os.Stat(oldPath); err == nil {
|
||||||
|
// 文件存在,使用旧路径(向后兼容)
|
||||||
|
return oldPath
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件不存在,使用新路径(当前目录)
|
||||||
|
return "cookies.json"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user