Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Remove common package

Common is no more a thing
Use of TorrentParam instead of SearchParam now
Common structs for search are exported in utils/search/structs
Util has been renamed utils
Cette révision appartient à :
akuma06 2017-07-02 16:54:55 +02:00
Parent 188c196fd3
révision 97b3a1d7ea
83 fichiers modifiés avec 193 ajouts et 329 suppressions

Voir le fichier

@ -1,8 +0,0 @@
package common
type CommentParam struct {
UserID uint32
CommentID uint32
Limit uint32
Offset uint32
}

Voir le fichier

@ -1,17 +0,0 @@
package common
import (
"errors"
)
var ErrInsufficientPermission = errors.New("you are not allowed to do that")
var ErrUserExists = errors.New("user already exists")
var ErrNoSuchUser = errors.New("no such user")
var ErrBadLogin = errors.New("bad login")
var ErrUserBanned = errors.New("banned")
var ErrBadEmail = errors.New("bad email")
var ErrNoSuchEntry = errors.New("no such entry")
var ErrNoSuchComment = errors.New("no such comment")
var ErrNotFollowing = errors.New("not following that user")
var ErrInvalidToken = errors.New("invalid token")
var ErrExpiredToken = errors.New("token is expired")

Voir le fichier

@ -1,15 +0,0 @@
package common
import (
"time"
)
type ReportParam struct {
Limit uint32
Offset uint32
AllTime bool
ID uint32
TorrentID uint32
Before time.Time
After time.Time
}

Voir le fichier

@ -1,14 +0,0 @@
package common
import (
"time"
)
type ScrapeResult struct {
Hash string
TorrentID uint32
Seeders uint32
Leechers uint32
Completed uint32
Date time.Time
}

Voir le fichier

@ -1,11 +0,0 @@
package common
type UserParam struct {
Full bool // if true populate Uploads, UsersWeLiked and UsersLikingMe
Email string
Name string
APIToken string
ID uint32
Max uint32
Offset uint32
}

Voir le fichier

@ -8,8 +8,8 @@ import (
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/activities" "github.com/NyaaPantsu/nyaa/models/activities"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -12,12 +12,12 @@ import (
"github.com/NyaaPantsu/nyaa/models/torrents" "github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/service" "github.com/NyaaPantsu/nyaa/service"
"github.com/NyaaPantsu/nyaa/service/api" "github.com/NyaaPantsu/nyaa/service/api"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/crypto" "github.com/NyaaPantsu/nyaa/utils/crypto"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/search" "github.com/NyaaPantsu/nyaa/utils/search"
"github.com/NyaaPantsu/nyaa/util/upload" "github.com/NyaaPantsu/nyaa/utils/upload"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -7,8 +7,8 @@ import (
"time" "time"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/util/metainfo" "github.com/NyaaPantsu/nyaa/utils/metainfo"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -3,7 +3,7 @@ package controllers
import ( import (
"github.com/NyaaPantsu/nyaa/common" "github.com/NyaaPantsu/nyaa/common"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -3,7 +3,7 @@ package controllers
import ( import (
"net/http" "net/http"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -13,11 +13,11 @@ import (
"github.com/NyaaPantsu/nyaa/models/comments" "github.com/NyaaPantsu/nyaa/models/comments"
"github.com/NyaaPantsu/nyaa/models/reports" "github.com/NyaaPantsu/nyaa/models/reports"
"github.com/NyaaPantsu/nyaa/models/torrents" "github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/util/categories" "github.com/NyaaPantsu/nyaa/utils/categories"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/search" "github.com/NyaaPantsu/nyaa/utils/search"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -388,7 +388,7 @@ func TorrentsPostListPanel(c *gin.Context) {
*/ */
func APIMassMod(c *gin.Context) { func APIMassMod(c *gin.Context) {
torrentManyAction(c) torrentManyAction(c)
messages := msg.GetMessages(c) // new util for errors and infos messages := msg.GetMessages(c) // new utils for errors and infos
c.Header("Content-Type", "application/json") c.Header("Content-Type", "application/json")
var mapOk map[string]interface{} var mapOk map[string]interface{}
@ -404,7 +404,7 @@ func APIMassMod(c *gin.Context) {
// DeletedTorrentsModPanel : Controller for viewing deleted torrents, accept common search arguments // DeletedTorrentsModPanel : Controller for viewing deleted torrents, accept common search arguments
func DeletedTorrentsModPanel(c *gin.Context) { func DeletedTorrentsModPanel(c *gin.Context) {
page := c.Param("page") page := c.Param("page")
messages := msg.GetMessages(c) // new util for errors and infos messages := msg.GetMessages(c) // new utils for errors and infos
deleted := c.Request.URL.Query()["deleted"] deleted := c.Request.URL.Query()["deleted"]
unblocked := c.Request.URL.Query()["unblocked"] unblocked := c.Request.URL.Query()["unblocked"]
blocked := c.Request.URL.Query()["blocked"] blocked := c.Request.URL.Query()["blocked"]
@ -487,7 +487,7 @@ func torrentManyAction(c *gin.Context) {
owner, _ := strconv.Atoi(c.PostForm("owner")) owner, _ := strconv.Atoi(c.PostForm("owner"))
category := c.PostForm("category") category := c.PostForm("category")
withReport, _ := strconv.ParseBool(c.DefaultPostForm("withreport", "false")) withReport, _ := strconv.ParseBool(c.DefaultPostForm("withreport", "false"))
messages := msg.GetMessages(c) // new util for errors and infos messages := msg.GetMessages(c) // new utils for errors and infos
catID, subCatID := -1, -1 catID, subCatID := -1, -1
var err error var err error

Voir le fichier

@ -5,10 +5,10 @@ import (
"net/url" "net/url"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/util/timeHelper" "github.com/NyaaPantsu/nyaa/utils/timeHelper"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -3,7 +3,7 @@ package controllers
import ( import (
"net/http" "net/http"
"github.com/NyaaPantsu/nyaa/util/captcha" "github.com/NyaaPantsu/nyaa/utils/captcha"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/justinas/nosurf" "github.com/justinas/nosurf"
) )

Voir le fichier

@ -12,11 +12,11 @@ import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/categories" "github.com/NyaaPantsu/nyaa/utils/categories"
userService "github.com/NyaaPantsu/nyaa/util/cookies" userService "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/feeds" "github.com/NyaaPantsu/nyaa/utils/feeds"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/util/search" "github.com/NyaaPantsu/nyaa/utils/search"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/feeds" "github.com/gorilla/feeds"
) )

Voir le fichier

@ -6,8 +6,8 @@ import (
"strconv" "strconv"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/util/search" "github.com/NyaaPantsu/nyaa/utils/search"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -6,10 +6,10 @@ import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
userForms "github.com/NyaaPantsu/nyaa/util/cookies" userForms "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/filelist" "github.com/NyaaPantsu/nyaa/utils/filelist"
"github.com/NyaaPantsu/nyaa/util/messages" "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/justinas/nosurf" "github.com/justinas/nosurf"

Voir le fichier

@ -13,12 +13,12 @@ import (
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/activities" "github.com/NyaaPantsu/nyaa/models/activities"
"github.com/NyaaPantsu/nyaa/models/torrents" "github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/util" "github.com/NyaaPantsu/nyaa/utils"
"github.com/NyaaPantsu/nyaa/util/categories" "github.com/NyaaPantsu/nyaa/utils/categories"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/filelist" "github.com/NyaaPantsu/nyaa/utils/filelist"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/util/torrentLanguages" "github.com/NyaaPantsu/nyaa/utils/torrentLanguages"
) )
type captchaData struct { type captchaData struct {

Voir le fichier

@ -16,7 +16,7 @@ import (
"github.com/NyaaPantsu/nyaa/model" "github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/service/api" "github.com/NyaaPantsu/nyaa/service/api"
userForm "github.com/NyaaPantsu/nyaa/service/user/form" userForm "github.com/NyaaPantsu/nyaa/service/user/form"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -9,12 +9,12 @@ import (
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents" "github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/service/api" "github.com/NyaaPantsu/nyaa/service/api"
"github.com/NyaaPantsu/nyaa/util/captcha" "github.com/NyaaPantsu/nyaa/utils/captcha"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/util/upload" "github.com/NyaaPantsu/nyaa/utils/upload"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -38,7 +38,7 @@ func UploadHandler(c *gin.Context) {
func UploadPostHandler(c *gin.Context) { func UploadPostHandler(c *gin.Context) {
var uploadForm apiService.TorrentRequest var uploadForm apiService.TorrentRequest
user := getUser(c) user := getUser(c)
messages := msg.GetMessages(c) // new util for errors and infos messages := msg.GetMessages(c) // new utils for errors and infos
if userPermission.NeedsCaptcha(user) { if userPermission.NeedsCaptcha(user) {
userCaptcha := captcha.Extract(c) userCaptcha := captcha.Extract(c)

Voir le fichier

@ -8,12 +8,12 @@ import (
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/notifications" "github.com/NyaaPantsu/nyaa/models/notifications"
"github.com/NyaaPantsu/nyaa/util/captcha" "github.com/NyaaPantsu/nyaa/utils/captcha"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/crypto" "github.com/NyaaPantsu/nyaa/utils/crypto"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/util/search" "github.com/NyaaPantsu/nyaa/utils/search"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -18,12 +18,12 @@ import (
"github.com/NyaaPantsu/nyaa/models/reports" "github.com/NyaaPantsu/nyaa/models/reports"
"github.com/NyaaPantsu/nyaa/models/torrents" "github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/service/api" "github.com/NyaaPantsu/nyaa/service/api"
"github.com/NyaaPantsu/nyaa/util" "github.com/NyaaPantsu/nyaa/utils"
"github.com/NyaaPantsu/nyaa/util/captcha" "github.com/NyaaPantsu/nyaa/utils/captcha"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/filelist" "github.com/NyaaPantsu/nyaa/utils/filelist"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

10
main.go
Voir le fichier

@ -11,11 +11,11 @@ import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/controllers" "github.com/NyaaPantsu/nyaa/controllers"
"github.com/NyaaPantsu/nyaa/util/cookies" "github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/util/search" "github.com/NyaaPantsu/nyaa/utils/search"
"github.com/NyaaPantsu/nyaa/util/signals" "github.com/NyaaPantsu/nyaa/utils/signals"
) )
var buildversion string var buildversion string

Voir le fichier

@ -4,7 +4,7 @@ import (
"html/template" "html/template"
"time" "time"
"github.com/NyaaPantsu/nyaa/util" "github.com/NyaaPantsu/nyaa/utils/format"
) )
// DatabaseDump model // DatabaseDump model
@ -28,7 +28,7 @@ type DatabaseDumpJSON struct {
func (dump *DatabaseDump) ToJSON() DatabaseDumpJSON { func (dump *DatabaseDump) ToJSON() DatabaseDumpJSON {
json := DatabaseDumpJSON{ json := DatabaseDumpJSON{
Date: dump.Date.Format(time.RFC3339), Date: dump.Date.Format(time.RFC3339),
Filesize: util.FormatFilesize(dump.Filesize), Filesize: format.FileSize(dump.Filesize),
Name: dump.Name, Name: dump.Name,
TorrentLink: template.URL(dump.TorrentLink), TorrentLink: template.URL(dump.TorrentLink),
} }

Voir le fichier

@ -2,7 +2,7 @@ package models
import ( import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/azhao12345/gorm" "github.com/azhao12345/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres" // Need for postgres support _ "github.com/jinzhu/gorm/dialects/postgres" // Need for postgres support
_ "github.com/jinzhu/gorm/dialects/sqlite" // Need for sqlite _ "github.com/jinzhu/gorm/dialects/sqlite" // Need for sqlite

Voir le fichier

@ -17,8 +17,9 @@ import (
"net/url" "net/url"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util" "github.com/NyaaPantsu/nyaa/utils/format"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/sanitize"
"github.com/bradfitz/slice" "github.com/bradfitz/slice"
) )
@ -256,14 +257,14 @@ func (t *Torrent) ToJSON() TorrentJSON {
} else { } else {
trackers = t.GetTrackersArray() trackers = t.GetTrackersArray()
} }
magnet := util.InfoHashToMagnet(strings.TrimSpace(t.Hash), t.Name, trackers...) magnet := format.InfoHashToMagnet(strings.TrimSpace(t.Hash), t.Name, trackers...)
commentsJSON := make([]CommentJSON, 0, len(t.OldComments)+len(t.Comments)) commentsJSON := make([]CommentJSON, 0, len(t.OldComments)+len(t.Comments))
for _, c := range t.OldComments { for _, c := range t.OldComments {
commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, UserID: -1, Content: template.HTML(c.Content), Date: c.Date.UTC()}) commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, UserID: -1, Content: template.HTML(c.Content), Date: c.Date.UTC()})
} }
for _, c := range t.Comments { for _, c := range t.Comments {
if c.User != nil { if c.User != nil {
commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), Content: util.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5}) commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5})
} else { } else {
commentsJSON = append(commentsJSON, CommentJSON{}) commentsJSON = append(commentsJSON, CommentJSON{})
} }
@ -317,17 +318,17 @@ func (t *Torrent) ToJSON() TorrentJSON {
Hash: t.Hash, Hash: t.Hash,
Date: t.Date.Format(time.RFC3339), Date: t.Date.Format(time.RFC3339),
Filesize: t.Filesize, Filesize: t.Filesize,
Description: util.MarkdownToHTML(t.Description), Description: sanitize.MarkdownToHTML(t.Description),
Comments: commentsJSON, Comments: commentsJSON,
SubCategory: strconv.Itoa(t.SubCategory), SubCategory: strconv.Itoa(t.SubCategory),
Category: strconv.Itoa(t.Category), Category: strconv.Itoa(t.Category),
Downloads: t.Downloads, Downloads: t.Downloads,
UploaderID: uploaderID, UploaderID: uploaderID,
UploaderName: util.SafeText(uploader), UploaderName: sanitize.SafeText(uploader),
WebsiteLink: util.Safe(t.WebsiteLink), WebsiteLink: sanitize.Safe(t.WebsiteLink),
Language: t.Language, Language: t.Language,
Magnet: template.URL(magnet), Magnet: template.URL(magnet),
TorrentLink: util.Safe(torrentlink), TorrentLink: sanitize.Safe(torrentlink),
Leechers: scrape.Leechers, Leechers: scrape.Leechers,
Seeders: scrape.Seeders, Seeders: scrape.Seeders,
Completed: scrape.Completed, Completed: scrape.Completed,

Voir le fichier

@ -2,7 +2,7 @@ package torrents
import ( import (
"errors" "errors"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"net/http" "net/http"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"

Voir le fichier

@ -9,7 +9,7 @@ import (
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/activities" "github.com/NyaaPantsu/nyaa/models/activities"
"github.com/NyaaPantsu/nyaa/models/notifications" "github.com/NyaaPantsu/nyaa/models/notifications"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
) )
// ExistOrDelete : Check if a torrent exist with the same hash and if it can be replaced, it is replaced // ExistOrDelete : Check if a torrent exist with the same hash and if it can be replaced, it is replaced

Voir le fichier

@ -8,7 +8,7 @@ import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/service" "github.com/NyaaPantsu/nyaa/utils/search/structs"
) )
/* Function to interact with Models /* Function to interact with Models
@ -79,24 +79,24 @@ func FindRawByHash(hash string) (torrent models.Torrent, err error) {
} }
// FindOrderByNoCount : Get torrents based on search without counting and user // FindOrderByNoCount : Get torrents based on search without counting and user
func FindOrderByNoCount(parameters *serviceBase.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, err error) { func FindOrderByNoCount(parameters *structs.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, err error) {
torrents, _, err = findOrderBy(parameters, orderBy, limit, offset, false, false, false) torrents, _, err = findOrderBy(parameters, orderBy, limit, offset, false, false, false)
return return
} }
// FindOrderBy : Get torrents based on search without user // FindOrderBy : Get torrents based on search without user
func FindOrderBy(parameters *serviceBase.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, count int, err error) { func FindOrderBy(parameters *structs.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, count int, err error) {
torrents, count, err = findOrderBy(parameters, orderBy, limit, offset, true, false, false) torrents, count, err = findOrderBy(parameters, orderBy, limit, offset, true, false, false)
return return
} }
// FindWithUserOrderBy : Get torrents based on search with user // FindWithUserOrderBy : Get torrents based on search with user
func FindWithUserOrderBy(parameters *serviceBase.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, count int, err error) { func FindWithUserOrderBy(parameters *structs.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, count int, err error) {
torrents, count, err = findOrderBy(parameters, orderBy, limit, offset, true, true, false) torrents, count, err = findOrderBy(parameters, orderBy, limit, offset, true, true, false)
return return
} }
func findOrderBy(parameters *serviceBase.WhereParams, orderBy string, limit int, offset int, countAll bool, withUser bool, deleted bool) ( func findOrderBy(parameters *structs.WhereParams, orderBy string, limit int, offset int, countAll bool, withUser bool, deleted bool) (
torrents []models.Torrent, count int, err error, torrents []models.Torrent, count int, err error,
) { ) {
var conditionArray []string var conditionArray []string
@ -150,12 +150,12 @@ func findOrderBy(parameters *serviceBase.WhereParams, orderBy string, limit int,
// database. The list will be of length 'limit' and in default order. // database. The list will be of length 'limit' and in default order.
// GetTorrents returns the first records found. Later records may be retrieved // GetTorrents returns the first records found. Later records may be retrieved
// by providing a positive 'offset' // by providing a positive 'offset'
func Find(parameters serviceBase.WhereParams, limit int, offset int) ([]models.Torrent, int, error) { func Find(parameters structs.WhereParams, limit int, offset int) ([]models.Torrent, int, error) {
return FindOrderBy(&parameters, "", limit, offset) return FindOrderBy(&parameters, "", limit, offset)
} }
// FindDB : Get Torrents with where parameters but no limit and order by default (get all the torrents corresponding in the db) // FindDB : Get Torrents with where parameters but no limit and order by default (get all the torrents corresponding in the db)
func FindDB(parameters serviceBase.WhereParams) ([]models.Torrent, int, error) { func FindDB(parameters structs.WhereParams) ([]models.Torrent, int, error) {
return FindOrderBy(&parameters, "", 0, 0) return FindOrderBy(&parameters, "", 0, 0)
} }
@ -192,7 +192,7 @@ func ToggleBlock(id uint) (models.Torrent, int, error) {
} }
// FindDeleted : Gets deleted torrents based on search params // FindDeleted : Gets deleted torrents based on search params
func FindDeleted(parameters *serviceBase.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, count int, err error) { func FindDeleted(parameters *structs.WhereParams, orderBy string, limit int, offset int) (torrents []models.Torrent, count int, err error) {
torrents, count, err = findOrderBy(parameters, orderBy, limit, offset, true, true, true) torrents, count, err = findOrderBy(parameters, orderBy, limit, offset, true, true, true)
return return
} }

Voir le fichier

@ -3,7 +3,7 @@ package models
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"time" "time"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"

Voir le fichier

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/crypto" "github.com/NyaaPantsu/nyaa/utils/crypto"
"github.com/dorajistyle/goyangi/util/modelHelper" "github.com/dorajistyle/goyangi/util/modelHelper"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"

Voir le fichier

@ -8,7 +8,7 @@ import (
"strconv" "strconv"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/validator/user" "github.com/NyaaPantsu/nyaa/utils/validator/user"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )

Voir le fichier

@ -4,10 +4,10 @@ import (
"errors" "errors"
"net/http" "net/http"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/validator" "github.com/NyaaPantsu/nyaa/utils/validator"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/context" "github.com/gorilla/context"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"

Voir le fichier

@ -5,7 +5,7 @@ import (
"net" "net"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/majestrate/i2p-tools/lib/i2p" "github.com/majestrate/i2p-tools/lib/i2p"
) )

Voir le fichier

@ -4,7 +4,7 @@ import (
"path/filepath" "path/filepath"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
gomail "gopkg.in/gomail.v2" gomail "gopkg.in/gomail.v2"
) )

Voir le fichier

@ -10,9 +10,9 @@ import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/db" "github.com/NyaaPantsu/nyaa/db"
"github.com/NyaaPantsu/nyaa/model" "github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/util" "github.com/NyaaPantsu/nyaa/utils"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/util/timeHelper" "github.com/NyaaPantsu/nyaa/utils/timeHelper"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/securecookie" "github.com/gorilla/securecookie"
"github.com/NyaaPantsu/nyaa/models/users" "github.com/NyaaPantsu/nyaa/models/users"

Voir le fichier

@ -4,7 +4,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/NyaaPantsu/nyaa/util/categories" "github.com/NyaaPantsu/nyaa/utils/categories"
) )
// ConvertToCat : Convert a torznab cat to our cat // ConvertToCat : Convert a torznab cat to our cat

Voir le fichier

Voir le fichier

Voir le fichier

Voir le fichier

@ -4,7 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/context" "github.com/gorilla/context"
"github.com/nicksnyder/go-i18n/i18n" "github.com/nicksnyder/go-i18n/i18n"

Voir le fichier

@ -3,16 +3,14 @@ package search
import ( import (
"strconv" "strconv"
"strings" "strings"
"time"
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"github.com/NyaaPantsu/nyaa/common"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents" "github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/service" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/search/structs"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -23,7 +21,7 @@ var useTSQuery bool
func Configure(conf *config.SearchConfig) (err error) { func Configure(conf *config.SearchConfig) (err error) {
useTSQuery = false useTSQuery = false
// Postgres needs ILIKE for case-insensitivity // Postgres needs ILIKE for case-insensitivity
if db.ORM.Dialect().GetName() == "postgres" { if models.ORM.Dialect().GetName() == "postgres" {
searchOperator = "ILIKE ?" searchOperator = "ILIKE ?"
//useTSQuery = true //useTSQuery = true
// !!DISABLED!! because this makes search a lot stricter // !!DISABLED!! because this makes search a lot stricter
@ -44,31 +42,31 @@ func stringIsASCII(input string) bool {
} }
// SearchByQuery : search torrents according to request without user // SearchByQuery : search torrents according to request without user
func SearchByQuery(c *gin.Context, pagenum int) (search common.SearchParam, tor []models.Torrent, count int, err error) { func SearchByQuery(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = searchByQuery(c, pagenum, true, false, false, false) search, tor, count, err = searchByQuery(c, pagenum, true, false, false, false)
return return
} }
// SearchByQueryWithUser : search torrents according to request with user // SearchByQueryWithUser : search torrents according to request with user
func SearchByQueryWithUser(c *gin.Context, pagenum int) (search common.SearchParam, tor []models.Torrent, count int, err error) { func SearchByQueryWithUser(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = searchByQuery(c, pagenum, true, true, false, false) search, tor, count, err = searchByQuery(c, pagenum, true, true, false, false)
return return
} }
// SearchByQueryNoCount : search torrents according to request without user and count // SearchByQueryNoCount : search torrents according to request without user and count
func SearchByQueryNoCount(c *gin.Context, pagenum int) (search common.SearchParam, tor []models.Torrent, err error) { func SearchByQueryNoCount(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, err error) {
search, tor, _, err = searchByQuery(c, pagenum, false, false, false, false) search, tor, _, err = searchByQuery(c, pagenum, false, false, false, false)
return return
} }
// SearchByQueryDeleted : search deleted torrents according to request with user and count // SearchByQueryDeleted : search deleted torrents according to request with user and count
func SearchByQueryDeleted(c *gin.Context, pagenum int) (search common.SearchParam, tor []models.Torrent, count int, err error) { func SearchByQueryDeleted(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = searchByQuery(c, pagenum, true, true, true, false) search, tor, count, err = searchByQuery(c, pagenum, true, true, true, false)
return return
} }
// SearchByQueryNoHidden : search torrents and filter those hidden // SearchByQueryNoHidden : search torrents and filter those hidden
func SearchByQueryNoHidden(c *gin.Context, pagenum int) (search common.SearchParam, tor []models.Torrent, count int, err error) { func SearchByQueryNoHidden(c *gin.Context, pagenum int) (search structs.TorrentParam, tor []models.Torrent, count int, err error) {
search, tor, count, err = searchByQuery(c, pagenum, true, false, false, true) search, tor, count, err = searchByQuery(c, pagenum, true, false, false, true)
return return
} }
@ -79,35 +77,16 @@ func SearchByQueryNoHidden(c *gin.Context, pagenum int) (search common.SearchPar
// elasticsearch always provide a count to how many hits // elasticsearch always provide a count to how many hits
// deleted is unused because es doesn't index deleted torrents // deleted is unused because es doesn't index deleted torrents
func searchByQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted bool, hidden bool) ( func searchByQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted bool, hidden bool) (
search common.SearchParam, tor []models.Torrent, count int, err error, search structs.TorrentParam, tor []models.Torrent, count int, err error,
) { ) {
if db.ElasticSearchClient != nil { if models.ElasticSearchClient != nil {
var torrentParam common.TorrentParam var torrentParam structs.TorrentParam
torrentParam.FromRequest(c) torrentParam.FromRequest(c)
torrentParam.Offset = uint32(pagenum) torrentParam.Offset = uint32(pagenum)
torrentParam.Hidden = hidden torrentParam.Hidden = hidden
totalHits, torrents, err := torrentParam.Find(db.ElasticSearchClient) totalHits, torrents, err := torrentParam.Find(models.ElasticSearchClient)
searchParam := common.SearchParam{
TorrentID: uint(torrentParam.TorrentID),
FromID: uint(torrentParam.FromID),
FromDate: torrentParam.FromDate,
ToDate: torrentParam.ToDate,
Order: torrentParam.Order,
Hidden: torrentParam.Hidden,
Status: torrentParam.Status,
Sort: torrentParam.Sort,
Category: torrentParam.Category,
Page: int(torrentParam.Offset),
UserID: uint(torrentParam.UserID),
Max: uint(torrentParam.Max),
NotNull: torrentParam.NotNull,
Language: torrentParam.Language,
MinSize: torrentParam.MinSize,
MaxSize: torrentParam.MaxSize,
Query: torrentParam.NameLike,
}
// Convert back to non-json torrents // Convert back to non-json torrents
return searchParam, torrents, int(totalHits), err return torrentParam, torrents, int(totalHits), err
} }
log.Errorf("Unable to create elasticsearch client: %s", err) log.Errorf("Unable to create elasticsearch client: %s", err)
log.Errorf("Falling back to postgresql query") log.Errorf("Falling back to postgresql query")
@ -115,64 +94,34 @@ func searchByQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, de
} }
func searchByQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted bool, hidden bool) ( func searchByQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted bool, hidden bool) (
search common.SearchParam, tor []models.Torrent, count int, err error, search structs.TorrentParam, tor []models.Torrent, count int, err error,
) { ) {
max, err := strconv.ParseUint(c.DefaultQuery("limit", "50"), 10, 32) search.FromRequest(c)
if err != nil {
max = 50 // default Value maxPerPage
} else if max > 300 {
max = 300
}
search.Max = uint(max)
search.Page = pagenum search.Offset = uint32(pagenum)
search.Hidden = hidden search.Hidden = hidden
search.Query = c.Query("q")
search.Language = c.Query("lang")
userID, _ := strconv.Atoi(c.Query("userID"))
search.UserID = uint(userID)
fromID, _ := strconv.Atoi(c.Query("fromID"))
search.FromID = uint(fromID)
maxage, err := strconv.Atoi(c.Query("maxage"))
if err != nil {
if c.Query("toDate") != "" {
search.FromDate.Parse(c.Query("toDate"), c.Query("dateType"))
search.ToDate.Parse(c.Query("fromDate"), c.Query("dateType"))
} else {
search.FromDate.Parse(c.Query("fromDate"), c.Query("dateType"))
}
} else {
search.FromDate = common.DateFilter(time.Now().AddDate(0, 0, -maxage).Format("2006-01-02"))
}
search.Category = common.ParseCategories(c.Query("c"))
search.Status.Parse(c.Query("s"))
search.Sort.Parse(c.Query("sort"))
search.MinSize.Parse(c.Query("minSize"), c.Query("sizeType"))
search.MaxSize.Parse(c.Query("maxSize"), c.Query("sizeType"))
orderBy := search.Sort.ToDBField() orderBy := search.Sort.ToDBField()
if search.Sort == common.Date { if search.Sort == structs.Date {
search.NotNull = search.Sort.ToDBField() + " IS NOT NULL" search.NotNull = search.Sort.ToDBField() + " IS NOT NULL"
} }
orderBy += " " orderBy += " "
switch s := c.Query("order"); s { switch search.Order {
case "true": case true:
search.Order = true
orderBy += "asc" orderBy += "asc"
if db.ORM.Dialect().GetName() == "postgres" { if models.ORM.Dialect().GetName() == "postgres" {
orderBy += " NULLS FIRST" orderBy += " NULLS FIRST"
} }
default: case false:
orderBy += "desc" orderBy += "desc"
if db.ORM.Dialect().GetName() == "postgres" { if models.ORM.Dialect().GetName() == "postgres" {
orderBy += " NULLS LAST" orderBy += " NULLS LAST"
} }
} }
parameters := serviceBase.WhereParams{ parameters := structs.WhereParams{
Params: make([]interface{}, 0, 64), Params: make([]interface{}, 0, 64),
} }
conditions := make([]string, 0, 64) conditions := make([]string, 0, 64)
@ -207,7 +156,7 @@ func searchByQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser
parameters.Params = append(parameters.Params, search.ToDate) parameters.Params = append(parameters.Params, search.ToDate)
} }
if search.Status != 0 { if search.Status != 0 {
if search.Status == common.FilterRemakes { if search.Status == structs.FilterRemakes {
conditions = append(conditions, "status <> ?") conditions = append(conditions, "status <> ?")
} else { } else {
conditions = append(conditions, "status >= ?") conditions = append(conditions, "status >= ?")
@ -230,8 +179,8 @@ func searchByQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser
parameters.Params = append(parameters.Params, uint64(search.MaxSize)) parameters.Params = append(parameters.Params, uint64(search.MaxSize))
} }
searchQuerySplit := strings.Fields(search.Query) querySplit := strings.Fields(search.NameLike)
for _, word := range searchQuerySplit { for _, word := range querySplit {
firstRune, _ := utf8.DecodeRuneInString(word) firstRune, _ := utf8.DecodeRuneInString(word)
if len(word) == 1 && unicode.IsPunct(firstRune) { if len(word) == 1 && unicode.IsPunct(firstRune) {
// some queries have a single punctuation character // some queries have a single punctuation character
@ -257,13 +206,13 @@ func searchByQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser
log.Infof("SQL query is :: %s\n", parameters.Conditions) log.Infof("SQL query is :: %s\n", parameters.Conditions)
if deleted { if deleted {
tor, count, err = torrentService.GetDeletedTorrents(&parameters, orderBy, int(search.Max), int(search.Max)*(search.Page-1)) tor, count, err = torrents.FindDeleted(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
} else if countAll && !withUser { } else if countAll && !withUser {
tor, count, err = torrentService.GetTorrentsOrderBy(&parameters, orderBy, int(search.Max), int(search.Max)*(search.Page-1)) tor, count, err = torrents.FindOrderBy(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
} else if withUser { } else if withUser {
tor, count, err = torrentService.GetTorrentsWithUserOrderBy(&parameters, orderBy, int(search.Max), int(search.Max)*(search.Page-1)) tor, count, err = torrents.FindWithUserOrderBy(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
} else { } else {
tor, err = torrentService.GetTorrentsOrderByNoCount(&parameters, orderBy, int(search.Max), int(search.Max)*(search.Page-1)) tor, err = torrents.FindOrderByNoCount(&parameters, orderBy, int(search.Max), int(search.Max*(search.Offset-1)))
} }
return return
} }

Voir le fichier

@ -1,4 +1,4 @@
package serviceBase package structs
// WhereParams struct for search // WhereParams struct for search
type WhereParams struct { type WhereParams struct {

Voir le fichier

@ -1,4 +1,4 @@
package common package structs
import ( import (
"math" "math"
@ -10,11 +10,9 @@ import (
"strings" "strings"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
catUtil "github.com/NyaaPantsu/nyaa/util/categories" catUtil "github.com/NyaaPantsu/nyaa/utils/categories"
) )
type Status uint8
const ( const (
ShowAll Status = 0 ShowAll Status = 0
FilterRemakes = 2 FilterRemakes = 2
@ -22,6 +20,39 @@ const (
APlus = 4 APlus = 4
) )
type Status uint8
type SortMode uint8
type Category struct {
Main, Sub uint8
}
type SizeBytes uint64
type DateFilter string
type Categories []*Category
// TorrentParam defines all parameters that can be provided when searching for a torrent
type TorrentParam struct {
All bool // True means ignore everything but Max and Offset
Full bool // True means load all members
Order bool // True means ascending
Hidden bool // True means filter hidden torrents
Status Status
Sort SortMode
Category Categories
Max uint32
Offset uint32
UserID uint32
TorrentID uint32
FromID uint32
FromDate DateFilter
ToDate DateFilter
NotNull string // csv
Null string // csv
NameLike string // csv
Language string
MinSize SizeBytes
MaxSize SizeBytes
}
func (st *Status) ToString() string { func (st *Status) ToString() string {
switch *st { switch *st {
case FilterRemakes: case FilterRemakes:
@ -47,7 +78,6 @@ func (st *Status) Parse(s string) {
} }
} }
type SortMode uint8
const ( const (
ID SortMode = iota ID SortMode = iota
@ -129,9 +159,6 @@ func (s *SortMode) ToDBField() string {
return config.Conf.Torrents.Order return config.Conf.Torrents.Order
} }
type Category struct {
Main, Sub uint8
}
func (c Category) String() (s string) { func (c Category) String() (s string) {
if c.Main != 0 { if c.Main != 0 {
@ -187,7 +214,6 @@ func ParseCategories(s string) []*Category {
return Categories{} return Categories{}
} }
type SizeBytes uint64
func (sz *SizeBytes) Parse(s string, sizeType string) bool { func (sz *SizeBytes) Parse(s string, sizeType string) bool {
if s == "" { if s == "" {
@ -214,7 +240,6 @@ func (sz *SizeBytes) Parse(s string, sizeType string) bool {
return true return true
} }
type DateFilter string
func (d *DateFilter) Parse(s string, dateType string) bool { func (d *DateFilter) Parse(s string, dateType string) bool {
if s == "" { if s == "" {
@ -237,25 +262,3 @@ func (d *DateFilter) Parse(s string, dateType string) bool {
return true return true
} }
type Categories []*Category
// deprecated for TorrentParam
type SearchParam struct {
TorrentID uint
FromID uint // Search for torrentID > FromID
Order bool // True means acsending
Hidden bool // True means filter hidden torrents
Status Status
Sort SortMode
Category Categories
FromDate DateFilter
ToDate DateFilter
Page int
UserID uint
Max uint
NotNull string
Language string
MinSize SizeBytes
MaxSize SizeBytes
Query string
}

Voir le fichier

@ -1,4 +1,4 @@
package common package structs
import ( import (
"path" "path"
@ -11,8 +11,8 @@ import (
// run before config/parse.go:init() // run before config/parse.go:init()
var _ = func() (_ struct{}) { var _ = func() (_ struct{}) {
config.ConfigPath = path.Join("..", config.ConfigPath) config.ConfigPath = path.Join("..", "..", "..", config.ConfigPath)
config.DefaultConfigPath = path.Join("..", config.DefaultConfigPath) config.DefaultConfigPath = path.Join("..", "..", "..", config.DefaultConfigPath)
config.Parse() config.Parse()
return return
}() }()

Voir le fichier

@ -1,4 +1,4 @@
package common package structs
import ( import (
"context" "context"
@ -11,41 +11,17 @@ import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
// TorrentParam defines all parameters that can be provided when searching for a torrent
type TorrentParam struct {
All bool // True means ignore everything but Max and Offset
Full bool // True means load all members
Order bool // True means ascending
Hidden bool // True means filter hidden torrents
Status Status
Sort SortMode
Category Categories
Max uint32
Offset uint32
UserID uint32
TorrentID uint32
FromID uint32
FromDate DateFilter
ToDate DateFilter
NotNull string // csv
Null string // csv
NameLike string // csv
Language string
MinSize SizeBytes
MaxSize SizeBytes
}
// FromRequest : parse a request in torrent param // FromRequest : parse a request in torrent param
// TODO Should probably return an error ? // TODO Should probably return an error ?
func (p *TorrentParam) FromRequest(c *gin.Context) { func (p *TorrentParam) FromRequest(c *gin.Context) {
var err error var err error
nameLike := strings.TrimSpace(c.Query("q")) nameLike := strings.TrimSpace(c.Query("q"))
max, err := strconv.ParseUint(c.Query("limit"), 10, 32) max, err := strconv.ParseUint(c.DefaultQuery("limit", strconv.Itoa(config.Conf.Navigation.TorrentsPerPage)), 10, 32)
if err != nil { if err != nil {
max = uint64(config.Conf.Navigation.TorrentsPerPage) max = uint64(config.Conf.Navigation.TorrentsPerPage)
} else if max > uint64(config.Conf.Navigation.MaxTorrentsPerPage) { } else if max > uint64(config.Conf.Navigation.MaxTorrentsPerPage) {

Voir le fichier

@ -3,7 +3,7 @@ package signals
import ( import (
"sync" "sync"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
) )
// registered interrupt callbacks. // registered interrupt callbacks.

Voir le fichier

@ -3,7 +3,7 @@ package timeHelper
import ( import (
"time" "time"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
) )
// FewDaysLater : Give time now + some days // FewDaysLater : Give time now + some days

Voir le fichier

@ -4,7 +4,7 @@ import (
"strings" "strings"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util/publicSettings" "github.com/NyaaPantsu/nyaa/utils/publicSettings"
) )
var torrentLanguages []string var torrentLanguages []string

Voir le fichier

@ -12,8 +12,8 @@ import (
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/service" "github.com/NyaaPantsu/nyaa/service"
"github.com/NyaaPantsu/nyaa/util/sanitize" "github.com/NyaaPantsu/nyaa/utils/sanitize"
"github.com/NyaaPantsu/nyaa/util/validator/torrent" "github.com/NyaaPantsu/nyaa/utils/validator/torrent"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

Voir le fichier

@ -1,7 +1,7 @@
package validator package validator
import ( import (
"github.com/NyaaPantsu/nyaa/util/messages" "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/go-playground/validator" "github.com/go-playground/validator"
) )

Voir le fichier

@ -1,7 +1,7 @@
package validator package validator
import ( import (
"github.com/NyaaPantsu/nyaa/util/messages" "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/go-playground/validator" "github.com/go-playground/validator"
) )

Voir le fichier

@ -1,7 +1,7 @@
package validator package validator
import ( import (
"github.com/NyaaPantsu/nyaa/util/messages" "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/go-playground/validator" "github.com/go-playground/validator"
) )

Voir le fichier

@ -1,7 +1,7 @@
package validator package validator
import ( import (
"github.com/NyaaPantsu/nyaa/util/messages" "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/go-playground/validator" "github.com/go-playground/validator"
) )

Voir le fichier

@ -5,10 +5,10 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util/categories" "github.com/NyaaPantsu/nyaa/utils/categories"
"github.com/NyaaPantsu/nyaa/util/format" "github.com/NyaaPantsu/nyaa/utils/format"
"github.com/NyaaPantsu/nyaa/util/metainfo" "github.com/NyaaPantsu/nyaa/utils/metainfo"
"github.com/NyaaPantsu/nyaa/util/torrentLanguages" "github.com/NyaaPantsu/nyaa/utils/torrentLanguages"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/zeebo/bencode" "github.com/zeebo/bencode"
"io" "io"

Voir le fichier

@ -1,8 +1,8 @@
package userValidator package userValidator
import ( import (
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/util/validator" "github.com/NyaaPantsu/nyaa/utils/validator"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http" "net/http"
"testing" "testing"

Voir le fichier

@ -3,8 +3,8 @@ package userValidator
import ( import (
"regexp" "regexp"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/util/validator" "github.com/NyaaPantsu/nyaa/utils/validator"
) )
// Regex by: Philippe Verdy (in a comment somewhere on a website) - Valid every email RFC valid // Regex by: Philippe Verdy (in a comment somewhere on a website) - Valid every email RFC valid

Voir le fichier

@ -6,8 +6,8 @@ import (
"time" "time"
"unicode" "unicode"
"github.com/NyaaPantsu/nyaa/util/log" "github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/go-playground/validator" "github.com/go-playground/validator"
"strconv" "strconv"
) )

Voir le fichier

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/config"
msg "github.com/NyaaPantsu/nyaa/util/messages" msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )