1
0
forked from MTSR/mapserver

/api/media/{filename} endpoint

This commit is contained in:
NatureFreshMilk 2019-06-14 11:21:07 +02:00
parent 644107f612
commit fbf2c1c190
5 changed files with 22 additions and 4 deletions

View File

@ -28,5 +28,7 @@ type App struct {
Mapblockrenderer *mapblockrenderer.MapBlockRenderer
Tilerenderer *tilerenderer.TileRenderer
MediaRepo map[string][]byte
WebEventbus *eventbus.Eventbus
}

View File

@ -9,6 +9,7 @@ import (
"mapserver/mapblockrenderer"
postgresobjdb "mapserver/mapobjectdb/postgres"
sqliteobjdb "mapserver/mapobjectdb/sqlite"
"mapserver/media"
"mapserver/params"
"mapserver/settings"
"mapserver/tiledb"
@ -143,5 +144,12 @@ func Setup(p params.ParamsType, cfg *Config) *App {
a.Config.Layers,
)
//create media repo
repo := make(map[string][]byte)
media.ScanDir(repo, ".", []string{"mapserver.tiles", ".git"})
logrus.WithFields(logrus.Fields{"count": len(repo)}).Info("Created media repository")
a.MediaRepo = repo
return &a
}

View File

@ -145,7 +145,6 @@ func TestMapObjectsQueryWithAttribute(t *testing.T) {
}
}
func TestMapObjectsQueryWithAttributeIgnoreCase(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMapObjects.*.sqlite")
if err != nil {

View File

@ -21,6 +21,15 @@ func (h *MediaHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
filename := parts[0]
resp.WriteHeader(500)
content := h.ctx.MediaRepo[filename]
if content != nil {
resp.Write(content)
resp.Header().Add("content-type", "image/png")
} else {
resp.WriteHeader(404)
resp.Write([]byte(filename))
}
}

View File

@ -30,7 +30,7 @@ func Serve(ctx *app.App) {
tiles.Init()
mux.Handle("/api/tile/", tiles)
mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
mux.Handle("/api/media", &MediaHandler{ctx: ctx})
mux.Handle("/api/media/", &MediaHandler{ctx: ctx})
mux.Handle("/api/minetest", &Minetest{ctx: ctx})
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})