Strip leading slashes from requests to download map
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
Tyler 2022-04-02 01:21:42 -04:00
parent a571832239
commit 2f43f2d934
2 changed files with 3 additions and 8 deletions

View File

@ -112,13 +112,7 @@ func redirectHandler(w http.ResponseWriter, r *http.Request) {
redirectPath := path.Join(server.Path, r.URL.Path)
if dlMap != nil {
p := r.URL.Path
if p[0] != '/' {
p = "/" + p
}
if newPath, exists := dlMap[p]; exists {
if newPath, exists := dlMap[strings.TrimLeft(r.URL.Path, "/")]; exists {
downloadsMapped.Inc()
redirectPath = path.Join(server.Path, newPath)
}

3
map.go
View File

@ -4,6 +4,7 @@ import (
"encoding/csv"
"io"
"os"
"strings"
)
func loadMap(file string) (map[string]string, error) {
@ -32,7 +33,7 @@ func loadMap(file string) (map[string]string, error) {
return nil, err
}
m[row[0]] = row[1]
m[strings.TrimLeft(row[0], "/")] = strings.TrimLeft(row[1], "/")
}
return m, nil