Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Display username of old uploads alongside れんちょん

Cette révision appartient à :
sfan5 2017-05-10 13:32:45 +02:00
Parent ee6aea139f
révision 775f9c15ad
5 fichiers modifiés avec 29 ajouts et 2 suppressions

Voir le fichier

@ -30,7 +30,9 @@ func GormInit(conf *config.Config) (*gorm.DB, error) {
// TODO: Enable Gorm initialization for non-development builds
if config.Environment == "DEVELOPMENT" {
db.LogMode(true)
db.AutoMigrate(&model.Torrent{}, &model.UserFollows{}, &model.User{}, &model.Comment{}, &model.OldComment{}, &model.TorrentReport{})
db.AutoMigrate(&model.User{}, &model.UserFollows{}, &model.UserUploadsOld{})
db.AutoMigrate(&model.Torrent{}, &model.TorrentReport{})
db.AutoMigrate(&model.Comment{}, &model.OldComment{})
}
return db, nil

Voir le fichier

@ -37,6 +37,7 @@ type Torrent struct {
DeletedAt *time.Time
Uploader *User `gorm:"ForeignKey:UploaderId"`
OldUploader string `gorm:"-"` // ???????
OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
Comments []Comment `gorm:"ForeignKey:torrent_id"`
}
@ -109,6 +110,7 @@ type TorrentJSON struct {
Downloads int `json:"downloads"`
UploaderID uint `json:"uploader_id"`
UploaderName template.HTML `json:"uploader_name"`
OldUploader template.HTML `json:"uploader_old"`
WebsiteLink template.URL `json:"website_link"`
Magnet template.URL `json:"magnet"`
TorrentLink template.URL `json:"torrent"`
@ -163,6 +165,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
Downloads: t.Downloads,
UploaderID: t.UploaderID,
UploaderName: util.SafeText(uploader),
OldUploader: util.SafeText(t.OldUploader),
WebsiteLink: util.Safe(t.WebsiteLink),
Magnet: util.Safe(magnet),
TorrentLink: util.Safe(torrentlink)}

Voir le fichier

@ -50,3 +50,13 @@ type UserFollows struct {
UserID uint `gorm:"column:user_id"`
FollowerID uint `gorm:"column:following"`
}
type UserUploadsOld struct {
Username string `gorm:"column:username"`
TorrentId uint `gorm:"column:torrent_id"`
}
func (c UserUploadsOld) TableName() string {
// TODO: rename this in db
return "user_uploads_old"
}

Voir le fichier

@ -73,6 +73,13 @@ func GetTorrentById(id string) (torrent model.Torrent, err error) {
// (or maybe I'm just retarded)
torrent.Uploader = new(model.User)
db.ORM.Where("user_id = ?", torrent.UploaderID).Find(torrent.Uploader)
torrent.OldUploader = ""
if torrent.ID <= config.LastOldTorrentID {
var tmp model.UserUploadsOld
if !db.ORM.Where("torrent_id = ?", torrent.ID).Find(&tmp).RecordNotFound() {
torrent.OldUploader = tmp.Username
}
}
for i := range torrent.Comments {
torrent.Comments[i].User = new(model.User)
err = db.ORM.Where("user_id = ?", torrent.Comments[i].UserID).Find(torrent.Comments[i].User).Error

Voir le fichier

@ -28,7 +28,12 @@
</tr>
<tr>
<td>Uploader</td>
<td><a href="{{$.URL.Parse (printf "/user/%d/-" .UploaderID) }}">{{.UploaderName}}</a></td>
<td>
<a href="{{$.URL.Parse (printf "/user/%d/-" .UploaderID) }}">{{.UploaderName}}</a>
{{if ne .OldUploader ""}}
({{.OldUploader}})
{{end}}
</td>
{{if ne .WebsiteLink ""}}
<tr>
<td>{{T "Link"}}</td>