From 54804b9c3d4039c42d0cb4054669e30a043e576d Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Fri, 14 Jun 2019 13:28:10 +0200 Subject: [PATCH] fallback media url --- web/media.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/media.go b/web/media.go index 849aaac..a19785d 100644 --- a/web/media.go +++ b/web/media.go @@ -2,6 +2,7 @@ package web import ( "mapserver/app" + "mapserver/vfs" "net/http" "strings" ) @@ -20,16 +21,20 @@ func (h *MediaHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { } filename := parts[0] + fallback, hasfallback := req.URL.Query()["fallback"] content := h.ctx.MediaRepo[filename] + if content == nil && hasfallback && len(fallback) > 0 { + content, _ = vfs.FSByte(h.ctx.Config.Webdev, "/pics/"+fallback[0]) + } + if content != nil { resp.Write(content) resp.Header().Add("content-type", "image/png") - - } else { - resp.WriteHeader(404) - resp.Write([]byte(filename)) - + return } + + resp.WriteHeader(404) + resp.Write([]byte(filename)) }