按需使用git代理
This commit is contained in:
Binary file not shown.
@@ -372,6 +372,26 @@ func getNpmPrefix() (string, error) {
|
|||||||
return cachedNpmPrefix, nil
|
return cachedNpmPrefix, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkIsCNLocation Checks if the current IP location is in China
|
||||||
|
func checkIsCNLocation() bool {
|
||||||
|
client := &http.Client{Timeout: 5 * time.Second}
|
||||||
|
resp, err := client.Get("https://www.cloudflare.com/cdn-cgi/trace")
|
||||||
|
if err != nil {
|
||||||
|
// If the request fails, assume CN to be safe and ensure accessibility
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
if line == "loc=CN" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func ResetPathCache() {
|
func ResetPathCache() {
|
||||||
cachedNpmPrefix = ""
|
cachedNpmPrefix = ""
|
||||||
cachedNodePath = ""
|
cachedNodePath = ""
|
||||||
@@ -395,6 +415,10 @@ func ConfigureNpmMirror() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ConfigureGitProxy() error {
|
func ConfigureGitProxy() error {
|
||||||
|
if !checkIsCNLocation() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var lastErr error
|
var lastErr error
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
ResetPathCache()
|
ResetPathCache()
|
||||||
@@ -416,6 +440,21 @@ func ConfigureGitProxy() error {
|
|||||||
return lastErr
|
return lastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveGitProxy 取消 Git 代理
|
||||||
|
func RemoveGitProxy() error {
|
||||||
|
gitPath, err := GetGitPath()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy := gitProxy()
|
||||||
|
key := fmt.Sprintf("url.%shttps://github.com/.insteadOf", proxy)
|
||||||
|
|
||||||
|
// Unset the proxy configuration
|
||||||
|
cmd := exec.Command(gitPath, "config", "--global", "--unset", key)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
// downloadFile 下载文件
|
// downloadFile 下载文件
|
||||||
func downloadFile(url, dest, expectedSHA256 string, onProgress ProgressCallback) error {
|
func downloadFile(url, dest, expectedSHA256 string, onProgress ProgressCallback) error {
|
||||||
if ok, err := verifyFileSHA256(dest, expectedSHA256); err == nil && ok {
|
if ok, err := verifyFileSHA256(dest, expectedSHA256); err == nil && ok {
|
||||||
@@ -1140,6 +1179,8 @@ func UninstallOpenclaw() error {
|
|||||||
cmd.Run()
|
cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RemoveGitProxy()
|
||||||
|
|
||||||
userHome, err := os.UserHomeDir()
|
userHome, err := os.UserHomeDir()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
configDir := filepath.Join(userHome, ".openclaw")
|
configDir := filepath.Join(userHome, ".openclaw")
|
||||||
|
|||||||
Reference in New Issue
Block a user