Merge branch 'master' into es6-modules
This commit is contained in:
commit
c4f52ee923
@ -146,8 +146,12 @@ func Setup(p params.ParamsType, cfg *Config) *App {
|
||||
|
||||
//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")
|
||||
mediasize, _ := media.ScanDir(repo, ".", []string{"mapserver.tiles", ".git"})
|
||||
fields := logrus.Fields{
|
||||
"count": len(repo),
|
||||
"bytes": mediasize,
|
||||
}
|
||||
logrus.WithFields(fields).Info("Created media repository")
|
||||
|
||||
a.MediaRepo = repo
|
||||
|
||||
|
@ -6,8 +6,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ScanDir(repo map[string][]byte, path string, ignore []string) error {
|
||||
func ScanDir(repo map[string][]byte, path string, ignore []string) (int, error) {
|
||||
_, files := scan_recursive(path, ignore)
|
||||
size := 0
|
||||
|
||||
for _, filename := range files {
|
||||
if strings.HasSuffix(filename, ".png") {
|
||||
@ -15,15 +16,17 @@ func ScanDir(repo map[string][]byte, path string, ignore []string) error {
|
||||
file, err := os.Open(filename)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadAll(file)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
size += len(content)
|
||||
|
||||
simplefilename := filename
|
||||
lastSlashIndex := strings.LastIndex(filename, "/")
|
||||
|
||||
@ -36,5 +39,5 @@ func ScanDir(repo map[string][]byte, path string, ignore []string) error {
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
return size, nil
|
||||
}
|
||||
|
15
web/media.go
15
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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user