Merge pull request #271 from sfan5/aaaah
Fix some things and a feature
Cette révision appartient à :
révision
68e3a4acfb
7 fichiers modifiés avec 43 ajouts et 16 suppressions
|
@ -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
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"github.com/ewhal/nyaa/util"
|
||||
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -37,11 +36,13 @@ 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"`
|
||||
}
|
||||
|
||||
// Returns the total size of memory recursively allocated for this struct
|
||||
// FIXME: doesn't go have sizeof or something nicer for this?
|
||||
func (t Torrent) Size() (s int) {
|
||||
s += 8 + // ints
|
||||
2*3 + // time.Time
|
||||
|
@ -108,6 +109,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"`
|
||||
|
@ -132,8 +134,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
|||
magnet := util.InfoHashToMagnet(strings.TrimSpace(t.Hash), t.Name, config.Trackers...)
|
||||
commentsJSON := make([]CommentJSON, 0, len(t.OldComments)+len(t.Comments))
|
||||
for _, c := range t.OldComments {
|
||||
escapedContent := template.HTML(html.EscapeString(c.Content))
|
||||
commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, Content: escapedContent, Date: c.Date})
|
||||
commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, Content: template.HTML(c.Content), Date: c.Date})
|
||||
}
|
||||
for _, c := range t.Comments {
|
||||
commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, Content: util.MarkdownToHTML(c.Content), Date: c.CreatedAt})
|
||||
|
@ -162,6 +163,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)}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
/* Torrent status colors */
|
||||
.remake {
|
||||
background-color: rgb(240, 176, 128);
|
||||
|
@ -323,7 +321,8 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ
|
|||
background: #fff;
|
||||
min-height: 460px;
|
||||
}
|
||||
/* Night mode switcher */
|
||||
|
||||
/* Night mode switcher */
|
||||
#mainmenu a.nightswitch {
|
||||
background: transparent url(/img/sun.png) no-repeat;
|
||||
background-size: 24px;
|
||||
|
@ -331,11 +330,12 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ
|
|||
margin-left: 3px;
|
||||
width: 24px;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
padding-bottom: 2rem;
|
||||
font-size: 2rem;
|
||||
font-family: cursive;
|
||||
color: #CCC;
|
||||
text-shadow: 0px -1px #999999;
|
||||
}
|
||||
color: #616161;
|
||||
text-shadow: -1px -1px #999999;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -98,7 +105,7 @@ func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs
|
|||
torrents []model.Torrent, count int, err error,
|
||||
) {
|
||||
var conditionArray []string
|
||||
conditionArray = append(conditionArray, "deleted_at IS NULL")
|
||||
conditionArray = append(conditionArray, "deleted_at IS NULL")
|
||||
if strings.HasPrefix(orderBy, "filesize") {
|
||||
// torrents w/ NULL filesize fuck up the sorting on Postgres
|
||||
conditionArray = append(conditionArray, "filesize IS NOT NULL")
|
||||
|
@ -112,12 +119,13 @@ func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs
|
|||
}
|
||||
conditions := strings.Join(conditionArray, " AND ")
|
||||
if countAll {
|
||||
// FIXME: `deleted_at IS NULL` is duplicate in here because GORM handles this for us
|
||||
err = db.ORM.Model(&torrents).Where(conditions, params...).Count(&count).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
// TODO: Vulnerable to injections. Use query builder.
|
||||
// TODO: Vulnerable to injections. Use query builder. (is it?)
|
||||
|
||||
// build custom db query for performance reasons
|
||||
dbQuery := "SELECT * FROM torrents"
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
{{.Name}}
|
||||
</a>
|
||||
</td>
|
||||
<td class="hidden-xs" class="date date-short">{{.Date}}</td>
|
||||
<td class="hidden-xs" class="filesize">{{.Filesize}}</td>
|
||||
<td class="hidden-xs date date-short">{{.Date}}</td>
|
||||
<td class="hidden-xs filesize">{{.Filesize}}</td>
|
||||
<td class="hidden-xs">
|
||||
<a href="{{.Magnet}}" title="Magnet link">
|
||||
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span>
|
||||
|
|
|
@ -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>
|
||||
|
|
Référencer dans un nouveau ticket