magneticow: most recent torrents now works correctly
This commit is contained in:
parent
cab54c6ec1
commit
80881c42c3
@ -49,11 +49,21 @@ func apiTorrentsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
*tq.Ascending = true
|
||||
}
|
||||
|
||||
orderBy, err := parseOrderBy(tq.OrderBy)
|
||||
var orderBy persistence.OrderingCriteria
|
||||
if tq.OrderBy == nil {
|
||||
if *tq.Query == "" {
|
||||
orderBy = persistence.ByDiscoveredOn
|
||||
} else {
|
||||
orderBy = persistence.ByRelevance
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
orderBy, err = parseOrderBy(*tq.OrderBy)
|
||||
if err != nil {
|
||||
respondError(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
torrents, err := database.QueryTorrents(
|
||||
*tq.Query, *tq.Epoch, orderBy,
|
||||
@ -87,12 +97,8 @@ func apiStatisticsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func parseOrderBy(s *string) (persistence.OrderingCriteria, error) {
|
||||
if s == nil {
|
||||
return persistence.ByRelevance, nil
|
||||
}
|
||||
|
||||
switch *s {
|
||||
func parseOrderBy(s string) (persistence.OrderingCriteria, error) {
|
||||
switch s {
|
||||
case "TOTAL_SIZE":
|
||||
return persistence.ByTotalSize, nil
|
||||
|
||||
|
@ -17,10 +17,20 @@ window.onload = function() {
|
||||
title.textContent = query + " - magneticow";
|
||||
const input = document.getElementsByTagName("input")[0];
|
||||
input.setAttribute("value", query);
|
||||
}
|
||||
else
|
||||
|
||||
setOrderBy("RELEVANCE");
|
||||
} else {
|
||||
title.textContent = "Most recent torrents - magneticow";
|
||||
|
||||
ascending = false;
|
||||
setOrderBy("DISCOVERED_ON");
|
||||
}
|
||||
|
||||
if (query) {
|
||||
const feedAnchor = document.getElementById("feed-anchor");
|
||||
feedAnchor.setAttribute("href", "/feed?query=" + encodeURIComponent(query));
|
||||
}
|
||||
|
||||
load();
|
||||
};
|
||||
|
||||
@ -63,7 +73,9 @@ function load() {
|
||||
query : query,
|
||||
epoch : epoch,
|
||||
lastID : lastID,
|
||||
lastOrderedValue: lastOrderedValue
|
||||
lastOrderedValue: lastOrderedValue,
|
||||
orderBy : orderBy,
|
||||
ascending : ascending
|
||||
});
|
||||
|
||||
console.log("reqURL", reqURL);
|
||||
@ -86,6 +98,10 @@ function load() {
|
||||
return;
|
||||
}
|
||||
|
||||
const last = torrents[torrents.length - 1];
|
||||
lastID = last.id;
|
||||
lastOrderedValue = orderedValue(last);
|
||||
|
||||
for (let t of torrents) {
|
||||
t.size = fileSize(t.size);
|
||||
t.discoveredOn = (new Date(t.discoveredOn * 1000)).toLocaleDateString("en-GB", {
|
||||
@ -96,10 +112,6 @@ function load() {
|
||||
|
||||
tbody.innerHTML += Mustache.render(template, t);
|
||||
}
|
||||
|
||||
const last = torrents[torrents.length - 1];
|
||||
lastID = last.id;
|
||||
lastOrderedValue = orderedValue(last);
|
||||
};
|
||||
|
||||
req.open("GET", reqURL);
|
||||
|
Loading…
Reference in New Issue
Block a user