mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 21:59:38 +05:00
view what tracks/playlists a user liked; small internal improvements
This commit is contained in:
@@ -56,6 +56,6 @@ func GetSelections(prefs cfg.Preferences) (*Paginated[*Selection], error) {
|
|||||||
func (s *Selection) Fix(prefs cfg.Preferences) {
|
func (s *Selection) Fix(prefs cfg.Preferences) {
|
||||||
for _, p := range s.Items.Collection {
|
for _, p := range s.Items.Collection {
|
||||||
p.Fix(false)
|
p.Fix(false)
|
||||||
p.Postfix(prefs)
|
p.Postfix(prefs, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func SearchPlaylists(prefs cfg.Preferences, args string) (*Paginated[*Playlist],
|
|||||||
|
|
||||||
for _, p := range p.Collection {
|
for _, p := range p.Collection {
|
||||||
p.Fix(false)
|
p.Fix(false)
|
||||||
p.Postfix(prefs)
|
p.Postfix(prefs, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &p, nil
|
return &p, nil
|
||||||
@@ -107,18 +107,22 @@ func (p *Playlist) Fix(cached bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) Postfix(prefs cfg.Preferences) []Track {
|
func (p *Playlist) Postfix(prefs cfg.Preferences, fixTracks bool) []Track {
|
||||||
if cfg.ProxyImages && *prefs.ProxyImages && p.Artwork != "" {
|
if cfg.ProxyImages && *prefs.ProxyImages && p.Artwork != "" {
|
||||||
p.Artwork = "/_/proxy/images?url=" + url.QueryEscape(p.Artwork)
|
p.Artwork = "/_/proxy/images?url=" + url.QueryEscape(p.Artwork)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Author.Postfix(prefs)
|
p.Author.Postfix(prefs)
|
||||||
var fixed = make([]Track, len(p.Tracks))
|
if fixTracks {
|
||||||
for i, t := range p.Tracks {
|
var fixed = make([]Track, len(p.Tracks))
|
||||||
t.Postfix(prefs)
|
for i, t := range p.Tracks {
|
||||||
fixed[i] = t
|
t.Postfix(prefs)
|
||||||
|
fixed[i] = t
|
||||||
|
}
|
||||||
|
return fixed
|
||||||
}
|
}
|
||||||
return fixed
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Playlist) FormatDescription() string {
|
func (p Playlist) FormatDescription() string {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ type Repost struct {
|
|||||||
Playlist *Playlist // type == playlist-repost
|
Playlist *Playlist // type == playlist-repost
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repost) Fix(prefs cfg.Preferences) {
|
func (r Repost) Fix(prefs cfg.Preferences) {
|
||||||
switch r.Type {
|
switch r.Type {
|
||||||
case TrackRepost:
|
case TrackRepost:
|
||||||
if r.Track != nil {
|
if r.Track != nil {
|
||||||
@@ -59,12 +59,27 @@ func (r *Repost) Fix(prefs cfg.Preferences) {
|
|||||||
case PlaylistRepost:
|
case PlaylistRepost:
|
||||||
if r.Playlist != nil {
|
if r.Playlist != nil {
|
||||||
r.Playlist.Fix(false) // err always nil if cached == false
|
r.Playlist.Fix(false) // err always nil if cached == false
|
||||||
r.Playlist.Postfix(prefs)
|
r.Playlist.Postfix(prefs, false)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// same thing
|
||||||
|
type Like struct {
|
||||||
|
Track *Track
|
||||||
|
Playlist *Playlist
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l Like) Fix(prefs cfg.Preferences) {
|
||||||
|
if l.Track != nil {
|
||||||
|
l.Track.Fix(false)
|
||||||
|
l.Track.Postfix(prefs)
|
||||||
|
} else if l.Playlist != nil {
|
||||||
|
l.Playlist.Fix(false)
|
||||||
|
l.Playlist.Postfix(prefs, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
func GetUser(permalink string) (User, error) {
|
func GetUser(permalink string) (User, error) {
|
||||||
usersCacheLock.RLock()
|
usersCacheLock.RLock()
|
||||||
if cell, ok := UsersCache[permalink]; ok && cell.Expires.After(time.Now()) {
|
if cell, ok := UsersCache[permalink]; ok && cell.Expires.After(time.Now()) {
|
||||||
@@ -189,7 +204,7 @@ func (u *User) GetPlaylists(prefs cfg.Preferences, args string) (*Paginated[*Pla
|
|||||||
|
|
||||||
for _, pl := range p.Collection {
|
for _, pl := range p.Collection {
|
||||||
pl.Fix(false)
|
pl.Fix(false)
|
||||||
pl.Postfix(prefs)
|
pl.Postfix(prefs, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &p, nil
|
return &p, nil
|
||||||
@@ -207,7 +222,7 @@ func (u *User) GetAlbums(prefs cfg.Preferences, args string) (*Paginated[*Playli
|
|||||||
|
|
||||||
for _, pl := range p.Collection {
|
for _, pl := range p.Collection {
|
||||||
pl.Fix(false)
|
pl.Fix(false)
|
||||||
pl.Postfix(prefs)
|
pl.Postfix(prefs, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &p, nil
|
return &p, nil
|
||||||
@@ -229,3 +244,20 @@ func (u *User) GetReposts(prefs cfg.Preferences, args string) (*Paginated[*Repos
|
|||||||
|
|
||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *User) GetLikes(prefs cfg.Preferences, args string) (*Paginated[*Like], error) {
|
||||||
|
p := Paginated[*Like]{
|
||||||
|
Next: "https://" + api + "/users/" + u.ID + "/likes" + args,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := p.Proceed(true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range p.Collection {
|
||||||
|
l.Fix(prefs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &p, nil
|
||||||
|
}
|
||||||
|
|||||||
25
main.go
25
main.go
@@ -310,6 +310,29 @@ func main() {
|
|||||||
return templates.Base(user.Username, templates.UserReposts(prefs, user, p), templates.UserHeader(user)).Render(context.Background(), c)
|
return templates.Base(user.Username, templates.UserReposts(prefs, user, p), templates.UserHeader(user)).Render(context.Background(), c)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.Get("/:user/likes", func(c *fiber.Ctx) error {
|
||||||
|
prefs, err := preferences.Get(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := sc.GetUser(c.Params("user"))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error getting %s (likes): %s\n", c.Params("user"), err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
user.Postfix(prefs)
|
||||||
|
|
||||||
|
p, err := user.GetLikes(prefs, c.Query("pagination", "?limit=20"))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error getting %s likes: %s\n", c.Params("user"), err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Set("Content-Type", "text/html")
|
||||||
|
return templates.Base(user.Username, templates.UserLikes(prefs, user, p), templates.UserHeader(user)).Render(context.Background(), c)
|
||||||
|
})
|
||||||
|
|
||||||
app.Get("/:user/:track", func(c *fiber.Ctx) error {
|
app.Get("/:user/:track", func(c *fiber.Ctx) error {
|
||||||
prefs, err := preferences.Get(c)
|
prefs, err := preferences.Get(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -385,7 +408,7 @@ func main() {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Don't ask why
|
// Don't ask why
|
||||||
playlist.Tracks = playlist.Postfix(prefs)
|
playlist.Tracks = playlist.Postfix(prefs, true)
|
||||||
|
|
||||||
p := c.Query("pagination")
|
p := c.Query("pagination")
|
||||||
if p != "" {
|
if p != "" {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/maid-zone/soundcloak/lib/cfg"
|
||||||
"github.com/maid-zone/soundcloak/lib/sc"
|
"github.com/maid-zone/soundcloak/lib/sc"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/maid-zone/soundcloak/lib/cfg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
templ UserHeader(u sc.User) {
|
templ UserHeader(u sc.User) {
|
||||||
@@ -59,16 +59,33 @@ templ UserBase(prefs cfg.Preferences, u sc.User) {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type btn struct {
|
||||||
|
text string
|
||||||
|
href string
|
||||||
|
external bool
|
||||||
|
}
|
||||||
|
|
||||||
|
templ UserButtons(current string, user string) {
|
||||||
|
<div class="btns"> // this part is the tedious one now, because formatting breaks if i space the list out with newlines
|
||||||
|
for _, b := range [6]btn{{"tracks", "", false},{"playlists", "/sets",false},{"albums", "/albums", false},{"reposts","/reposts", false},{"likes", "/likes", false},{"view on soundcloud", "https://soundcloud.com/"+user, true}} {
|
||||||
|
if b.text == current {
|
||||||
|
<a class="btn active">{b.text}</a>
|
||||||
|
} else {
|
||||||
|
if b.external {
|
||||||
|
<a class="btn" href={ templ.URL(b.href) } referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank">{ b.text }</a>
|
||||||
|
} else {
|
||||||
|
<a class="btn" href={ templ.URL("/" + user + b.href) }>{ b.text }</a>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
templ User(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Track]) {
|
templ User(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Track]) {
|
||||||
@UserBase(prefs, u)
|
@UserBase(prefs, u)
|
||||||
// kinda tedious but whatever, might make it more flexible in the future
|
// kinda tedious but whatever, might make it more flexible in the future
|
||||||
<div class="btns">
|
// ^ outdated, no longer tedious but whatever
|
||||||
<a class="btn active">tracks</a>
|
@UserButtons("tracks", u.Permalink)
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/sets") }>playlists</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/albums") }>albums</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/reposts") }>reposts</a>
|
|
||||||
<a class="btn" href={ templ.URL("https://soundcloud.com/" + u.Permalink) } referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank">view on soundcloud</a>
|
|
||||||
</div>
|
|
||||||
<br/>
|
<br/>
|
||||||
if len(p.Collection) != 0 {
|
if len(p.Collection) != 0 {
|
||||||
<div>
|
<div>
|
||||||
@@ -86,13 +103,7 @@ templ User(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Track]) {
|
|||||||
|
|
||||||
templ UserPlaylists(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
|
templ UserPlaylists(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
|
||||||
@UserBase(prefs, u)
|
@UserBase(prefs, u)
|
||||||
<div class="btns">
|
@UserButtons("playlists", u.Permalink)
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink) }>tracks</a>
|
|
||||||
<a class="btn active">playlists</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/albums") }>albums</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/reposts") }>reposts</a>
|
|
||||||
<a class="btn" href={ templ.URL("https://soundcloud.com/" + u.Permalink) } referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank">view on soundcloud</a>
|
|
||||||
</div>
|
|
||||||
<br/>
|
<br/>
|
||||||
if len(p.Collection) != 0 {
|
if len(p.Collection) != 0 {
|
||||||
<div>
|
<div>
|
||||||
@@ -110,13 +121,7 @@ templ UserPlaylists(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playli
|
|||||||
|
|
||||||
templ UserAlbums(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
|
templ UserAlbums(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]) {
|
||||||
@UserBase(prefs, u)
|
@UserBase(prefs, u)
|
||||||
<div class="btns">
|
@UserButtons("albums", u.Permalink)
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink) }>tracks</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/sets") }>playlists</a>
|
|
||||||
<a class="btn active">albums</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/reposts") }>reposts</a>
|
|
||||||
<a class="btn" href={ templ.URL("https://soundcloud.com/" + u.Permalink) } referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank">view on soundcloud</a>
|
|
||||||
</div>
|
|
||||||
<br/>
|
<br/>
|
||||||
if len(p.Collection) != 0 {
|
if len(p.Collection) != 0 {
|
||||||
<div>
|
<div>
|
||||||
@@ -134,13 +139,7 @@ templ UserAlbums(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Playlist]
|
|||||||
|
|
||||||
templ UserReposts(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Repost]) {
|
templ UserReposts(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Repost]) {
|
||||||
@UserBase(prefs, u)
|
@UserBase(prefs, u)
|
||||||
<div class="btns">
|
@UserButtons("reposts", u.Permalink)
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink) }>tracks</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/sets") }>playlists</a>
|
|
||||||
<a class="btn" href={ templ.URL("/" + u.Permalink + "/albums") }>albums</a>
|
|
||||||
<a class="btn active">reposts</a>
|
|
||||||
<a class="btn" href={ templ.URL("https://soundcloud.com/" + u.Permalink) } referrerpolicy="no-referrer" rel="external nofollow noopener noreferrer" target="_blank">view on soundcloud</a>
|
|
||||||
</div>
|
|
||||||
<br/>
|
<br/>
|
||||||
if len(p.Collection) != 0 {
|
if len(p.Collection) != 0 {
|
||||||
<div>
|
<div>
|
||||||
@@ -160,6 +159,28 @@ templ UserReposts(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Repost])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templ UserLikes(prefs cfg.Preferences, u sc.User, p *sc.Paginated[*sc.Like]) {
|
||||||
|
@UserBase(prefs, u)
|
||||||
|
@UserButtons("likes", u.Permalink)
|
||||||
|
<br/>
|
||||||
|
if len(p.Collection) != 0 {
|
||||||
|
<div>
|
||||||
|
for _, like := range p.Collection {
|
||||||
|
if like.Track != nil {
|
||||||
|
@TrackItem(like.Track, true)
|
||||||
|
} else if like.Playlist != nil {
|
||||||
|
@PlaylistItem(like.Playlist, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
if p.Next != "" && len(p.Collection) != int(p.Total) {
|
||||||
|
<a class="btn" href={ templ.URL("?pagination=" + url.QueryEscape(strings.Split(p.Next, "/likes")[1])) } rel="noreferrer">more likes</a>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<span>no more likes</span>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
templ SearchUsers(p *sc.Paginated[*sc.User]) {
|
templ SearchUsers(p *sc.Paginated[*sc.User]) {
|
||||||
<span>Found { strconv.FormatInt(p.Total, 10) } users</span>
|
<span>Found { strconv.FormatInt(p.Total, 10) } users</span>
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
Reference in New Issue
Block a user