started working on playlists support

This commit is contained in:
Laptop
2024-08-25 09:23:03 +03:00
parent b420776711
commit e71e61df72
7 changed files with 94 additions and 2 deletions

21
main.go
View File

@@ -53,6 +53,16 @@ func main() {
c.Set("Content-Type", "text/html")
return templates.Base("users: "+q, templates.SearchUsers(p)).Render(context.Background(), c)
case "playlists":
p, err := sc.SearchPlaylists("?q=" + url.QueryEscape(q))
if err != nil {
fmt.Printf("error getting users for %s: %s\n", q, err)
return err
}
c.Set("Content-Type", "text/html")
return templates.Base("playlists: "+q, templates.SearchPlaylists(p)).Render(context.Background(), c)
}
return c.SendStatus(404)
@@ -95,5 +105,16 @@ func main() {
return templates.Base(usr.Username, templates.User(usr, p)).Render(context.Background(), c)
})
app.Get("/:user/sets/:playlist", func(c *fiber.Ctx) error {
playlist, err := sc.GetPlaylist(c.Params("user") + "/sets/" + c.Params("playlist"))
if err != nil {
fmt.Printf("error getting %s playlist from %s: %s\n", c.Params("playlist"), c.Params("user"), err)
return err
}
c.Set("Content-Type", "text/html")
return templates.Base(playlist.Title+" by "+playlist.Author.Username, templates.Playlist(playlist)).Render(context.Background(), c)
})
log.Fatal(app.Listen(cfg.Addr))
}