feat: render local artist images with no foreign key

This commit is contained in:
sentriz
2022-02-09 17:55:19 +00:00
committed by Senan Kelly
parent a0b9934d08
commit a74b5a261c
10 changed files with 160 additions and 49 deletions

View File

@@ -55,6 +55,21 @@ func (c *Controller) Path(rel string) string {
return path.Join(c.ProxyPrefix, rel)
}
func (c *Controller) BaseURL(r *http.Request) string {
scheme := firstExisting(
"http", // fallback
r.Header.Get("X-Forwarded-Proto"),
r.Header.Get("X-Forwarded-Scheme"),
r.URL.Scheme,
)
host := firstExisting(
"localhost:4747", // fallback
r.Header.Get("X-Forwarded-Host"),
r.Host,
)
return fmt.Sprintf("%s://%s", scheme, host)
}
func (c *Controller) WithLogging(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// this is (should be) the first middleware. pass right though it
@@ -87,3 +102,12 @@ func (c *Controller) WithCORS(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
})
}
func firstExisting(or string, strings ...string) string {
for _, s := range strings {
if s != "" {
return s
}
}
return or
}