Improved playlist handling

This commit is contained in:
Carl Pearson
2024-10-11 06:25:25 -06:00
parent 4b81dd46f2
commit 037e6279e6
15 changed files with 302 additions and 169 deletions

12
handlers/init.go Normal file
View File

@@ -0,0 +1,12 @@
package handlers
import "github.com/sirupsen/logrus"
var log *logrus.Logger
func Init(logger *logrus.Logger) error {
log = logger.WithFields(logrus.Fields{
"component": "handlers",
}).Logger
return nil
}

View File

@@ -0,0 +1,36 @@
package handlers
import (
"net/http"
"strconv"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
"ytdlp-site/database"
"ytdlp-site/originals"
)
func ToggleWatched(c echo.Context) error {
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
db := database.Get()
result := db.Model(&originals.Original{}).
Where("id = ?", id).
Update("watched", gorm.Expr("NOT watched"))
if result.Error != nil {
log.Errorln(result.Error)
}
if result.RowsAffected == 0 {
log.Errorln(gorm.ErrRecordNotFound)
}
referrer := c.Request().Referer()
if referrer == "" {
referrer = "/videos"
}
return c.Redirect(http.StatusSeeOther, referrer)
}