diff --git a/CHANGELOG.md b/CHANGELOG.md index 843eab0..f880d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# Changelog for 1.1.1 + +The following sections list the changes for 1.1.1. + +## Summary + + * Fix #8: Some mods are missing a download URL + +## Details + + * Bugfix #8: Some mods are missing a download URL + + We found the cases where the provided download URL from the curseforge API were missing, to work + around this we are constructing the URL as a fallback now. This is identicated by the fallback + flag within the logs now. + + https://github.com/webhippie/cursecli/issues/8 + + # Changelog for 1.1.0 The following sections list the changes for 1.1.0. diff --git a/changelog/1.1.1_2022-05-22/download-urls.md b/changelog/1.1.1_2022-05-22/download-urls.md new file mode 100644 index 0000000..3562df5 --- /dev/null +++ b/changelog/1.1.1_2022-05-22/download-urls.md @@ -0,0 +1,7 @@ +Bugfix: Some mods are missing a download URL + +We found the cases where the provided download URL from the curseforge API were +missing, to work around this we are constructing the URL as a fallback now. This +is identicated by the fallback flag within the logs now. + +https://github.com/webhippie/cursecli/issues/8 diff --git a/pkg/forge/forge.go b/pkg/forge/forge.go index 64ebfd3..b7da191 100644 --- a/pkg/forge/forge.go +++ b/pkg/forge/forge.go @@ -83,12 +83,6 @@ func (f *Forge) DownloadManifest() error { download := File{} if err := json.Unmarshal(body, &download); err != nil { - fmt.Printf( - downloadURL, - file.ProjectID, - file.FileID, - ) - log.Error(). Err(err). Int("project", file.ProjectID). @@ -107,6 +101,7 @@ func (f *Forge) DownloadManifest() error { Int("project", file.ProjectID). Int("file", file.FileID). Str("name", download.Name). + Bool("fallback", download.Fallback). Msg("Failed to download mod") return err @@ -116,6 +111,7 @@ func (f *Forge) DownloadManifest() error { Int("project", file.ProjectID). Int("file", file.FileID). Str("name", download.Name). + Bool("fallback", download.Fallback). Msg("Successfully downloaded mod") } diff --git a/pkg/forge/types.go b/pkg/forge/types.go index e5e4fd4..c5cfa7d 100644 --- a/pkg/forge/types.go +++ b/pkg/forge/types.go @@ -2,6 +2,8 @@ package forge import ( "encoding/json" + "fmt" + "strconv" ) // HashAlgo defines the available hash algorithms. @@ -33,11 +35,12 @@ var HashAlgoToID = map[string]HashAlgo{ // File represents a single file from the forgesvc API. type File struct { - ID int `json:"id"` - Name string `json:"fileName"` - Size int `json:"fileLength"` - URL string `json:"downloadUrl"` - Hashes []Hash `json:"hashes"` + ID int `json:"id"` + Name string `json:"fileName"` + Size int `json:"fileLength"` + URL string `json:"downloadUrl"` + Fallback bool `json:"-"` + Hashes []Hash `json:"hashes"` } // UnmarshalJSON implements the JSON unmarshaling. @@ -50,6 +53,20 @@ func (f *File) UnmarshalJSON(b []byte) error { } *f = File(v) + + if f.URL == "" { + identifier := strconv.Itoa(f.ID) + + f.URL = fmt.Sprintf( + "https://edge.forgecdn.net/files/%s/4%s/%s", + identifier[0:4], + identifier[5:len(identifier)-1], + f.Name, + ) + + f.Fallback = true + } + return nil }