admin: able to download files through /files/ route

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

View file

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

View file

@ -44,7 +44,7 @@
<form ng-submit="saveFile()" class="list-group-item bg-light text-dark" ng-repeat="file in files"> <form ng-submit="saveFile()" class="list-group-item bg-light text-dark" ng-repeat="file in files">
<div class="row form-group"> <div class="row form-group">
<input type="text" ng-model="file.name" class="col form-control form-control-sm" placeholder="Nom de fichier"> <input type="text" ng-model="file.name" class="col form-control form-control-sm" placeholder="Nom de fichier">
<a href="{{file.path}}" class="btn btn-sm btn-secondary col-auto"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></a> <a href="/files{{file.path}}" class="btn btn-sm btn-secondary col-auto"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></a>
<button type="submit" class="btn btn-sm btn-success col-auto"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button><br> <button type="submit" class="btn btn-sm btn-success col-auto"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button><br>
<button type="button" ng-click="deleteFile()" class="btn btn-sm btn-danger col-auto"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button> <button type="button" ng-click="deleteFile()" class="btn btn-sm btn-danger col-auto"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
</div> </div>