Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add fallback download url #9

Merged
merged 1 commit into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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