Skip to content

Commit

Permalink
fix: fix download DeveloperDiskImage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Nov 23, 2023
1 parent 5158762 commit 028d354
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var App AppConfiguration
type AppConfiguration struct {
LockdownDir string `koanf:"lockdown_dir" default:"/var/lib/lockdown"`
DeveloperDiskImage struct {
ImageSource string `koanf:"image_source" json:"image_source" default:"https://ghproxy.com/https://github.com/haikieu/xcode-developer-disk-image-all-platforms/raw/master/DiskImages/AppleTVOS.platform/DeviceSupport/{0}.zip"`
ImageSource string `koanf:"image_source" json:"image_source" default:"https://github.com/haikieu/xcode-developer-disk-image-all-platforms/raw/master/DiskImages/AppleTVOS.platform/DeviceSupport/{0}.zip"`
CNProxy string `koanf:"cn_proxy" json:"cn_proxy" default:"https://mirror.ghproxy.com"`
} `koanf:"developer_disk_image" json:"developer_disk_image"`
}

Expand Down
20 changes: 15 additions & 5 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,22 @@ func downloadDeveloperDiskImageByVersion(url string, version string) error {
_ = os.RemoveAll(tmpUnzipPath)

// download current version DeveloperDiskImage
resp, err := http.NewClient().R().SetOutput(tmpPath).Get(url)
if err != nil {
return err
hasDownloaded := false
if config.App.DeveloperDiskImage.CNProxy != "" {
// download by proxy
cnProxyUrl := strings.TrimSuffix(config.App.DeveloperDiskImage.CNProxy, "/") + "/" + url
if resp, err := http.NewClient().R().SetOutput(tmpPath).Get(cnProxyUrl); err == nil && resp.IsSuccess() {
hasDownloaded = true
}
}
if !resp.IsSuccess() {
return fmt.Errorf("Developer disk image download failed. url: %s status: %d", url, resp.StatusCode())
if !hasDownloaded {
resp, err := http.NewClient().R().SetOutput(tmpPath).Get(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("developer disk image download failed. url: %s status: %d", url, resp.StatusCode())
}
}

// unzip
Expand Down

0 comments on commit 028d354

Please sign in to comment.