From cec71bd759a722a58d4c3bb8fc51eb243db44585 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Tue, 16 May 2017 12:53:02 +1000 Subject: [PATCH] Add in support for commenting on sukebei --- config/config.go | 8 +++++--- model/comment.go | 5 +++++ model/torrent.go | 6 +++++- service/comment/comment.go | 6 +++--- service/user/user.go | 3 ++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/config/config.go b/config/config.go index 6891b7a7..d983b553 100644 --- a/config/config.go +++ b/config/config.go @@ -12,10 +12,12 @@ import ( const ( // LastOldTorrentID is the highest torrent ID // that was copied from the original Nyaa - LastOldTorrentID = 923000 - TableName = "torrents" + LastOldTorrentID = 923000 + TableName = "torrents" + CommentsTableName = "comments" // for sukebei - //TableName = "sukebei_torrents" + //TableName = "sukebei_torrents" + //CommentsTableName = "sukebei_comments" ) type Config struct { diff --git a/model/comment.go b/model/comment.go index 67f31c67..fa57e535 100644 --- a/model/comment.go +++ b/model/comment.go @@ -1,6 +1,7 @@ package model import ( + "github.com/ewhal/nyaa/config" "time" ) @@ -22,6 +23,10 @@ func (c Comment) Size() int { return (3 + 3*3 + 2 + 2 + len(c.Content)) * 8 } +func (c Comment) TableName() string { + return config.CommentsTableName +} + type OldComment struct { TorrentID uint `gorm:"column:torrent_id"` Username string `gorm:"column:username"` diff --git a/model/torrent.go b/model/torrent.go index 5d6b0131..8af3e91d 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -74,6 +74,10 @@ func (t Torrent) Size() (s int) { } +func (t Torrent) TableName() string { + return config.TableName +} + /* We need a JSON object instead of a Gorm structure because magnet URLs are not in the database and have to be generated dynamically */ @@ -133,7 +137,7 @@ func (t *Torrent) ToJSON() TorrentJSON { fileListJSON := make([]FileJSON, 0, len(t.FileList)) for _, f := range t.FileList { fileListJSON = append(fileListJSON, FileJSON{ - Path: filepath.Join(f.Path()...), + Path: filepath.Join(f.Path()...), Filesize: util.FormatFilesize2(f.Filesize), }) } diff --git a/service/comment/comment.go b/service/comment/comment.go index 19497c19..2ac4f3df 100644 --- a/service/comment/comment.go +++ b/service/comment/comment.go @@ -1,15 +1,15 @@ package commentService import ( + "github.com/ewhal/nyaa/config" "github.com/ewhal/nyaa/db" "github.com/ewhal/nyaa/model" - ) -func GetAllComments(limit int, offset int, conditions string, values ...interface{}) ([]model.Comment, int){ +func GetAllComments(limit int, offset int, conditions string, values ...interface{}) ([]model.Comment, int) { var comments []model.Comment var nbComments int - db.ORM.Model(&comments).Where(conditions, values...).Count(&nbComments) + db.ORM.Table(config.CommentsTableName).Model(&comments).Where(conditions, values...).Count(&nbComments) db.ORM.Preload("User").Limit(limit).Offset(offset).Where(conditions, values...).Find(&comments) return comments, nbComments } diff --git a/service/user/user.go b/service/user/user.go index d8786d47..ac0f945a 100644 --- a/service/user/user.go +++ b/service/user/user.go @@ -7,6 +7,7 @@ import ( "strconv" "time" + "github.com/ewhal/nyaa/config" "github.com/ewhal/nyaa/db" "github.com/ewhal/nyaa/model" formStruct "github.com/ewhal/nyaa/service/user/form" @@ -128,7 +129,7 @@ func RetrieveUser(r *http.Request, id string) (*model.PublicUser, bool, uint, in var currentUserID uint var isAuthor bool - if db.ORM.First(&user, id).RecordNotFound() { + if db.ORM.Table(config.TableName).First(&user, id).RecordNotFound() { return nil, isAuthor, currentUserID, http.StatusNotFound, errors.New("user not found") } currentUser, err := CurrentUser(r)