Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Removed the old search parameter on /api.
Fixed issue with navigatation.
Fixed issue with notifications.
Fixed issue with fake anonymous upload on search with userID.
Fixed issue with number of upload on user page.
Moved api to version 1.1.0 with search displaying same as /api
Cette révision appartient à :
akuma06 2017-07-20 20:21:57 +02:00
Parent 8cb217eb33
révision c5b3702fcd
9 fichiers modifiés avec 347 ajouts et 114 suppressions

Voir le fichier

@ -13,4 +13,233 @@
// ------------------------------------------------------------------------------------------
// History.
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
/**
* @api {get} / Request Torrents index
* @apiVersion 1.0.0
* @apiName GetTorrents
* @apiGroup Torrents
*
* @apiParam {Number} id Torrent unique ID.
*
* @apiSuccess {Object[]} torrents List of torrent object (see view for the properties).
* @apiSuccess {Number} queryRecordCount Number of torrents given.
* @apiSuccess {Number} totalRecordCount Total number of torrents.
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "torrents": [...],
* "queryRecordCount": 50,
* "totalRecordCount": 798414
* }
*
* @apiUse NotFoundError
*/
/**
* @api {get} /view/:id Request Torrent information
* @apiVersion 1.0.0
* @apiName GetTorrent
* @apiGroup Torrents
*
* @apiParam {Number} id Torrent unique ID.
*
* @apiSuccess {Number} id ID of the torrent.
* @apiSuccess {String} name Name of the torrent.
* @apiSuccess {Number} status Status of the torrent.
* @apiSuccess {String} hash Hash of the torrent.
* @apiSuccess {Date} date Uploaded date of the torrent.
* @apiSuccess {Number} filesize File size in Bytes of the torrent.
* @apiSuccess {String} description Description of the torrent.
* @apiSuccess {Object[]} comments Comments of the torrent.
* @apiSuccess {String} sub_category Sub Category of the torrent.
* @apiSuccess {String} category Category of the torrent.
* @apiSuccess {String} anidb_id Anidb ID of the torrent.
* @apiSuccess {Number} uploader_id ID of the torrent uploader.
* @apiSuccess {String} uploader_name Username of the torrent uploader.
* @apiSuccess {String} uploader_old Old username from nyaa of the torrent uploader.
* @apiSuccess {String} website_link External Link of the torrent.
* @apiSuccess {String[]} languages Languages of the torrent.
* @apiSuccess {String} magnet Magnet URI of the torrent.
* @apiSuccess {String} torrent Download URL of the torrent.
* @apiSuccess {Number} seeders Number of seeders of the torrent.
* @apiSuccess {Number} leechers Number of leechers of the torrent.
* @apiSuccess {Number} completed Downloads completed of the torrent.
* @apiSuccess {Date} last_scrape Last statistics update of the torrent.
* @apiSuccess {Object[]} file_list List of files in the torrent.
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "id": 952801,
* "name": "[HorribleSubs] Uchouten Kazoku S2 [720p]",
* "status": 1,
* "hash": "6E4D96F7A0B0456672E80B150CCB7C15868CD47D",
* "date": "2017-07-05T11:01:39Z",
* "filesize": 4056160259,
* "description": "<p>Unofficial batch</p>\n",
* "comments": [],
* "sub_category": "5",
* "category": "3",
* "anidb_id": "",
* "downloads": 0,
* "uploader_id": 7177,
* "uploader_name": "DarAR92",
* "uploader_old": "",
* "website_link": "http://horriblesubs.info/",
* "languages": [
* "en-us"
* ],
* "magnet": "magnet:?xt=urn:btih:6E4D96F7A0B0456672E80B150CCB7C15868CD47D&dn=%5BHorribleSubs%5D+Uchouten+Kazoku+S2+%5B720p%5D&tr=http://nyaa.tracker.wf:7777/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=udp://tracker.doko.moe:6969&tr=http://tracker.anirena.com:80/announce&tr=http://anidex.moe:6969/announce&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://zer0day.ch:1337&tr=udp://9.rarbg.com:2710/announce&tr=udp://tracker2.christianbro.pw:6969/announce&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://eddie4.nl:6969/announce&tr=udp://tracker.doko.moe:6969/announce",
* "torrent": "https://nyaa.pantsu.cat/download/6E4D96F7A0B0456672E80B150CCB7C15868CD47D",
* "seeders": 4,
* "leechers": 2,
* "completed": 28,
* "last_scrape": "2017-07-07T07:48:32.509635Z",
* "file_list": [
* {
* "path": "[HorribleSubs] Uchouten Kazoku S2 - 01[720p].mkv",
* "filesize": 338250895
* },
* {
* "path": "[HorribleSubs] Uchouten Kazoku S2 - 12 [720p].mkv",
* "filesize": 338556275
* }
* ]
* }
*
* @apiUse NotFoundError
*/
/**
* @api {get} /head/:id Request Torrent Head
* @apiVersion 1.0.0
* @apiName GetTorrentHead
* @apiGroup Torrents
*
* @apiParam {Number} id Torrent unique ID.
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
*
* @apiUse NotFoundError
*/
/**
* @api {post} /upload Upload a Torrent
* @apiVersion 1.0.0
* @apiName UploadTorrent
* @apiGroup Torrents
*
* @apiParam {String} username Torrent uploader name.
* @apiParam {String} name Torrent name.
* @apiParam {String} magnet Torrent magnet URI.
* @apiParam {String} category Torrent category.
* @apiParam {Boolean} remake Torrent is a remake.
* @apiParam {String} description Torrent description.
* @apiParam {Number} status Torrent status.
* @apiParam {Boolean} hidden Torrent hidden.
* @apiParam {String} website_link Torrent website link.
* @apiParam {String[]} languages Torrent languages.
* @apiParam {File} torrent Torrent file to upload (you have to send a torrent file or a magnet, not both!).
*
* @apiSuccess {Boolean} ok The request is done without failing
* @apiSuccess {String[]} infos Messages information relative to the request
* @apiSuccess {Object} data The resulting torrent uploaded (see view for the properties)
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
*
* @apiUse RequestError
*/
/**
* @api {post} /update/ Update a Torrent
* @apiVersion 1.0.0
* @apiName UpdateTorrent
* @apiGroup Torrents
*
* @apiParam {String} username Torrent uploader name.
* @apiParam {Number} id Torrent ID.
* @apiParam {String} name Torrent name.
* @apiParam {String} category Torrent category.
* @apiParam {Boolean} remake Torrent is a remake.
* @apiParam {String} description Torrent description.
* @apiParam {Number} status Torrent status.
* @apiParam {Boolean} hidden Torrent hidden.
* @apiParam {String} website_link Torrent website link.
* @apiParam {String[]} languages Torrent languages.
*
* @apiSuccess {Boolean} ok The request is done without failing
* @apiSuccess {String[]} infos Messages information relative to the request
* @apiSuccess {Object} data The resulting torrent updated (see view for the properties)
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
*
* @apiUse RequestError
*/
/**
* @api {get} /search/ Request Torrents index
* @apiVersion 1.0.0
* @apiName FindTorrents
* @apiGroup Torrents
*
* @apiParam {String[]} c In which categories to search.
* @apiParam {String} q Query to search (torrent name).
* @apiParam {String} limit Number of results per page.
* @apiParam {String} userID Uploader ID owning the torrents.
* @apiParam {String} fromID Show results with torrents ID superior to this.
* @apiParam {String} s Torrent status.
* @apiParam {String} maxage Torrents which have been uploaded the last x days.
* @apiParam {String} toDate Torrents which have been uploaded since x <code>dateType</code>.
* @apiParam {String} fromDate Torrents which have been uploaded the last x <code>dateType</code>.
* @apiParam {String} dateType Which type of date (<code>d</code> for days, <code>m</code> for months, <code>y</code> for years).
* @apiParam {String} minSize Filter by minimal size in <code>sizeType</code>.
* @apiParam {String} maxSize Filter by maximal size in <code>sizeType</code>.
* @apiParam {String} sizeType Which type of size (<code>b</code> for bytes, <code>k</code> for kilobytes, <code>m</code> for megabytes, <code>g</code> for gigabytes).
* @apiParam {String} sort Torrent sorting type (0 = id, 1 = name, 2 = date, 3 = downloads, 4 = size, 5 = seeders, 6 = leechers, 7 = completed).
* @apiParam {Boolean} order Order ascending or descending (true = ascending).
* @apiParam {String[]} lang Filter the languages.
* @apiParam {Number} page Search page.
*
* @apiSuccess {Object[]} torrents List of torrent object (see view for the properties).
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* [...]
* }
*
* @apiUse NotFoundError
*/
/**
* @api {post} /login/ Login a user
* @apiVersion 1.0.0
* @apiName Login
* @apiGroup Users
*
* @apiParam {String} username Username or Email.
* @apiParam {String} password Password.
*
* @apiSuccess {Boolean} ok The request is done without failing
* @apiSuccess {String[]} infos Messages information relative to the request
* @apiSuccess {Object} data The connected user object
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* data:
* [{
* user_id:1,
* username:"username",
* status:1,
* token:"token",
* md5:"",
* created_at:"date",
* liking_count:0,
* liked_count:0
* }],
* infos: ["Logged", ... ],
* ok:true
* }
*
* @apiUse RequestError
*/

