From 5f91ecf0b48bff211b8f9af11894ab530412952b Mon Sep 17 00:00:00 2001 From: kilo Date: Fri, 28 Jul 2017 14:30:07 +0200 Subject: [PATCH 1/4] Update main.js (#1296) --- public/js/main.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index bc2f80dd..94c1ae8f 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -125,16 +125,6 @@ function startupCode() { if (document.cookie.includes("newVersion")) document.getElementById("commit").className = "new"; - - document.getElementsByClassName("search-box")[0].addEventListener("focus", function (e) { - var w = document.getElementsByClassName("h-user")[0].offsetWidth - document.getElementsByClassName("h-user")[0].style.display = "none" - document.getElementsByClassName("search-box")[0].style.width = document.getElementsByClassName("search-box")[0].offsetWidth + w + "px" - }) - document.getElementsByClassName("search-box")[0].addEventListener("blur", function (e) { - document.getElementsByClassName("search-box")[0].style.width = "" - document.getElementsByClassName("h-user")[0].style.display = "inline-block" - }) } function playVoice() { From f62bd4f6384d123bb275b0aa5b77690bca2a3b21 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Fri, 28 Jul 2017 23:54:18 +0200 Subject: [PATCH 2/4] fix trusted status + locked status on upload --- controllers/upload/upload.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/controllers/upload/upload.go b/controllers/upload/upload.go index 47e85653..181447c6 100644 --- a/controllers/upload/upload.go +++ b/controllers/upload/upload.go @@ -6,6 +6,7 @@ import ( "strconv" "github.com/NyaaPantsu/nyaa/controllers/router" + "github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models/torrents" "github.com/NyaaPantsu/nyaa/templates" "github.com/NyaaPantsu/nyaa/utils/captcha" @@ -51,6 +52,13 @@ func UploadPostHandler(c *gin.Context) { messages.AddError("errors", err.Error()) } + uploadForm.Status = models.TorrentStatusNormal + if uploadForm.Remake { // overrides trusted + uploadForm.Status = models.TorrentStatusRemake + } else if user.IsTrusted() { + uploadForm.Status = models.TorrentStatusTrusted + } + err = torrents.ExistOrDelete(uploadForm.Infohash, user) if err != nil { messages.AddError("errors", err.Error()) From 5866881ecac983072103f259646ec63ce6054317 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Sat, 29 Jul 2017 00:10:49 +0200 Subject: [PATCH 3/4] fix gorm dependency --- models/torrents/find.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/models/torrents/find.go b/models/torrents/find.go index a0f41c32..b9cd29da 100644 --- a/models/torrents/find.go +++ b/models/torrents/find.go @@ -127,7 +127,7 @@ func findOrderBy(parameters *structs.WhereParams, orderBy string, limit int, off if !deleted { conditionArray = append(conditionArray, "deleted_at IS NULL") } else { - conditionArray = append(conditionArray, "deleted_at NOT NULL") + conditionArray = append(conditionArray, "deleted_at IS NOT NULL") } conditions := strings.Join(conditionArray, " AND ") @@ -145,26 +145,27 @@ func findOrderBy(parameters *structs.WhereParams, orderBy string, limit int, off } // build custom db query for performance reasons - dbQuery := "SELECT * FROM " + config.Get().Models.TorrentsTableName + dbQuery := models.ORM.Unscoped().Preload("Scrape").Preload("FileList") + if withUser { + dbQuery = dbQuery.Preload("Uploader") + } + if countAll { + dbQuery = dbQuery.Preload("Comments") + } + if conditions != "" { - dbQuery = dbQuery + " WHERE " + conditions + dbQuery = dbQuery.Where(conditions, params...) } if orderBy == "" { // default OrderBy - orderBy = "torrent_id DESC" + orderBy = "torrent_date DESC" } - dbQuery = dbQuery + " ORDER BY " + orderBy + dbQuery = dbQuery.Order(orderBy) if limit != 0 || offset != 0 { // if limits provided - dbQuery = dbQuery + " LIMIT " + strconv.Itoa(limit) + " OFFSET " + strconv.Itoa(offset) + dbQuery = dbQuery.Limit(strconv.Itoa(limit)).Offset(strconv.Itoa(offset)) } - dbQ := models.ORM.Preload("Scrape") - if withUser { - dbQ = dbQ.Preload("Uploader") - } - if countAll { - dbQ = dbQ.Preload("Comments") - } - err = dbQ.Preload("FileList").Raw(dbQuery, params...).Find(&torrents).Error + + err = dbQuery.Find(&torrents).Error // cache.C.Set(fmt.Sprintf("%v", parameters), &structs.TorrentCache{torrents, count}, 5*time.Minute) // Cache shouldn't be done here but in search util return } From 590ebbf0d80571c35ea6276dd92ef8b7433f47b5 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Sat, 29 Jul 2017 12:48:43 +0200 Subject: [PATCH 4/4] Fix filesize bug --- controllers/upload/upload.go | 5 +++-- models/torrents/create.go | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/controllers/upload/upload.go b/controllers/upload/upload.go index 181447c6..67171037 100644 --- a/controllers/upload/upload.go +++ b/controllers/upload/upload.go @@ -15,6 +15,7 @@ import ( "github.com/NyaaPantsu/nyaa/utils/upload" "github.com/NyaaPantsu/nyaa/utils/validator/torrent" "github.com/gin-gonic/gin" + "github.com/NyaaPantsu/nyaa/utils/log" ) // UploadHandler : Main Controller for uploading a torrent @@ -66,8 +67,8 @@ func UploadPostHandler(c *gin.Context) { if !messages.HasErrors() { // add to db and redirect - torrent, _ := torrents.Create(user, &uploadForm) - + torrent, err := torrents.Create(user, &uploadForm) + log.CheckErrorWithMessage(err, "ERROR_TORRENT_CREATED: Error while creating entry in db") url := "/view/" + strconv.FormatUint(uint64(torrent.ID), 10) c.Redirect(302, url+"?success") } diff --git a/models/torrents/create.go b/models/torrents/create.go index 5e507360..c422a205 100644 --- a/models/torrents/create.go +++ b/models/torrents/create.go @@ -25,7 +25,11 @@ func Create(user *models.User, uploadForm *torrentValidator.TorrentRequest) (*mo UploaderID: user.ID} torrent.EncodeLanguages() // Convert languages array in language string torrent.ParseTrackers(uploadForm.Trackers) - models.ORM.Create(&torrent) + err := models.ORM.Create(&torrent).Error + log.Infof("Torrent ID %d created!\n", torrent.ID) + if err != nil { + log.CheckErrorWithMessage(err, "ERROR_TORRENT_CREATE: Cannot create a torrent") + } if config.Get().Search.EnableElasticSearch && models.ElasticSearchClient != nil { err := torrent.AddToESIndex(models.ElasticSearchClient) if err == nil { @@ -39,7 +43,7 @@ func Create(user *models.User, uploadForm *torrentValidator.TorrentRequest) (*mo NewTorrentEvent(user, &torrent) if len(uploadForm.FileList) > 0 { for _, uploadedFile := range uploadForm.FileList { - file := models.File{TorrentID: torrent.ID, Filesize: uploadForm.Filesize} + file := models.File{TorrentID: torrent.ID, Filesize: uploadedFile.Filesize} err := file.SetPath(uploadedFile.Path) if err != nil { return &torrent, err