From 9fa34273082e588f8876c4f4d1f658f4b3590e92 Mon Sep 17 00:00:00 2001 From: James Mills Date: Wed, 25 Mar 2020 16:22:41 +1000 Subject: Add trending and ability to sort playlist by views --- app/app.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index 71ef0d7..6c56540 100644 --- a/app/app.go +++ b/app/app.go @@ -162,7 +162,7 @@ func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) { log.Printf("/") pl := a.Library.Playlist() if len(pl) > 0 { - http.Redirect(w, r, "/v/"+pl[0].ID, 302) + http.Redirect(w, r, fmt.Sprintf("/v/%s?%s", pl[0].ID, r.URL.RawQuery), 302) } else { ctx := &struct { Playing *media.Video @@ -312,6 +312,13 @@ func (a *App) pageHandler(w http.ResponseWriter, r *http.Request) { video.Views = views } + if r.URL.Query().Get("trending") != "" { + log.Info("sorting by trending") + media.By(media.SortByViews).Sort(playlist) + } else { + media.By(media.SortByTimestamp).Sort(playlist) + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") ctx := &struct { Playing *media.Video -- cgit v1.2.3