Skip to content

Commit

Permalink
Merge pull request #9 from webhippie/fix-download-url
Browse files Browse the repository at this point in the history
fix: add fallback download url
  • Loading branch information
tboerger committed May 21, 2022
2 parents 681a5c0 + 685653b commit cc69b05
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 7 additions & 0 deletions changelog/1.1.1_2022-05-22/download-urls.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 2 additions & 6 deletions pkg/forge/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand All @@ -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")
}

Expand Down
27 changes: 22 additions & 5 deletions pkg/forge/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package forge

import (
"encoding/json"
"fmt"
"strconv"
)

// HashAlgo defines the available hash algorithms.
Expand Down Expand Up @@ -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.
Expand All @@ -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
}

Expand Down

0 comments on commit cc69b05

Please sign in to comment.