2023-08-14 18:14:08 -04:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.fifitido.net/ytdl-web/app"
|
|
|
|
"go.fifitido.net/ytdl-web/pkg/htmx"
|
|
|
|
"go.fifitido.net/ytdl-web/pkg/server"
|
|
|
|
"go.fifitido.net/ytdl-web/pkg/view"
|
2023-08-14 18:16:42 -04:00
|
|
|
"go.fifitido.net/ytdl-web/pkg/ytdl"
|
2023-08-14 18:14:08 -04:00
|
|
|
"go.fifitido.net/ytdl-web/version"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HomeController struct {
|
|
|
|
ytdl ytdl.Ytdl
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ server.Controller = (*HomeController)(nil)
|
|
|
|
|
|
|
|
func NewHomeController(ytdl ytdl.Ytdl) *HomeController {
|
|
|
|
return &HomeController{
|
|
|
|
ytdl: ytdl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HomeController) Router(r chi.Router) {
|
|
|
|
r.Get("/", c.Index)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HomeController) Index(w http.ResponseWriter, r *http.Request) {
|
|
|
|
hx := htmx.New(w, r)
|
|
|
|
|
|
|
|
if hx.IsHtmxRequest() {
|
|
|
|
hx.PushUrl("/")
|
|
|
|
|
|
|
|
app.Views.Render(w, "index", view.Data{
|
|
|
|
"BasePath": viper.GetString("base_path"),
|
|
|
|
"Version": version.Version,
|
|
|
|
"Build": version.Build,
|
|
|
|
"BinaryVersion": c.ytdl.Version(),
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
app.Views.Render(w, "index", view.Data{
|
|
|
|
"BasePath": viper.GetString("base_path"),
|
|
|
|
"Version": version.Version,
|
|
|
|
"Build": version.Build,
|
|
|
|
"BinaryVersion": c.ytdl.Version(),
|
|
|
|
}, "layouts/main")
|
|
|
|
}
|
|
|
|
}
|