Skip to content

Commit

Permalink
Adapted the gog-api sdk to a change in gog's api: Retrieving a downlo…
Browse files Browse the repository at this point in the history
…ad's filename when there is no file metadata is now done by looking at the url's path and not the query parameters
  • Loading branch information
Magnitus- committed Oct 11, 2024
1 parent 82d71e8 commit 9c5906f
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions sdk/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,14 @@ func (s *Sdk) retrieveDownloadMetadata(metadataUrl string, fn string, retriesLef
}, nil
}

func getFilenameFromQueryParams(location string, fn string) (string, error) {
func getFilenameFromUrlPath(location string, fn string) (string, error) {
locUrl, err := url.Parse(location)
if err != nil {
msg := fmt.Sprintf("%s -> Error parsing location header url: %s", fn, err.Error())
return "", errors.New(msg)
}

queryParams := locUrl.Query()
pathParam, ok := queryParams["path"]
if !ok {
msg := fmt.Sprintf("%s -> Error location header url does not have the expected path query parameter", fn)
return "", errors.New(msg)
}

return path.Base(pathParam[0]), nil
return path.Base(locUrl.Path), nil
}

func convertDownloadUrlToMetadataUrl(downloadUrl string) (string, error) {
Expand Down Expand Up @@ -151,7 +144,7 @@ func (s *Sdk) getDownloadFileInfo(downloadPath string) (string, string, int64, e

if !metadata.Found {
var filename string
filename, err = getFilenameFromQueryParams(filenameLoc, fn)
filename, err = getFilenameFromUrlPath(filenameLoc, fn)
if err != nil {
return "", "", int64(-1), err, false, true
}
Expand Down Expand Up @@ -246,7 +239,7 @@ func (s *Sdk) GetDownloadFilename(downloadPath string) (string, error) {
return "", err
}

name, err := getFilenameFromQueryParams(reply.RedirectUrl, fn)
name, err := getFilenameFromUrlPath(reply.RedirectUrl, fn)
return name, err
}

Expand Down

0 comments on commit 9c5906f

Please sign in to comment.