/api/media/{filename} endpoint
This commit is contained in:
parent
644107f612
commit
fbf2c1c190
@ -28,5 +28,7 @@ type App struct {
|
||||
Mapblockrenderer *mapblockrenderer.MapBlockRenderer
|
||||
Tilerenderer *tilerenderer.TileRenderer
|
||||
|
||||
MediaRepo map[string][]byte
|
||||
|
||||
WebEventbus *eventbus.Eventbus
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -145,7 +145,6 @@ func TestMapObjectsQueryWithAttribute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestMapObjectsQueryWithAttributeIgnoreCase(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "TestMapObjects.*.sqlite")
|
||||
if err != nil {
|
||||
|
13
web/media.go
13
web/media.go
@ -21,6 +21,15 @@ func (h *MediaHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||
|
||||
filename := parts[0]
|
||||
|
||||
resp.WriteHeader(500)
|
||||
resp.Write([]byte(filename))
|
||||
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))
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user