Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/controllers/search_handler.go
akuma06 205daea027 Finally services are nearly empty 👍
Moved api services. All validations are now in validator util and all upload functions are in upload util
2017-07-01 23:09:35 +02:00

53 lignes
1,4 Kio
Go

package controllers
import (
"html"
"net/http"
"strconv"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/util/search"
"github.com/gin-gonic/gin"
)
// SearchHandler : Controller for displaying search result page, accepting common search arguments
func SearchHandler(c *gin.Context) {
var err error
// TODO Don't create a new client for each request
// TODO Fallback to postgres search if es is down
page := c.Param("page")
// db params url
pagenum := 1
if page != "" {
pagenum, err = strconv.Atoi(html.EscapeString(page))
if !log.CheckError(err) {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
if pagenum <= 0 {
NotFoundHandler(c)
return
}
}
searchParam, torrents, nbTorrents, err := search.SearchByQuery(c, pagenum)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
// Convert back to strings for now.
// TODO Deprecate fully SearchParam and only use TorrentParam
category := ""
if len(searchParam.Category) > 0 {
category = searchParam.Category[0].String()
}
nav := navigation{int(nbTorrents), int(searchParam.Max), int(searchParam.Page), "search"}
searchForm := newSearchForm(c)
searchForm.SearchParam, searchForm.Category = searchParam, category
modelList(c, "site/torrents/listing.jet.html", models.TorrentsToJSON(torrents), nav, searchForm)
}