Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Show every userstatus (member, janitor, banned, mod) in comments

Cette révision appartient à :
kilo 2017-11-09 15:59:44 +01:00 révisé par GitHub
Parent 8955d2a791
révision 8bbc28900a
Aucune clé n'a été trouvée pour cette signature dans la base de données
ID de la clé GPG: 4AEE18F83AFDEB23

Voir le fichier

@ -21,6 +21,7 @@ import (
"github.com/NyaaPantsu/nyaa/utils/format"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/sanitize"
"github.com/anacrolix/torrent"
"github.com/bradfitz/slice"
"github.com/fatih/structs"
)
@ -312,17 +313,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
}
for _, c := range t.Comments {
if c.User != nil {
userStatus := ""
if c.User.IsBanned() {
userStatus = "userstatus_banned"
}
if c.User.HasAdmin() {
userStatus = "userstatus_moderator"
}
if c.User.ID == t.ID {
userStatus = "userstatus_uploader"
}
commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), UserStatus: userStatus, Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5})
commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), UserStatus: c.User.GetRole(), Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5})
} else {
commentsJSON = append(commentsJSON, CommentJSON{})
}
@ -463,6 +454,26 @@ func (t *Torrent) Update(unscope bool) (int, error) {
return http.StatusOK, nil
}
func (t *Torrent) CreateFileList(Files []torrent.File) ([]File, error) {
var createdFilelist []File
t.Filesize = 0
for _, uploadedFile := range Files {
file := File{TorrentID: t.ID, Filesize: uploadedFile.Length()}
err := file.SetPath(uploadedFile.FileInfo().Path)
if err != nil {
return []File{}, err
}
createdFilelist = append(createdFilelist, file)
t.Filesize += uploadedFile.Length()
ORM.Create(&file)
}
t.FileList = createdFilelist
t.Update(false)
return createdFilelist, nil
}
// UpdateUnscope : Update a torrent based on model
func (t *Torrent) UpdateUnscope() (int, error) {
return t.Update(true)