32 lines
646 B
Go
32 lines
646 B
Go
package view
|
|
|
|
import (
|
|
"local/dndex/config"
|
|
"local/dndex/storage"
|
|
"local/simpleserve/simpleserve"
|
|
"net/http"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
func files(_ storage.Graph, w http.ResponseWriter, r *http.Request) error {
|
|
r.URL.Path = strings.TrimPrefix(r.URL.Path, config.New().FilePrefix)
|
|
if len(r.URL.Path) < 2 {
|
|
http.NotFound(w, r)
|
|
return nil
|
|
}
|
|
simpleserve.SetContentTypeIfMedia(w, r)
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
return filesGet(w, r)
|
|
default:
|
|
http.NotFound(w, r)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func filesGet(w http.ResponseWriter, r *http.Request) error {
|
|
http.ServeFile(w, r, path.Join(config.New().FileRoot, r.URL.Path))
|
|
return nil
|
|
}
|