admin: able to download files through /files/ route

This commit is contained in:
nemunaire 2018-12-08 21:00:00 +01:00
commit 69979ced1d
2 changed files with 8 additions and 2 deletions

View file

@ -3,8 +3,10 @@ package main
import (
"net/http"
"path"
"strings"
"srs.epita.fr/fic-server/admin/api"
"srs.epita.fr/fic-server/libfic"
"github.com/julienschmidt/httprouter"
)
@ -22,7 +24,7 @@ func init() {
api.Router().GET("/events/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
})
api.Router().GET("/files/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
api.Router().GET("/files", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
})
api.Router().GET("/public/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
@ -57,6 +59,10 @@ func init() {
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
})
api.Router().GET("/files/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
http.ServeFile(w, r, path.Join(fic.FilesDir, strings.TrimPrefix(r.URL.Path, "/files")))
})
api.Router().GET("/check_import.html", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
http.ServeFile(w, r, path.Join(StaticDir, "check_import.html"))
})