From aae93755cd8e9f87d3b988b155a027659fdb2df4 Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 30 Jan 2024 00:12:50 -0500 Subject: [PATCH] [bugfix] Fix JSON mapping using full urls - Fixes JSON mapping to use only paths, preserving redirector functionality --- map.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/map.go b/map.go index 4064018..b7ff891 100644 --- a/map.go +++ b/map.go @@ -4,7 +4,9 @@ import ( "encoding/csv" "encoding/json" "errors" + log "github.com/sirupsen/logrus" "io" + "net/url" "os" "path" "strings" @@ -97,6 +99,19 @@ func loadMapJSON(f io.Reader) (map[string]string, error) { } for _, file := range data.Assets { + // Because download mapping a full URL, redirecting, and finding a server again is redundant, + // we parse the URL and only return the path here. Previously, it would use https://dl.armbian.com/PATH + // which is not supported, as the redirector will always prepend a server + u, err := url.Parse(file.FileURL) + + if err != nil { + log.WithFields(log.Fields{ + "error": err, + "uri": file.FileURL, + }).Warning("Error parsing redirect url or path") + continue + } + var sb strings.Builder sb.WriteString(file.BoardSlug) @@ -116,7 +131,7 @@ func loadMapJSON(f io.Reader) (map[string]string, error) { } if file.Extension == "img.xz" { - m[sb.String()] = file.FileURL + m[sb.String()] = u.Path } sb.WriteString(".") @@ -131,8 +146,7 @@ func loadMapJSON(f io.Reader) (map[string]string, error) { sb.WriteString(file.Extension) } - builtURI := sb.String() - m[builtURI] = file.FileURL + m[sb.String()] = u.Path } return m, nil