blob: 35523043805c32a61f14bca152bfb7c7e4c29f05 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package controller
import (
"context"
"net/http"
"git.sr.ht/~gabrielgio/midr/db"
"git.sr.ht/~gabrielgio/midr/yt"
work "git.sr.ht/~sircmpwn/dowork"
"github.com/gin-gonic/gin"
)
func spawnWorker(link string, output string) {
work.Submit(func(ctx context.Context) error {
yt.RunYtDlpProcess(link, output)
return nil
})
}
func GetEntries(c *gin.Context) {
var entries []db.YdlEntry
db.DB.Find(&entries)
c.HTML(http.StatusOK, "index", entries)
}
func GetEntry(c *gin.Context) {
var entry db.YdlEntry
id := c.Param("id")
where := "id = " + id
db.DB.Where(where).FirstOrInit(&entry)
c.HTML(http.StatusOK, "entry", entry)
}
func UpdateEntry(c *gin.Context) {
var entry db.YdlEntry
c.ShouldBind(&entry)
db.DB.Save(&entry)
c.HTML(http.StatusOK, "entry", entry)
}
func CreateEntry(c *gin.Context) {
var entry db.YdlEntry
c.ShouldBind(&entry)
db.DB.Create(&entry)
spawnWorker(entry.Link, entry.Output_folder)
c.Redirect(http.StatusFound, "/")
}
func DeleteEntry(c *gin.Context) {
var entry db.YdlEntry
id := c.Param("id")
db.DB.Delete(&entry, id)
c.HTML(http.StatusOK, "entry", entry)
}
|