Voir le fichier

@ -9,6 +9,7 @@ import (
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/controllers/feed"
"github.com/NyaaPantsu/nyaa/controllers/router"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/models/users"
@ -17,7 +18,6 @@ import (
"github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/search"
"github.com/NyaaPantsu/nyaa/utils/search/structs"
"github.com/NyaaPantsu/nyaa/utils/upload"
"github.com/NyaaPantsu/nyaa/utils/validator"
"github.com/NyaaPantsu/nyaa/utils/validator/torrent"
@ -56,7 +56,7 @@ import (
/**
* @api {get} / Request Torrents index
* @apiVersion 1.0.0
* @apiVersion 1.1.0
* @apiName GetTorrents
* @apiGroup Torrents
*
@ -83,66 +83,13 @@ func APIHandler(c *gin.Context) {
if t != "" {
feedController.RSSTorznabHandler(c)
} else {
page := c.Param("page")
whereParams := structs.WhereParams{}
req := upload.TorrentsRequest{}
contentType := c.Request.Header.Get("Content-Type")
if contentType == "application/json" {
c.Bind(&req)
if req.MaxPerPage == 0 {
req.MaxPerPage = config.Get().Navigation.TorrentsPerPage
}
if req.Page <= 0 {
req.Page = 1
}
whereParams = req.ToParams()
} else {
var err error
maxString := c.Query("max")
if maxString != "" {
req.MaxPerPage, err = strconv.Atoi(maxString)
if !log.CheckError(err) {
req.MaxPerPage = config.Get().Navigation.TorrentsPerPage
}
} else {
req.MaxPerPage = config.Get().Navigation.TorrentsPerPage
}
req.Page = 1
if page != "" {
req.Page, err = strconv.Atoi(html.EscapeString(page))
if err != nil || req.Page <= 0 {
c.AbortWithError(http.StatusNotFound, err)
return
}
}
}
torrentSearch, nbTorrents, err := torrents.Find(whereParams, req.MaxPerPage, req.MaxPerPage*(req.Page-1))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
b := upload.APIResultJSON{
Torrents: torrents.APITorrentsToJSON(torrentSearch),
}
b.QueryRecordCount = req.MaxPerPage
b.TotalRecordCount = nbTorrents
c.JSON(http.StatusOK, b)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
APISearchHandler(c)
}
}
/**
* @api {get} /view/:id Request Torrent information
* @apiVersion 1.0.0
* @apiVersion 1.1.0
* @apiName GetTorrent
* @apiGroup Torrents
*
@ -232,7 +179,7 @@ func APIViewHandler(c *gin.Context) {
/**
* @api {get} /head/:id Request Torrent Head
* @apiVersion 1.0.0
* @apiVersion 1.1.0
* @apiName GetTorrentHead
* @apiGroup Torrents
*
@ -264,7 +211,7 @@ func APIViewHeadHandler(c *gin.Context) {
/**
* @api {post} /upload Upload a Torrent
* @apiVersion 1.0.0
* @apiVersion 1.1.0
* @apiName UploadTorrent
* @apiGroup Torrents
*
@ -351,7 +298,7 @@ func APIUploadHandler(c *gin.Context) {
/**
* @api {post} /update/ Update a Torrent
* @apiVersion 1.0.0
* @apiVersion 1.1.0
* @apiName UpdateTorrent
* @apiGroup Torrents
*
@ -421,7 +368,7 @@ func APIUpdateHandler(c *gin.Context) {
/**
* @api {get} /search/ Request Torrents index
* @apiVersion 1.0.0
* @apiVersion 1.1.0
* @apiName FindTorrents
* @apiGroup Torrents
*
@ -448,7 +395,9 @@ func APIUpdateHandler(c *gin.Context) {
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* [...]
* "torrents": [...],
* "queryRecordCount": 50,
* "totalRecordCount": 798414
* }
*
* @apiUse NotFoundError
@ -457,6 +406,7 @@ func APIUpdateHandler(c *gin.Context) {
func APISearchHandler(c *gin.Context) {
c.Header("Content-Type", "application/json")
page := c.Param("page")
currentUser := router.GetUser(c)
// db params url
var err error
@ -473,19 +423,36 @@ func APISearchHandler(c *gin.Context) {
}
}
_, torrentSearch, _, err := search.ByQueryWithUser(c, pagenum)
userID, err := strconv.ParseUint(c.Query("userID"), 10, 32)
if err != nil {
userID = 0
}
_, torrentSearch, nbTorrents, err := search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrAdmin(uint(userID)))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
b := torrents.APITorrentsToJSON(torrentSearch)
maxQuery, err := strconv.Atoi(c.DefaultQuery("limit", strconv.Itoa(config.Get().Navigation.TorrentsPerPage)))
if err != nil {
maxQuery = config.Get().Navigation.TorrentsPerPage
} else if maxQuery > config.Get().Navigation.MaxTorrentsPerPage {
maxQuery = config.Get().Navigation.MaxTorrentsPerPage
}
b := upload.APIResultJSON{
TotalRecordCount: nbTorrents,
Torrents: torrents.APITorrentsToJSON(torrentSearch),
QueryRecordCount: maxQuery,
}
c.JSON(http.StatusOK, b)
}
/**
* @api {post} /login/ Login a user
* @apiVersion 1.0.0
* @apiVersion 1.1.0
* @apiName Login
* @apiGroup Users
*

Voir le fichier

@ -7,6 +7,7 @@ import (
"time"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/controllers/router"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/users"
"github.com/NyaaPantsu/nyaa/utils/feeds"
@ -19,6 +20,7 @@ func getTorrentList(c *gin.Context) (torrents []models.Torrent, createdAsTime ti
userID := c.Param("id")
cat := c.Query("cat")
offset := 0
currentUser := router.GetUser(c)
if c.Query("offset") != "" {
offset, err = strconv.Atoi(html.EscapeString(c.Query("offset")))
if err != nil {
@ -79,7 +81,12 @@ func getTorrentList(c *gin.Context) (torrents []models.Torrent, createdAsTime ti
c.Request.URL.RawQuery = query.Encode()
}
_, torrents, err = search.ByQueryNoCount(c, pagenum)
user, err := strconv.ParseUint(c.Param("id"), 10, 32)
if err != nil {
user = 0
}
_, torrents, _, err = search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrAdmin(uint(user)))
return
}

Voir le fichier

@ -7,6 +7,7 @@ import (
"math"
"github.com/NyaaPantsu/nyaa/controllers/router"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/templates"
"github.com/NyaaPantsu/nyaa/utils/search"
@ -21,7 +22,7 @@ func SearchHandler(c *gin.Context) {
// TODO Fallback to postgres search if es is down
page := c.Param("page")
currentUser := router.GetUser(c)
// db params url
pagenum := 1
if page != "" {
@ -36,7 +37,12 @@ func SearchHandler(c *gin.Context) {
}
}
searchParam, torrents, nbTorrents, err := search.ByQuery(c, pagenum)
userID, err := strconv.ParseUint(c.Query("userID"), 10, 32)
if err != nil {
userID = 0
}
searchParam, torrents, nbTorrents, err := search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrAdmin(uint(userID)))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return

Voir le fichier

@ -16,7 +16,6 @@ import (
"github.com/NyaaPantsu/nyaa/utils/email"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/utils/search"
"github.com/NyaaPantsu/nyaa/utils/validator"
"github.com/NyaaPantsu/nyaa/utils/validator/user"
"github.com/gin-gonic/gin"
@ -49,20 +48,7 @@ func UserProfileHandler(c *gin.Context) {
messages.AddInfof("infos", Ts("user_unfollowed_msg"), userProfile.Username)
}
userProfile.ParseSettings()
query := c.Request.URL.Query()
query.Set("userID", strconv.Itoa(int(id)))
query.Set("limit", "20")
c.Request.URL.RawQuery = query.Encode()
var err error
_, userProfile.Torrents, _, err = search.ByQuery(c, 1)
if currentUser.CurrentOrAdmin(userProfile.ID) {
userProfile.Splice(1, 20)
} else {
userProfile.Splice(1, 20).Filter()
}
if err != nil {
messages.AddErrorT("errors", "retrieve_torrents_error")
}
templates.UserProfile(c, userProfile)
}
} else {

Voir le fichier

@ -13,7 +13,7 @@
<p class="profile-usertitle-job">
{{UserProfile.GetRole()}}
</p>
<p class="profile-usertitle-uploadcount">{{ T("torrents_uploaded") }}:<span>{{ len(UserProfile.Torrents) }}</span></p>
<p class="profile-usertitle-uploadcount">{{ T("torrents_uploaded") }}:<span>{{ NbTorrents }}</span></p>
</div>
<!-- END SIDEBAR USER TITLE -->
<!-- SIDEBAR BUTTONS -->

Voir le fichier

@ -3,12 +3,14 @@ package templates
import (
"net/http"
"path"
"strconv"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/utils/filelist"
"github.com/NyaaPantsu/nyaa/utils/messages"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/utils/search"
"github.com/gin-gonic/gin"
"github.com/justinas/nosurf"
@ -44,7 +46,7 @@ func init() {
// Commonvariables return a jet.VarMap variable containing the necessary variables to run index layouts
func Commonvariables(c *gin.Context) jet.VarMap {
token := nosurf.Token(c.Request)
msg := messages.GetMessages(c)
messages := msg.GetMessages(c)
user, _, _ := cookies.CurrentUser(c)
variables := templateFunctions(make(jet.VarMap))
variables.Set("Navigation", NewNavigation())
@ -57,8 +59,8 @@ func Commonvariables(c *gin.Context) jet.VarMap {
variables.Set("URL", c.Request.URL)
variables.Set("CsrfToken", token)
variables.Set("Config", config.Get())
variables.Set("Infos", msg.GetAllInfos())
variables.Set("Errors", msg.GetAllErrors())
variables.Set("Infos", messages.GetAllInfos())
variables.Set("Errors", messages.GetAllErrors())
return variables
}
@ -151,30 +153,44 @@ func Torrent(c *gin.Context, torrent models.TorrentJSON, rootFolder *filelist.Fi
variables.Set("Torrent", torrent)
variables.Set("RootFolder", rootFolder)
variables.Set("CaptchaID", captchaID)
Render(c, path.Join(SiteDir, "torrents/view.jet.html"), variables)
Render(c, path.Join(SiteDir, "torrents", "view.jet.html"), variables)
}
// userProfilBase render the base for user profile
func userProfileBase(c *gin.Context, templateName string, userProfile *models.User, variables jet.VarMap) {
currentUser, _, _ := cookies.CurrentUser(c)
query := c.Request.URL.Query()
query.Set("userID", strconv.Itoa(int(userProfile.ID)))
query.Set("limit", "20")
c.Request.URL.RawQuery = query.Encode()
nbTorrents := 0
if currentUser.CurrentOrAdmin(userProfile.ID) {
_, userProfile.Torrents, nbTorrents, _ = search.ByQuery(c, 1, true, true, false, false)
} else {
_, userProfile.Torrents, nbTorrents, _ = search.ByQuery(c, 1, true, true, false, true)
}
variables.Set("UserProfile", userProfile)
variables.Set("NbTorrents", nbTorrents)
Render(c, path.Join(SiteDir, "user", templateName), variables)
}
// UserProfileEdit render a form to edit a profile
func UserProfileEdit(c *gin.Context, userProfile *models.User, userForm userValidator.UserForm, languages publicSettings.Languages) {
variables := Commonvariables(c)
variables.Set("UserProfile", userProfile)
variables.Set("UserForm", userForm)
variables.Set("Languages", languages)
Render(c, path.Join(SiteDir, "user/edit.jet.html"), variables)
userProfileBase(c, "edit.jet.html", userProfile, variables)
}
// UserProfile render a user profile
func UserProfile(c *gin.Context, userProfile *models.User) {
variables := Commonvariables(c)
variables.Set("UserProfile", userProfile)
Render(c, path.Join(SiteDir, "user/torrents.jet.html"), variables)
userProfileBase(c, "torrents.jet.html", userProfile, Commonvariables(c))
}
// UserProfileNotifications render a user profile notifications
func UserProfileNotifications(c *gin.Context, userProfile *models.User) {
variables := Commonvariables(c)
variables.Set("UserProfile", userProfile)
Render(c, path.Join(SiteDir, "user/notifications.jet.html"), variables)
userProfileBase(c, "notifications.jet.html", userProfile, Commonvariables(c))
}
// DatabaseDump render the list of database dumps template
@ -182,7 +198,7 @@ func DatabaseDump(c *gin.Context, listDumps []models.DatabaseDumpJSON, GPGLink s
variables := Commonvariables(c)
variables.Set("ListDumps", listDumps)
variables.Set("GPGLink", GPGLink)
Render(c, path.Join(SiteDir, "database/dumps.jet.html"), variables)
Render(c, path.Join(SiteDir, "database", "dumps.jet.html"), variables)
}
// PanelAdmin render the panel admin template index

Voir le fichier

@ -71,15 +71,25 @@ func walkDirTest(dir string, t *testing.T) {
return variables
},
"edit.jet.html": func(variables jet.VarMap) jet.VarMap {
variables.Set("NbTorrents", 0)
variables.Set("Form", fakeTorrentRequest)
variables.Set("Languages", publicSettings.Languages{*fakeLanguage, *fakeLanguage})
return variables
},
"torrents.jet.html": func(variables jet.VarMap) jet.VarMap {
variables.Set("NbTorrents", 0)
return variables
},
"profile.jet.html": func(variables jet.VarMap) jet.VarMap {
variables.Set("NbTorrents", 0)
return variables
},
"upload.jet.html": func(variables jet.VarMap) jet.VarMap {
variables.Set("Form", fakeTorrentRequest)
return variables
},
"view.jet.html": func(variables jet.VarMap) jet.VarMap {
variables.Set("NbTorrents", 0)
variables.Set("Torrent", fakeTorrent.ToJSON())
variables.Set("CaptchaID", "xxxxxx")
variables.Set("RootFolder", filelist.FileListToFolder(fakeTorrent.FileList, "root"))
@ -128,6 +138,10 @@ func walkDirTest(dir string, t *testing.T) {
variables.Set("Models", []models.TorrentReportJSON{fakeReport.ToJSON(), fakeReport.ToJSON()})
return variables
},
"notifications.jet.html": func(variables jet.VarMap) jet.VarMap {
variables.Set("NbTorrents", 0)
return variables
},
"report.jet.html": func(variables jet.VarMap) jet.VarMap {
type form struct {
ID int

Voir le fichier

@ -44,42 +44,42 @@ func stringIsASCII(input string) bool {
return true
}
// ByQuery : search torrents according to request without user
func ByQuery(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = byQuery(c, pagenum, true, false, false, false)
// ByQueryNoUser : search torrents according to request without user
func ByQueryNoUser(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = ByQuery(c, pagenum, true, false, false, false)
return
}
// ByQueryWithUser : search torrents according to request with user
func ByQueryWithUser(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = byQuery(c, pagenum, true, true, false, false)
search, tor, count, err = ByQuery(c, pagenum, true, true, false, false)
return
}
// ByQueryNoCount : search torrents according to request without user and count
func ByQueryNoCount(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, err error) {
search, tor, _, err = byQuery(c, pagenum, false, false, false, false)
search, tor, _, err = ByQuery(c, pagenum, false, false, false, false)
return
}
// ByQueryDeleted : search deleted torrents according to request with user and count
func ByQueryDeleted(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = byQuery(c, pagenum, true, true, true, false)
search, tor, count, err = ByQuery(c, pagenum, true, true, true, false)
return
}
// ByQueryNoHidden : search torrents and filter those hidden
func ByQueryNoHidden(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = byQuery(c, pagenum, true, false, false, true)
search, tor, count, err = ByQuery(c, pagenum, true, false, false, true)
return
}
// TODO Clean this up
// FIXME Some fields are not used by elasticsearch (pagenum, countAll, deleted, withUser)
// pagenum is extracted from request in .FromRequest()
// Some fields are postgres specific (countAll, withUser)
// elasticsearch always provide a count to how many hits
// ES doesn't store users
// deleted is unused because es doesn't index deleted torrents
func byQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted bool, hidden bool) (structs.TorrentParam, []models.Torrent, int, error) {
func ByQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted bool, hidden bool) (structs.TorrentParam, []models.Torrent, int, error) {
var err error
if models.ElasticSearchClient != nil && !deleted {
var torrentParam structs.TorrentParam
@ -170,10 +170,10 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
if search.UserID != 0 {
conditions = append(conditions, "uploader = ?")
parameters.Params = append(parameters.Params, search.UserID)
}
if search.Hidden {
conditions = append(conditions, "hidden = ?")
parameters.Params = append(parameters.Params, false)
if search.Hidden {
conditions = append(conditions, "hidden = ?")
parameters.Params = append(parameters.Params, false)
}
}
if search.FromID != 0 {
conditions = append(conditions, "torrent_id > ?")
@ -237,7 +237,7 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
tor, count, err = torrents.FindDeleted(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
} else if countAll && !withUser {
tor, count, err = torrents.FindOrderBy(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
} else if withUser {
} else if countAll && withUser {
tor, count, err = torrents.FindWithUserOrderBy(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
} else {
tor, err = torrents.FindOrderByNoCount(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
@ -245,3 +245,11 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
cache.C.Set(search.Identifier(), &structs.TorrentCache{tor, count}, 5*time.Minute)
return
}
// AuthorizedQuery return a seach byquery according to the bool. If false, it doesn't look for hidden torrents, else it looks for every torrents
func AuthorizedQuery(c *gin.Context, pagenum int, authorized bool) (structs.TorrentParam, []models.Torrent, int, error) {
if !authorized {
return ByQuery(c, pagenum, true, true, false, true)
}
return ByQuery(c, pagenum, true, true, false, false)
}