aboutsummaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
Diffstat (limited to 'controller')
-rw-r--r--controller/controller.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/controller/controller.go b/controller/controller.go
index 252be73..3e029f0 100644
--- a/controller/controller.go
+++ b/controller/controller.go
@@ -1,24 +1,16 @@
package controller
import (
- "context"
"net/http"
"git.sr.ht/~gabrielgio/midr/db"
- "git.sr.ht/~gabrielgio/midr/yt"
- work "git.sr.ht/~sircmpwn/dowork"
+ "git.sr.ht/~gabrielgio/midr/worker"
"github.com/gin-gonic/gin"
)
type Env struct {
Entries db.EntryModel
-}
-
-func spawnWorker(link string, output string) {
- work.Submit(func(ctx context.Context) error {
- yt.RunYtDlpProcess(link, output)
- return nil
- })
+ Worker worker.Worker
}
func (e Env) GetEntries(c *gin.Context) {
@@ -28,8 +20,12 @@ func (e Env) GetEntries(c *gin.Context) {
func (e *Env) GetEntry(c *gin.Context) {
id := c.Param("id")
- entry := e.Entries.Find(id)
- c.HTML(http.StatusOK, "entry", entry)
+ if id != "" {
+ entry := e.Entries.Find(id)
+ c.HTML(http.StatusOK, "entry", entry)
+ } else {
+ c.HTML(http.StatusOK, "entry", db.Entry{})
+ }
}
func (e *Env) UpdateEntry(c *gin.Context) {
@@ -43,7 +39,7 @@ func (e *Env) CreateEntry(c *gin.Context) {
var entry db.Entry
c.ShouldBind(&entry)
e.Entries.Create(entry)
- spawnWorker(entry.Link, entry.OutputFolder)
+ e.Worker.SpawnWorker(entry.ID, entry.Link, entry.OutputFolder)
c.Redirect(http.StatusFound, "/")
}