Display uploader name with link to profile page
Cette révision appartient à :
Parent
a913bead67
révision
fb07da18ec
4 fichiers modifiés avec 24 ajouts et 7 suppressions
|
@ -4,7 +4,6 @@ import (
|
|||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/util"
|
||||
|
||||
"html"
|
||||
"html/template"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -34,7 +33,7 @@ type Torrents struct {
|
|||
Description string `gorm:"column:description"`
|
||||
WebsiteLink string `gorm:"column:website_link"`
|
||||
|
||||
Uploader *User `gorm:"ForeignKey:uploader"`
|
||||
Uploader *User `gorm:"ForeignKey:UploaderId"`
|
||||
OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
|
||||
Comments []Comment `gorm:"ForeignKey:torrent_id"`
|
||||
}
|
||||
|
@ -66,6 +65,7 @@ type TorrentsJson struct {
|
|||
Category string `json:"category"`
|
||||
Downloads int `json:"downloads"`
|
||||
UploaderId uint `json:"uploader_id"`
|
||||
UploaderName template.HTML `json:"uploader_name"`
|
||||
WebsiteLink template.URL `json:"website_link"`
|
||||
Magnet template.URL `json:"magnet"`
|
||||
}
|
||||
|
@ -79,12 +79,15 @@ func (t *Torrents) ToJson() TorrentsJson {
|
|||
commentsJson = append(commentsJson, CommentsJson{Username: c.Username, Content: template.HTML(c.Content), Date: c.Date})
|
||||
}
|
||||
for _, c := range t.Comments {
|
||||
|
||||
commentsJson = append(commentsJson, CommentsJson{Username: c.User.Username, Content: util.MarkdownToHTML(c.Content), Date: c.CreatedAt})
|
||||
}
|
||||
uploader := ""
|
||||
if t.Uploader != nil {
|
||||
uploader = t.Uploader.Username
|
||||
}
|
||||
res := TorrentsJson{
|
||||
Id: strconv.FormatUint(uint64(t.Id), 10),
|
||||
Name: html.UnescapeString(t.Name),
|
||||
Name: t.Name,
|
||||
Status: t.Status,
|
||||
Hash: t.Hash,
|
||||
Date: t.Date.Format(time.RFC3339),
|
||||
|
@ -95,6 +98,7 @@ func (t *Torrents) ToJson() TorrentsJson {
|
|||
Category: strconv.Itoa(t.Category),
|
||||
Downloads: t.Downloads,
|
||||
UploaderId: t.UploaderId,
|
||||
UploaderName: util.SafeText(uploader),
|
||||
WebsiteLink: util.Safe(t.WebsiteLink),
|
||||
Magnet: util.Safe(magnet)}
|
||||
|
||||
|
|
|
@ -58,7 +58,10 @@ func GetTorrentById(id string) (model.Torrents, error) {
|
|||
if tmp.Find(&torrent).RecordNotFound() {
|
||||
return torrent, errors.New("Article is not found.")
|
||||
}
|
||||
// .Preload("Comments.User") doesn't work
|
||||
// GORM relly likes not doing its job correctly
|
||||
// (or maybe I'm just retarded)
|
||||
torrent.Uploader = new(model.User)
|
||||
db.ORM.Where("user_id = ?", torrent.UploaderId).Find(torrent.Uploader)
|
||||
for i := range torrent.Comments {
|
||||
torrent.Comments[i].User = new(model.User)
|
||||
db.ORM.Where("user_id = ?", torrent.Comments[i].UserId).Find(torrent.Comments[i].User)
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
<td>{{T "size"}}</td>
|
||||
<td>{{.Filesize}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Uploader</td>
|
||||
<td><a href="{{$.URL.Parse (printf "/user/%d/-" .UploaderId) }}">{{.UploaderName}}</a></td>
|
||||
{{if ne .WebsiteLink ""}}
|
||||
<tr>
|
||||
<td>{{T "Link"}}</td>
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
package util
|
||||
|
||||
import "html/template"
|
||||
import (
|
||||
"html"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
func Safe(s string) template.URL {
|
||||
return template.URL(s)
|
||||
}
|
||||
|
||||
func SafeText(s string) template.HTML {
|
||||
return template.HTML(html.EscapeString(s))
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket