Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Added also a maxage field

Now you can provide ?maxage=nb_days to get the torrents from the last
nb_days days
Cette révision appartient à :
akuma06 2017-06-02 16:25:45 +02:00
Parent f41f2c3a25
révision 61a0ab0bc3
2 fichiers modifiés avec 17 ajouts et 4 suppressions

Voir le fichier

@ -6,6 +6,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/gorilla/mux" "github.com/gorilla/mux"
elastic "gopkg.in/olivere/elastic.v5" elastic "gopkg.in/olivere/elastic.v5"
@ -71,8 +72,13 @@ func (p *TorrentParam) FromRequest(r *http.Request) {
var status Status var status Status
status.Parse(r.URL.Query().Get("s")) status.Parse(r.URL.Query().Get("s"))
p.FromDate = r.URL.Query().Get("fromDate") maxage, err := strconv.Atoi(r.URL.Query().Get("maxage"))
p.ToDate = r.URL.Query().Get("toDate") 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 var category Category
category.Parse(r.URL.Query().Get("c")) category.Parse(r.URL.Query().Get("c"))

Voir le fichier

@ -4,6 +4,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time"
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
@ -123,8 +124,14 @@ func searchByQueryPostgres(r *http.Request, pagenum int, countAll bool, withUser
search.UserID = uint(userID) search.UserID = uint(userID)
fromID, _ := strconv.Atoi(r.URL.Query().Get("fromID")) fromID, _ := strconv.Atoi(r.URL.Query().Get("fromID"))
search.FromID = uint(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 { switch s := r.URL.Query().Get("s"); s {
case "1": case "1":