From a3fa6df938a108182f4af4dbfe6ea511552d89a9 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 20 May 2017 12:45:27 +0200 Subject: [PATCH] Remove bugs (#643) * Fix S/L/D columns wasting huge amounts of space Partially reverts 0c9cdfa8bf93acb038ea62dc3da6db691acb9d9f. * Move last scrape below seed-bar Also fixes the very misleading indentation * Show category name on view page too * Fix fucked up login page (fixes #640) * Fix empty page on login w/o pass (fixes #634) * Fix incorrectly colored error text in day mode * Better readable footer in night mode * Prepare having old uploader names on sukebei and various fixes for sukebei * Different HTML title for sukebei --- config/config.go | 23 ++++++++++++---- model/torrent.go | 9 ++++-- model/user.go | 6 ++-- public/css/style-night.css | 4 +-- public/css/style.css | 3 +- router/modpanel.go | 2 -- router/template_functions.go | 8 +----- router/user_handler.go | 3 +- service/torrent/torrent.go | 7 ++--- service/user/user.go | 2 +- templates/admin_index.html | 2 +- templates/home.html | 20 ++++++++------ templates/index.html | 2 +- templates/view.html | 53 ++++++++++++++++++------------------ 14 files changed, 77 insertions(+), 67 deletions(-) diff --git a/config/config.go b/config/config.go index d2c23cd3..ad37f71e 100644 --- a/config/config.go +++ b/config/config.go @@ -12,14 +12,25 @@ import ( const ( // LastOldTorrentID is the highest torrent ID // that was copied from the original Nyaa - LastOldTorrentID = 923000 - TorrentsTableName = "torrents" - CommentsTableName = "comments" - // for sukebei - //TableName = "sukebei_torrents" - //CommentsTableName = "sukebei_comments" + LastOldTorrentID = 923000 + TorrentsTableName = "torrents" + CommentsTableName = "comments" + UploadsOldTableName = "user_uploads_old" + + // for sukebei: + //LastOldTorrentID = 2303945 + //TorrentsTableName = "sukebei_torrents" + //CommentsTableName = "sukebei_comments" + //UploadsOldTableName = "sukebei_user_uploads_old" + + // FIXME: files table needs to be seperate too ) +func IsSukebei() bool { + return TorrentsTableName == "sukebei_torrents" +} + + type Config struct { Host string `json:"host"` Port int `json:"port"` diff --git a/model/torrent.go b/model/torrent.go index 96df8416..75efc69f 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -187,9 +187,12 @@ func (t *Torrent) ToJSON() TorrentJSON { } torrentlink := "" if t.ID <= config.LastOldTorrentID && len(config.TorrentCacheLink) > 0 { - torrentlink = fmt.Sprintf(config.TorrentCacheLink, t.Hash) + if config.IsSukebei() { + torrentlink = "" // torrent cache doesn't have sukebei torrents + } else { + torrentlink = fmt.Sprintf(config.TorrentCacheLink, t.Hash) + } } else if t.ID > config.LastOldTorrentID && len(config.TorrentStorageLink) > 0 { - // TODO: Fix as part of configuration changes (fix what?) torrentlink = fmt.Sprintf(config.TorrentStorageLink, t.Hash) } res := TorrentJSON{ @@ -223,7 +226,7 @@ func (t *Torrent) ToJSON() TorrentJSON { /* Complete the functions when necessary... */ // Map Torrents to TorrentsToJSON without reallocations -func TorrentsToJSON(t []Torrent) []TorrentJSON { // TODO: Convert to singular version +func TorrentsToJSON(t []Torrent) []TorrentJSON { json := make([]TorrentJSON, len(t)) for i := range t { json[i] = t[i].ToJSON() diff --git a/model/user.go b/model/user.go index b1bb07d6..6d98ca21 100644 --- a/model/user.go +++ b/model/user.go @@ -2,6 +2,8 @@ package model import ( "time" + + "github.com/NyaaPantsu/nyaa/config" ) const ( @@ -86,8 +88,8 @@ type UserUploadsOld struct { } func (c UserUploadsOld) TableName() string { - // TODO: rename this in db - return "user_uploads_old" + // is this needed here? + return config.UploadsOldTableName } func (u *User) ToJSON() UserJSON { diff --git a/public/css/style-night.css b/public/css/style-night.css index d135e9ce..d7926659 100644 --- a/public/css/style-night.css +++ b/public/css/style-night.css @@ -60,8 +60,8 @@ background-image: url(/img/megumin.png); } -body { - background-color:#282A2E; +body, footer { + background-color: #282A2E; color: #eff5f5; } diff --git a/public/css/style.css b/public/css/style.css index 5145699f..100a4d41 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -440,8 +440,7 @@ select#bottom_language_selector { } .text-error { - background: white; - color: #cf9fff; + color: #fb3333; } /* Wordbreak fix*/ diff --git a/router/modpanel.go b/router/modpanel.go index fed54ede..8931d788 100644 --- a/router/modpanel.go +++ b/router/modpanel.go @@ -72,7 +72,6 @@ func (f *ReassignForm) ExtractInfo(r *http.Request) error { } func (f *ReassignForm) ExecuteAction() (int, error) { - var toBeChanged []uint var err error if f.By == "olduser" { @@ -93,7 +92,6 @@ func (f *ReassignForm) ExecuteAction() (int, error) { num += 1 } } - // TODO: clean shit from user_uploads_old if needed return num, nil } diff --git a/router/template_functions.go b/router/template_functions.go index dce4f9d5..97aacc1c 100644 --- a/router/template_functions.go +++ b/router/template_functions.go @@ -131,13 +131,7 @@ var FuncMap = template.FuncMap{ } return template.HTML(ret) }, - "Sukebei": func() bool { - if config.TorrentsTableName == "sukebei_torrents" { - return true - } else { - return false - } - }, + "Sukebei": config.IsSukebei, "T": i18n.IdentityTfunc, "Ts": i18n.IdentityTfunc, "getDefaultLanguage": languages.GetDefaultLanguage, diff --git a/router/user_handler.go b/router/user_handler.go index 94ce39ff..5e642173 100644 --- a/router/user_handler.go +++ b/router/user_handler.go @@ -282,13 +282,14 @@ func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) { if errorTmpl != nil { http.Error(w, errorTmpl.Error(), http.StatusInternalServerError) } + return } else { url, _ := Router.Get("home").URL() http.Redirect(w, r, url.String(), http.StatusSeeOther) } } if len(err) > 0 { - languages.SetTranslationFromRequest(viewRegisterTemplate, r) + languages.SetTranslationFromRequest(viewLoginTemplate, r) htv := UserLoginFormVariables{b, err, NewSearchForm(), NewNavigation(), GetUser(r), r.URL, mux.CurrentRoute(r)} errorTmpl := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv) if errorTmpl != nil { diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index 33b604f8..899460ca 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -58,7 +58,7 @@ func GetTorrentById(id string) (torrent model.Torrent, err error) { if err != nil { return } - if id_int <= config.LastOldTorrentID { + if id_int <= config.LastOldTorrentID && !config.IsSukebei() { // only preload old comments if they could actually exist tmp = tmp.Preload("OldComments") } @@ -73,7 +73,7 @@ func GetTorrentById(id string) (torrent model.Torrent, err error) { torrent.OldUploader = "" if torrent.ID <= config.LastOldTorrentID && torrent.UploaderID == 0 { var tmp model.UserUploadsOld - if !db.ORM.Where("torrent_id = ?", torrent.ID).Find(&tmp).RecordNotFound() { + if !db.ORM.Table(config.UploadsOldTableName).Where("torrent_id = ?", torrent.ID).Find(&tmp).RecordNotFound() { torrent.OldUploader = tmp.Username } } @@ -91,7 +91,7 @@ func GetTorrentById(id string) (torrent model.Torrent, err error) { // won't fetch user or comments func GetRawTorrentById(id uint) (torrent model.Torrent, err error) { err = nil - if db.ORM.Table(config.TorrentsTableName).Table(config.TorrentsTableName).Where("torrent_id = ?", id).Find(&torrent).RecordNotFound() { + if db.ORM.Table(config.TorrentsTableName).Where("torrent_id = ?", id).Find(&torrent).RecordNotFound() { err = errors.New("Article is not found.") } return @@ -127,7 +127,6 @@ func getTorrentsOrderBy(parameters *serviceBase.WhereParams, orderBy string, lim return } } - // TODO: Vulnerable to injections. Use query builder. (is it?) // build custom db query for performance reasons dbQuery := "SELECT * FROM " + config.TorrentsTableName diff --git a/service/user/user.go b/service/user/user.go index 9f59e2b1..db0e595a 100644 --- a/service/user/user.go +++ b/service/user/user.go @@ -268,7 +268,7 @@ func RetrieveUserByUsername(username string) (*model.PublicUser, string, int, er func RetrieveOldUploadsByUsername(username string) ([]uint, error) { var ret []uint var tmp []*model.UserUploadsOld - err := db.ORM.Where("username = ?", username).Find(&tmp).Error + err := db.ORM.Table(config.UploadsOldTableName).Where("username = ?", username).Find(&tmp).Error if err != nil { return ret, err } diff --git a/templates/admin_index.html b/templates/admin_index.html index 279e529b..3dd1d0b6 100644 --- a/templates/admin_index.html +++ b/templates/admin_index.html @@ -5,7 +5,7 @@ - Nyaa Pantsu - {{block "title" .}}{{ T "error_404" }}{{end}} + {{if Sukebei}}Sukebei{{else}}Nyaa{{end}} Pantsu - {{block "title" .}}{{ T "error_404" }}{{end}} diff --git a/templates/home.html b/templates/home.html index 9f8c2157..dbe1e587 100644 --- a/templates/home.html +++ b/templates/home.html @@ -25,13 +25,15 @@ Your browser does not support the audio element. - + - - - @@ -62,11 +64,13 @@ Your browser does not support the audio element. --> {{if .LastScrape.IsZero}} - + {{else}} - - - + {{end}} diff --git a/templates/index.html b/templates/index.html index 519f9c76..a2c59b15 100755 --- a/templates/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@ - Nyaa Pantsu - {{block "title" .}}{{ T "error_404" }}{{end}} + {{if Sukebei}}Sukebei{{else}}Nyaa{{end}} Pantsu - {{block "title" .}}{{ T "error_404" }}{{end}} diff --git a/templates/view.html b/templates/view.html index 57f27633..bbdbbc88 100644 --- a/templates/view.html +++ b/templates/view.html @@ -16,9 +16,11 @@
{{ if Sukebei }} - + + {{ T (Category_Sukebei .Category .SubCategory) }} {{ else }} - + + {{ T (Category_Nyaa .Category .SubCategory) }} {{ end }}

@@ -72,31 +74,23 @@ {{end}}
-
-
{{T "seeders"}}
-
{{T "leechers"}}
-
{{T "completed"}}
-
-
-
-
- {{if .LastScrape.IsZero}} -
{{T "unknown"}}
- {{else}} -
{{.Seeders}}
-
{{.Leechers}}
-
{{.Completed}}
- {{end}} -
-
-
-
- {{if not .LastScrape.IsZero}} -
{{T "last_scraped"}}
-
{{ formatDateRFC .LastScrape }}
- {{end}} -
-
+
+
{{T "seeders"}}
+
{{T "leechers"}}
+
{{T "completed"}}
+
+
+
+
+ {{if .LastScrape.IsZero}} +
{{T "unknown"}}
+ {{else}} +
{{.Seeders}}
+
{{.Leechers}}
+
{{.Completed}}
+ {{end}} +
+

@@ -105,6 +99,11 @@
+
+ {{if not .LastScrape.IsZero}} + {{T "last_scraped"}}{{ formatDateRFC .LastScrape }} + {{end}} +

+ {{T "name"}}{{ genSortArrows .URL "1" }}