révision
efb280fdec
7 fichiers modifiés avec 27 ajouts et 50 suppressions
|
@ -2,7 +2,7 @@
|
|||
.nightswitch {
|
||||
position: fixed;
|
||||
top: 12px;
|
||||
right: 48px;
|
||||
right: 12px;
|
||||
}
|
||||
.nightswitch > a > img {
|
||||
width: 24px;
|
||||
|
@ -43,7 +43,7 @@
|
|||
}
|
||||
#container.cont-view {
|
||||
background: #29363d url(/img/megumin.png) no-repeat;
|
||||
background-size: 75px, 100px;
|
||||
background-size: 75px;
|
||||
}
|
||||
|
||||
body {
|
||||
|
@ -178,6 +178,7 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ
|
|||
max-height: 80vh;
|
||||
}
|
||||
|
||||
/* the curved edges triggered my autism */
|
||||
.navbar {
|
||||
border-radius: 0px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
.nightswitch {
|
||||
position: fixed;
|
||||
top: 12px;
|
||||
right: 48px;
|
||||
right: 12px;
|
||||
}
|
||||
.nightswitch > a > img {
|
||||
width: 24px;
|
||||
|
@ -43,7 +43,7 @@
|
|||
}
|
||||
#container.cont-view {
|
||||
background: white url(/img/renchon.png) no-repeat;
|
||||
background-size: 75px, 100px;
|
||||
background-size: 61px;
|
||||
}
|
||||
|
||||
body {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
import(
|
||||
"time"
|
||||
"net/http"
|
||||
"github.com/gorilla/feeds"
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/util/search"
|
||||
"github.com/gorilla/feeds"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RssHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
_, torrents := search.SearchByQueryNoCount(r, 1)
|
||||
_, torrents, _ := search.SearchByQuery( r, 1 )
|
||||
created_as_time := time.Now()
|
||||
|
||||
if len(torrents) > 0 {
|
||||
|
|
|
@ -23,7 +23,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
search_param, torrents, nbTorrents := search.SearchByQuery(r, pagenum)
|
||||
|
||||
for i := range torrents {
|
||||
for i, _ := range torrents {
|
||||
res := torrents[i].ToJson()
|
||||
b = append(b, res)
|
||||
}
|
||||
|
|
|
@ -53,28 +53,22 @@ func GetTorrentById(id string) (model.Torrents, error) {
|
|||
}
|
||||
|
||||
func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offset int) ([]model.Torrents, int) {
|
||||
return getTorrentsOrderBy(parameters, orderBy, limit, offset, true)
|
||||
}
|
||||
|
||||
func GetTorrentsOrderByNoCount(parameters *WhereParams, orderBy string, limit int, offset int) (torrents []model.Torrents) {
|
||||
torrents, _ = getTorrentsOrderBy(parameters, orderBy, limit, offset, false)
|
||||
return
|
||||
}
|
||||
|
||||
func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offset int, countAll bool) ([]model.Torrents, int) {
|
||||
var torrents []model.Torrents
|
||||
var dbQuery *gorm.DB
|
||||
var count int
|
||||
|
||||
conditions := "torrent_hash IS NOT NULL AND filesize > 0" //filter out broken entries
|
||||
conditions := "torrent_hash IS NOT NULL" // filter out broken entries
|
||||
if strings.HasPrefix(orderBy, "filesize") {
|
||||
// torrents w/ NULL filesize fuck up the sorting on postgres
|
||||
// TODO: fix this properly
|
||||
conditions += " AND filesize IS NOT NULL"
|
||||
}
|
||||
|
||||
var params []interface{}
|
||||
if parameters != nil { // if there is where parameters
|
||||
conditions += " AND " + parameters.Conditions
|
||||
params = parameters.Params
|
||||
}
|
||||
if countAll {
|
||||
db.ORM.Model(&torrents).Where(conditions, params...).Count(&count)
|
||||
}
|
||||
db.ORM.Model(&torrents).Where(conditions, params...).Count(&count)
|
||||
dbQuery = db.ORM.Model(&torrents).Where(conditions, params...)
|
||||
|
||||
if orderBy == "" { // default OrderBy
|
||||
|
@ -92,7 +86,7 @@ func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs
|
|||
* Get Torrents with where parameters and limits, order by default
|
||||
*/
|
||||
func GetTorrents(parameters WhereParams, limit int, offset int) ([]model.Torrents, int) {
|
||||
return getTorrentsOrderBy(¶meters, "", limit, offset, true)
|
||||
return GetTorrentsOrderBy(¶meters, "", limit, offset)
|
||||
}
|
||||
|
||||
/* Get Torrents with where parameters but no limit and order by default (get all the torrents corresponding in the db)
|
||||
|
@ -113,11 +107,6 @@ func GetAllTorrents(limit int, offset int) ([]model.Torrents, int) {
|
|||
return GetTorrentsOrderBy(nil, "", limit, offset)
|
||||
}
|
||||
|
||||
func GetAllTorrentsNoCouting(limit int, offset int) (torrents []model.Torrents) {
|
||||
torrents, _ = getTorrentsOrderBy(nil, "", limit, offset, false)
|
||||
return
|
||||
}
|
||||
|
||||
func GetAllTorrentsDB() ([]model.Torrents, int) {
|
||||
return GetTorrentsOrderBy(nil, "", 0, 0)
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
{{block "search_button" .}}{{end}}
|
||||
</div>
|
||||
</form>
|
||||
<div class="nightswitch" style="position:absolute;right:1em">
|
||||
<div class="nightswitch">
|
||||
<a href="javascript:toggleNightMode();" ><img id="nighticon" src="/img/moon.png"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -31,16 +31,6 @@ func Init(backend string) {
|
|||
}
|
||||
|
||||
func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents, int) {
|
||||
return searchByQuery(r, pagenum, true)
|
||||
|
||||
}
|
||||
|
||||
func SearchByQueryNoCount(r *http.Request, pagenum int) (param SearchParam, torrents []model.Torrents) {
|
||||
param, torrents, _ = searchByQuery(r, pagenum, false)
|
||||
return
|
||||
}
|
||||
|
||||
func searchByQuery(r *http.Request, pagenum int, count bool) (search_param SearchParam, torrents []model.Torrents, n int) {
|
||||
maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max"))
|
||||
if errConv != nil {
|
||||
maxPerPage = 50 // default Value maxPerPage
|
||||
|
@ -49,6 +39,7 @@ func searchByQuery(r *http.Request, pagenum int, count bool) (search_param Searc
|
|||
if maxPerPage > 300 {
|
||||
maxPerPage = 300
|
||||
}
|
||||
search_param := SearchParam{}
|
||||
search_param.Max = maxPerPage
|
||||
search_param.Query = r.URL.Query().Get("q")
|
||||
search_param.Category = r.URL.Query().Get("c")
|
||||
|
@ -91,17 +82,13 @@ func searchByQuery(r *http.Request, pagenum int, count bool) (search_param Searc
|
|||
parameters.Params = append(parameters.Params, search_param.Status)
|
||||
}
|
||||
searchQuerySplit := strings.Split(search_param.Query, " ")
|
||||
for i := range searchQuerySplit {
|
||||
conditions = append(conditions, "torrent_name LIKE ?")
|
||||
for i, _ := range searchQuerySplit {
|
||||
conditions = append(conditions, "torrent_name " + search_op + " ?")
|
||||
parameters.Params = append(parameters.Params, "%"+searchQuerySplit[i]+"%")
|
||||
}
|
||||
|
||||
parameters.Conditions = strings.Join(conditions[:], " AND ")
|
||||
log.Infof("SQL query is :: %s\n", parameters.Conditions)
|
||||
if count {
|
||||
torrents, n = torrentService.GetTorrentsOrderBy(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1))
|
||||
} else {
|
||||
torrents = torrentService.GetTorrentsOrderByNoCount(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1))
|
||||
}
|
||||
return
|
||||
torrents, n := torrentService.GetTorrentsOrderBy(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1))
|
||||
return search_param, torrents, n
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket