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/activities"
"github.com/NyaaPantsu/nyaa/util/cookies"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/gin-gonic/gin"
)

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

@ -13,11 +13,11 @@ import (
"github.com/NyaaPantsu/nyaa/models/comments"
"github.com/NyaaPantsu/nyaa/models/reports"
"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/util/categories"
"github.com/NyaaPantsu/nyaa/util/cookies"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/search"
"github.com/NyaaPantsu/nyaa/utils/categories"
"github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/search"
"github.com/gin-gonic/gin"
)
@ -388,7 +388,7 @@ func TorrentsPostListPanel(c *gin.Context) {
*/
func APIMassMod(c *gin.Context) {
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")
var mapOk map[string]interface{}
@ -404,7 +404,7 @@ func APIMassMod(c *gin.Context) {
// DeletedTorrentsModPanel : Controller for viewing deleted torrents, accept common search arguments
func DeletedTorrentsModPanel(c *gin.Context) {
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"]
unblocked := c.Request.URL.Query()["unblocked"]
blocked := c.Request.URL.Query()["blocked"]
@ -487,7 +487,7 @@ func torrentManyAction(c *gin.Context) {
owner, _ := strconv.Atoi(c.PostForm("owner"))
category := c.PostForm("category")
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
var err error

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

@ -16,7 +16,7 @@ import (
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/service/api"
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"
)

Voir le fichier

@ -9,12 +9,12 @@ import (
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/service/api"
"github.com/NyaaPantsu/nyaa/util/captcha"
"github.com/NyaaPantsu/nyaa/util/cookies"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/NyaaPantsu/nyaa/util/upload"
"github.com/NyaaPantsu/nyaa/utils/captcha"
"github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/utils/upload"
"github.com/gin-gonic/gin"
)
@ -38,7 +38,7 @@ func UploadHandler(c *gin.Context) {
func UploadPostHandler(c *gin.Context) {
var uploadForm apiService.TorrentRequest
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) {
userCaptcha := captcha.Extract(c)

Voir le fichier

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

Voir le fichier

@ -18,12 +18,12 @@ import (
"github.com/NyaaPantsu/nyaa/models/reports"
"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/service/api"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/captcha"
"github.com/NyaaPantsu/nyaa/util/cookies"
"github.com/NyaaPantsu/nyaa/util/filelist"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/NyaaPantsu/nyaa/utils"
"github.com/NyaaPantsu/nyaa/utils/captcha"
"github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/utils/filelist"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
"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/controllers"
"github.com/NyaaPantsu/nyaa/util/cookies"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/NyaaPantsu/nyaa/util/search"
"github.com/NyaaPantsu/nyaa/util/signals"
"github.com/NyaaPantsu/nyaa/utils/cookies"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/NyaaPantsu/nyaa/utils/search"
"github.com/NyaaPantsu/nyaa/utils/signals"
)
var buildversion string

Voir le fichier

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

Voir le fichier

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

Voir le fichier

@ -17,8 +17,9 @@ import (
"net/url"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/utils/format"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/sanitize"
"github.com/bradfitz/slice"
)
@ -256,14 +257,14 @@ func (t *Torrent) ToJSON() TorrentJSON {
} else {
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))
for _, c := range t.OldComments {
commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, UserID: -1, Content: template.HTML(c.Content), Date: c.Date.UTC()})
}
for _, c := range t.Comments {
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 {
commentsJSON = append(commentsJSON, CommentJSON{})
}
@ -317,17 +318,17 @@ func (t *Torrent) ToJSON() TorrentJSON {
Hash: t.Hash,
Date: t.Date.Format(time.RFC3339),
Filesize: t.Filesize,
Description: util.MarkdownToHTML(t.Description),
Description: sanitize.MarkdownToHTML(t.Description),
Comments: commentsJSON,
SubCategory: strconv.Itoa(t.SubCategory),
Category: strconv.Itoa(t.Category),
Downloads: t.Downloads,
UploaderID: uploaderID,
UploaderName: util.SafeText(uploader),
WebsiteLink: util.Safe(t.WebsiteLink),
UploaderName: sanitize.SafeText(uploader),
WebsiteLink: sanitize.Safe(t.WebsiteLink),
Language: t.Language,
Magnet: template.URL(magnet),
TorrentLink: util.Safe(torrentlink),
TorrentLink: sanitize.Safe(torrentlink),
Leechers: scrape.Leechers,
Seeders: scrape.Seeders,
Completed: scrape.Completed,

Voir le fichier

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

Voir le fichier

@ -9,7 +9,7 @@ import (
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/activities"
"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

Voir le fichier

@ -8,7 +8,7 @@ import (
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/service"
"github.com/NyaaPantsu/nyaa/utils/search/structs"
)
/* 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
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)
return
}
// 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)
return
}
// 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)
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,
) {
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.
// GetTorrents returns the first records found. Later records may be retrieved
// 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)
}
// 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)
}
@ -192,7 +192,7 @@ func ToggleBlock(id uint) (models.Torrent, int, error) {
}
// 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)
return
}

Voir le fichier

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

Voir le fichier

@ -7,7 +7,7 @@ import (
"time"
"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/gin-gonic/gin"
"golang.org/x/crypto/bcrypt"

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

@ -4,7 +4,7 @@ import (
"strconv"
"strings"
"github.com/NyaaPantsu/nyaa/util/categories"
"github.com/NyaaPantsu/nyaa/utils/categories"
)
// 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"
"fmt"
"github.com/NyaaPantsu/nyaa/util/publicSettings"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
"github.com/gin-gonic/gin"
"github.com/gorilla/context"
"github.com/nicksnyder/go-i18n/i18n"

Voir le fichier

@ -3,16 +3,14 @@ package search
import (
"strconv"
"strings"
"time"
"unicode"
"unicode/utf8"
"github.com/NyaaPantsu/nyaa/common"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/service"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/search/structs"
"github.com/gin-gonic/gin"
)
@ -23,7 +21,7 @@ var useTSQuery bool
func Configure(conf *config.SearchConfig) (err error) {
useTSQuery = false
// Postgres needs ILIKE for case-insensitivity
if db.ORM.Dialect().GetName() == "postgres" {
if models.ORM.Dialect().GetName() == "postgres" {
searchOperator = "ILIKE ?"
//useTSQuery = true
// !!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
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)
return
}
// 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)
return
}
// 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)
return
}
// 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)
return
}
// 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)
return
}
@ -79,35 +77,16 @@ func SearchByQueryNoHidden(c *gin.Context, pagenum int) (search common.SearchPar
// elasticsearch always provide a count to how many hits
// 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) (
search common.SearchParam, tor []models.Torrent, count int, err error,
search structs.TorrentParam, tor []models.Torrent, count int, err error,
) {
if db.ElasticSearchClient != nil {
var torrentParam common.TorrentParam
if models.ElasticSearchClient != nil {
var torrentParam structs.TorrentParam
torrentParam.FromRequest(c)
torrentParam.Offset = uint32(pagenum)
torrentParam.Hidden = hidden
totalHits, torrents, err := torrentParam.Find(db.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,
}
totalHits, torrents, err := torrentParam.Find(models.ElasticSearchClient)
// 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("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) (
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)
if err != nil {
max = 50 // default Value maxPerPage
} else if max > 300 {
max = 300
}
search.Max = uint(max)
search.FromRequest(c)
search.Page = pagenum
search.Offset = uint32(pagenum)
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()
if search.Sort == common.Date {
if search.Sort == structs.Date {
search.NotNull = search.Sort.ToDBField() + " IS NOT NULL"
}
orderBy += " "
switch s := c.Query("order"); s {
case "true":
search.Order = true
switch search.Order {
case true:
orderBy += "asc"
if db.ORM.Dialect().GetName() == "postgres" {
if models.ORM.Dialect().GetName() == "postgres" {
orderBy += " NULLS FIRST"
}
default:
case false:
orderBy += "desc"
if db.ORM.Dialect().GetName() == "postgres" {
if models.ORM.Dialect().GetName() == "postgres" {
orderBy += " NULLS LAST"
}
}
parameters := serviceBase.WhereParams{
parameters := structs.WhereParams{
Params: make([]interface{}, 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)
}
if search.Status != 0 {
if search.Status == common.FilterRemakes {
if search.Status == structs.FilterRemakes {
conditions = append(conditions, "status <> ?")
} else {
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))
}
searchQuerySplit := strings.Fields(search.Query)
for _, word := range searchQuerySplit {
querySplit := strings.Fields(search.NameLike)
for _, word := range querySplit {
firstRune, _ := utf8.DecodeRuneInString(word)
if len(word) == 1 && unicode.IsPunct(firstRune) {
// 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)
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 {
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 {
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 {
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
}

Voir le fichier

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

Voir le fichier

@ -1,4 +1,4 @@
package common
package structs
import (
"math"
@ -10,11 +10,9 @@ import (
"strings"
"github.com/NyaaPantsu/nyaa/config"
catUtil "github.com/NyaaPantsu/nyaa/util/categories"
catUtil "github.com/NyaaPantsu/nyaa/utils/categories"
)
type Status uint8
const (
ShowAll Status = 0
FilterRemakes = 2
@ -22,6 +20,39 @@ const (
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 {
switch *st {
case FilterRemakes:
@ -47,7 +78,6 @@ func (st *Status) Parse(s string) {
}
}
type SortMode uint8
const (
ID SortMode = iota
@ -129,9 +159,6 @@ func (s *SortMode) ToDBField() string {
return config.Conf.Torrents.Order
}
type Category struct {
Main, Sub uint8
}
func (c Category) String() (s string) {
if c.Main != 0 {
@ -187,7 +214,6 @@ func ParseCategories(s string) []*Category {
return Categories{}
}
type SizeBytes uint64
func (sz *SizeBytes) Parse(s string, sizeType string) bool {
if s == "" {
@ -214,7 +240,6 @@ func (sz *SizeBytes) Parse(s string, sizeType string) bool {
return true
}
type DateFilter string
func (d *DateFilter) Parse(s string, dateType string) bool {
if s == "" {
@ -237,25 +262,3 @@ func (d *DateFilter) Parse(s string, dateType string) bool {
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 (
"path"
@ -11,8 +11,8 @@ import (
// run before config/parse.go:init()
var _ = func() (_ struct{}) {
config.ConfigPath = path.Join("..", config.ConfigPath)
config.DefaultConfigPath = path.Join("..", config.DefaultConfigPath)
config.ConfigPath = path.Join("..", "..", "..", config.ConfigPath)
config.DefaultConfigPath = path.Join("..", "..", "..", config.DefaultConfigPath)
config.Parse()
return
}()

Voir le fichier

@ -1,4 +1,4 @@
package common
package structs
import (
"context"
@ -11,41 +11,17 @@ import (
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/utils/log"
"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
// TODO Should probably return an error ?
func (p *TorrentParam) FromRequest(c *gin.Context) {
var err error
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 {
max = uint64(config.Conf.Navigation.TorrentsPerPage)
} else if max > uint64(config.Conf.Navigation.MaxTorrentsPerPage) {

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

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

Voir le fichier

@ -3,8 +3,8 @@ package userValidator
import (
"regexp"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/util/validator"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/validator"
)
// 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"
"unicode"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/go-playground/validator"
"strconv"
)

Voir le fichier

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