Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Add in support for commenting on sukebei

Cette révision appartient à :
Eliot Whalan 2017-05-16 12:53:02 +10:00
Parent bde31582de
révision cec71bd759
5 fichiers modifiés avec 20 ajouts et 8 suppressions

Voir le fichier

@ -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 {

Voir le fichier

@ -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"`

Voir le fichier

@ -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),
})
}

Voir le fichier

@ -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
}

Voir le fichier

@ -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)