Initial /video/[id] endpoint
This commit is contained in:
14
handlers.go
14
handlers.go
@@ -255,6 +255,20 @@ func videosHandler(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "videos.html", map[string]interface{}{"videos": videos})
|
||||
}
|
||||
|
||||
func videoHandler(c echo.Context) error {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
var video Video
|
||||
if err := db.First(&video, id).Error; err != nil {
|
||||
return c.Redirect(http.StatusSeeOther, "/videos")
|
||||
}
|
||||
|
||||
return c.Render(http.StatusOK, "video.html",
|
||||
map[string]interface{}{
|
||||
"video": video,
|
||||
"downloadDir": getDownloadDir(),
|
||||
})
|
||||
}
|
||||
|
||||
func videoCancelHandler(c echo.Context) error {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
var video Video
|
||||
|
2
main.go
2
main.go
@@ -90,6 +90,7 @@ func main() {
|
||||
e.GET("/download", downloadHandler, authMiddleware)
|
||||
e.POST("/download", downloadPostHandler, authMiddleware)
|
||||
e.GET("/videos", videosHandler, authMiddleware)
|
||||
e.GET("/video/:id", videoHandler, authMiddleware)
|
||||
e.POST("/video/:id/cancel", videoCancelHandler, authMiddleware)
|
||||
e.POST("/video/:id/restart", videoRestartHandler, authMiddleware)
|
||||
e.POST("/video/:id/delete", videoDeleteHandler, authMiddleware)
|
||||
@@ -97,7 +98,6 @@ func main() {
|
||||
staticGroup := e.Group("/downloads")
|
||||
staticGroup.Use(authMiddleware)
|
||||
staticGroup.Static("/", getDownloadDir())
|
||||
|
||||
// e.Static("/downloads", getDownloadDir())
|
||||
|
||||
store.Options = &sessions.Options{
|
||||
|
21
templates/video.html
Normal file
21
templates/video.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Downloaded Videos</title>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Downloaded Video {{.video.Title}}</h1>
|
||||
|
||||
<video controls width="250">
|
||||
<source src="/{{.downloadDir}}/video/{{.video.VideoFilename}}" type="video/mp4" />
|
||||
|
||||
<!-- <source src="/media/cc0-videos/flower.mp4" type="video/mp4" /> -->
|
||||
</video>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user