增加github加速
This commit is contained in:
Binary file not shown.
@@ -36,6 +36,20 @@ const (
|
|||||||
downloadConcurrentParts = 4
|
downloadConcurrentParts = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const gitProxyEnv = "GIT_PROXY"
|
||||||
|
const gitProxyDefault = "https://g.blfrp.cn/"
|
||||||
|
|
||||||
|
func gitProxy() string {
|
||||||
|
proxy := strings.TrimSpace(os.Getenv(gitProxyEnv))
|
||||||
|
if proxy == "" {
|
||||||
|
proxy = gitProxyDefault
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(proxy, "/") {
|
||||||
|
proxy += "/"
|
||||||
|
}
|
||||||
|
return proxy
|
||||||
|
}
|
||||||
|
|
||||||
// SHA256 来源 https://nodejs.org/dist/v24.13.0/SHASUMS256.txt.asc
|
// SHA256 来源 https://nodejs.org/dist/v24.13.0/SHASUMS256.txt.asc
|
||||||
const nodeMsiSHA256 = "1a5f0cd914386f3be2fbaf03ad9fff808a588ce50d2e155f338fad5530575f18"
|
const nodeMsiSHA256 = "1a5f0cd914386f3be2fbaf03ad9fff808a588ce50d2e155f338fad5530575f18"
|
||||||
|
|
||||||
@@ -365,6 +379,20 @@ func ConfigureNpmMirror() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConfigureGitProxy() error {
|
||||||
|
gitPath, err := GetGitPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
proxy := gitProxy()
|
||||||
|
key := fmt.Sprintf("url.%shttps://github.com/.insteadOf", proxy)
|
||||||
|
cmd := exec.Command(gitPath, "config", "--global", key, "https://github.com/")
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return fmt.Errorf("设置 git 代理失败: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// downloadFile 下载文件
|
// downloadFile 下载文件
|
||||||
func downloadFile(url, dest, expectedSHA256 string) error {
|
func downloadFile(url, dest, expectedSHA256 string) error {
|
||||||
if ok, err := verifyFileSHA256(dest, expectedSHA256); err == nil && ok {
|
if ok, err := verifyFileSHA256(dest, expectedSHA256); err == nil && ok {
|
||||||
@@ -747,7 +775,7 @@ func InstallGit() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gitUrl := "https://gh.kejilion.pro/github.com/git-for-windows/git/releases/download/v2.52.0.windows.1/Git-2.52.0-64-bit.exe"
|
gitUrl := fmt.Sprintf("%sgithub.com/git-for-windows/git/releases/download/v2.52.0.windows.1/Git-2.52.0-64-bit.exe", gitProxy())
|
||||||
tempDir := os.TempDir()
|
tempDir := os.TempDir()
|
||||||
exePath := filepath.Join(tempDir, "Git-2.52.0-64-bit.exe")
|
exePath := filepath.Join(tempDir, "Git-2.52.0-64-bit.exe")
|
||||||
|
|
||||||
|
|||||||
@@ -709,6 +709,11 @@ func runInstallFlowCmd() tea.Msg {
|
|||||||
return actionResultMsg{err: fmt.Errorf("git 安装失败: %v", err)}
|
return actionResultMsg{err: fmt.Errorf("git 安装失败: %v", err)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = sys.ConfigureGitProxy()
|
||||||
|
if err != nil {
|
||||||
|
return actionResultMsg{err: fmt.Errorf("git 代理配置失败: %v", err)}
|
||||||
|
}
|
||||||
|
|
||||||
err = sys.ConfigureNpmMirror()
|
err = sys.ConfigureNpmMirror()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return actionResultMsg{err: fmt.Errorf("npm 配置失败: %v", err)}
|
return actionResultMsg{err: fmt.Errorf("npm 配置失败: %v", err)}
|
||||||
|
|||||||
Reference in New Issue
Block a user