Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/model/report.go
sfan5 4c24318cb3 More sukebei fixes (#649)
* Remove useless .Table() from db usage

This is handled via TableName() already

* Optimization: omit file-list fetching for old torrents

* Use seperate tables for reports & files on sukebei

* Fix invalid pages in nav if <5 pages total
2017-05-21 00:26:22 +10:00

68 lignes
1,7 Kio
Go

package model
import (
"time"
"github.com/NyaaPantsu/nyaa/config"
)
// User can be null (anonymous reports)
// FIXME can't preload field Torrents for model.TorrentReport
type TorrentReport struct {
ID uint `gorm:"column:torrent_report_id;primary_key"`
Description string `gorm:"column:type"`
TorrentID uint `gorm:"column:torrent_id"`
UserID uint `gorm:"column:user_id"`
CreatedAt time.Time `gorm:"column:created_at"`
Torrent *Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
User *User `gorm:"AssociationForeignKey:UserID;ForeignKey:user_id"`
}
func (r TorrentReport) TableName() string {
return config.ReportsTableName
}
type TorrentReportJson struct {
ID uint `json:"id"`
Description string `json:"description"`
Torrent TorrentJSON `json:"torrent"`
User UserJSON `json:"user"`
}
/* Model Conversion to Json */
func getReportDescription(d string) string {
if d == "illegal" {
return "Illegal content"
} else if d == "spam" {
return "Spam / Garbage"
} else if d == "wrongcat" {
return "Wrong category"
} else if d == "dup" {
return "Duplicate / Deprecated"
}
return "???"
}
func (report *TorrentReport) ToJson() TorrentReportJson {
var t TorrentJSON = TorrentJSON{}
if report.Torrent != nil { // FIXME: report.Torrent should never be nil
t = report.Torrent.ToJSON()
}
var u UserJSON = UserJSON{}
if report.User != nil {
u = report.User.ToJSON()
}
json := TorrentReportJson{report.ID, getReportDescription(report.Description), t, u}
return json
}
func TorrentReportsToJSON(reports []TorrentReport) []TorrentReportJson {
json := make([]TorrentReportJson, len(reports))
for i := range reports {
json[i] = reports[i].ToJson()
}
return json
}