diff --git a/common/torrent.go b/common/torrent.go index b2d28c9b..99216a1a 100644 --- a/common/torrent.go +++ b/common/torrent.go @@ -6,6 +6,7 @@ import ( "net/http" "strconv" "strings" + "time" "github.com/gorilla/mux" elastic "gopkg.in/olivere/elastic.v5" @@ -71,8 +72,13 @@ func (p *TorrentParam) FromRequest(r *http.Request) { var status Status status.Parse(r.URL.Query().Get("s")) - p.FromDate = r.URL.Query().Get("fromDate") - p.ToDate = r.URL.Query().Get("toDate") + maxage, err := strconv.Atoi(r.URL.Query().Get("maxage")) + if err != nil { + p.FromDate = r.URL.Query().Get("fromDate") + p.ToDate = r.URL.Query().Get("toDate") + } else { + p.FromDate = time.Now().AddDate(0, 0, -maxage).Format("2006-01-02") + } var category Category category.Parse(r.URL.Query().Get("c")) diff --git a/util/search/search.go b/util/search/search.go index 0ba142b6..af6d8997 100644 --- a/util/search/search.go +++ b/util/search/search.go @@ -4,6 +4,7 @@ import ( "net/http" "strconv" "strings" + "time" "unicode" "unicode/utf8" @@ -123,8 +124,14 @@ func searchByQueryPostgres(r *http.Request, pagenum int, countAll bool, withUser search.UserID = uint(userID) fromID, _ := strconv.Atoi(r.URL.Query().Get("fromID")) search.FromID = uint(fromID) - search.FromDate = r.URL.Query().Get("fromDate") - search.ToDate = r.URL.Query().Get("toDate") + + maxage, err := strconv.Atoi(r.URL.Query().Get("maxage")) + if err != nil { + search.FromDate = r.URL.Query().Get("fromDate") + search.ToDate = r.URL.Query().Get("toDate") + } else { + search.FromDate = time.Now().AddDate(0, 0, -maxage).Format("2006-01-02") + } switch s := r.URL.Query().Get("s"); s { case "1":