frontend: add resolution route
This commit is contained in:
parent
7367e7cc5d
commit
10bd687ecc
2 changed files with 38 additions and 0 deletions
34
frontend/resolution.go
Normal file
34
frontend/resolution.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in a new issue