1
0
forked from MTSR/mapserver

fallback media url

This commit is contained in:
NatureFreshMilk 2019-06-14 13:28:10 +02:00
parent 8bcbd877e8
commit 54804b9c3d

View File

@ -2,6 +2,7 @@ package web
import ( import (
"mapserver/app" "mapserver/app"
"mapserver/vfs"
"net/http" "net/http"
"strings" "strings"
) )
@ -20,16 +21,20 @@ func (h *MediaHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
} }
filename := parts[0] filename := parts[0]
fallback, hasfallback := req.URL.Query()["fallback"]
content := h.ctx.MediaRepo[filename] 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 { if content != nil {
resp.Write(content) resp.Write(content)
resp.Header().Add("content-type", "image/png") resp.Header().Add("content-type", "image/png")
return
} else {
resp.WriteHeader(404)
resp.Write([]byte(filename))
} }
resp.WriteHeader(404)
resp.Write([]byte(filename))
} }