frontend: add resolution route

This commit is contained in:
nemunaire 2016-11-19 16:43:57 +01:00
parent 0c6e3e7771
commit 3c84c6194d
2 changed files with 38 additions and 0 deletions

View File

@ -33,6 +33,7 @@ func main() {
var duration = flag.Duration("duration", 180*time.Minute, "Challenge duration")
var denyChName = flag.Bool("denyChName", false, "Deny team to change their name")
var allowRegistration = flag.Bool("allowRegistration", false, "New team can add itself")
var resolutionRoute = flag.Bool("resolutionRoute", false, "Enable resolution route")
flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files")
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
flag.Parse()
@ -69,6 +70,9 @@ func main() {
log.Println("Registering handlers...")
http.Handle(fmt.Sprintf("%s/time.json", *prefix), http.StripPrefix(*prefix, TimeHandler{startTime, *duration}))
if *resolutionRoute {
http.Handle(fmt.Sprintf("%s/resolution/", *prefix), http.StripPrefix(fmt.Sprintf("%s/resolution/", *prefix), ResolutionHandler{}))
}
http.Handle(fmt.Sprintf("%s/", *prefix), http.StripPrefix(*prefix, SubmissionHandler{end, *denyChName, *allowRegistration}))
log.Println(fmt.Sprintf("Ready, listening on %s", *bind))

34
frontend/resolution.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"log"
"net/http"
"path"
"text/template"
)
type ResolutionHandler struct {}
const resolutiontpl = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Challenge Forensic - Résolution</title>
</head>
<body style="margin: 0">
<video src="{{.}}" controls width="100%" height="100%"></video>
</body>
</html>
`
func (s ResolutionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Printf("Handling %s request from %s: /resolution%s [%s]\n", r.Method, r.RemoteAddr, r.URL.Path, r.UserAgent())
w.Header().Set("Content-Type", "text/html")
if resolutionTmpl, err := template.New("resolution").Parse(resolutiontpl); err != nil {
log.Println("Cannot create template: ", err)
} else if err := resolutionTmpl.Execute(w, path.Join("/vids/", r.URL.Path)); err != nil {
log.Println("An error occurs during template execution: ", err)
}
}