From bde8ff4f49f7768870afe4eaabdefc15bda70f3b Mon Sep 17 00:00:00 2001 From: kilo Date: Thu, 12 Oct 2017 17:53:04 +0200 Subject: [PATCH] Fix invalid comment date when JS is enabled, wrong url in an admin torrent list link, malformed pubDate for RSS feed (#1654) * Fix invalid comment date when JS is enabled * fix travis * fix wrong url in admin torrent list * Fix wrong pubDate for /feed * Different function name * same changes as rss for magnet rss * travis test * fix delete button on torrent view * Update edit.jet.html * Update index.jet.html * Update userlist.jet.html * Update torrentlist.jet.html --- controllers/feed/magnet.go | 5 ++--- controllers/feed/rss.go | 11 +++++++++-- public/css/main.css | 2 +- templates/admin/index.jet.html | 2 +- templates/admin/torrentlist.jet.html | 6 +++--- templates/admin/userlist.jet.html | 2 +- templates/site/torrents/view.jet.html | 12 +++++++++--- templates/site/user/edit.jet.html | 2 +- 8 files changed, 27 insertions(+), 15 deletions(-) diff --git a/controllers/feed/magnet.go b/controllers/feed/magnet.go index c7d7928b..4ef5fd85 100644 --- a/controllers/feed/magnet.go +++ b/controllers/feed/magnet.go @@ -4,7 +4,6 @@ import ( "net/http" "strconv" "strings" - "time" "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/utils/feeds" @@ -26,7 +25,7 @@ func RSSMagnetHandler(c *gin.Context) { feed := &nyaafeeds.RssFeed{ Title: title, Link: config.WebAddress() + "/", - PubDate: createdAsTime.String(), + PubDate: formatRSSDate(createdAsTime), } feed.Items = make([]*nyaafeeds.RssItem, len(torrents)) @@ -36,7 +35,7 @@ func RSSMagnetHandler(c *gin.Context) { Title: torrentJSON.Name, Link: &nyaafeeds.RssMagnetLink{Text: string(torrentJSON.Magnet)}, Description: string(torrentJSON.Description), - PubDate: torrent.Date.Format(time.RFC1123Z), + PubDate: formatRSSDate(torrent.Date), GUID: config.WebAddress() + "/view/" + strconv.FormatUint(uint64(torrentJSON.ID), 10), Enclosure: &nyaafeeds.RssEnclosure{ URL: config.WebAddress() + "/download/" + strings.TrimSpace(torrentJSON.Hash), diff --git a/controllers/feed/rss.go b/controllers/feed/rss.go index fc3e6fd1..b2b79e0f 100644 --- a/controllers/feed/rss.go +++ b/controllers/feed/rss.go @@ -5,6 +5,7 @@ import ( "strconv" "strings" "time" + "fmt" "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/utils/feeds" @@ -26,7 +27,7 @@ func RSSHandler(c *gin.Context) { feed := &nyaafeeds.RssFeed{ Title: title, Link: config.WebAddress() + "/", - PubDate: createdAsTime.String(), + PubDate: formatRSSDate(createdAsTime), } feed.Items = make([]*nyaafeeds.RssItem, len(torrents)) @@ -36,7 +37,7 @@ func RSSHandler(c *gin.Context) { Title: torrentJSON.Name, Link: config.WebAddress() + "/download/" + torrentJSON.Hash, Description: string(torrentJSON.Description), - PubDate: torrent.Date.Format(time.RFC1123Z), + PubDate: formatRSSDate(torrent.Date), GUID: config.WebAddress() + "/view/" + strconv.FormatUint(uint64(torrentJSON.ID), 10), Enclosure: &nyaafeeds.RssEnclosure{ URL: config.WebAddress() + "/download/" + strings.TrimSpace(torrentJSON.Hash), @@ -57,3 +58,9 @@ func RSSHandler(c *gin.Context) { c.AbortWithError(http.StatusInternalServerError, writeErr) } } + +//Return date in an RFC 2822 format, the official one for RSS2 +func formatRSSDate(Date time.Time) string { + Date = Date.UTC() + return fmt.Sprintf("%.3s, %.2d %.3s %d %.2d:%.2d:%.2d +0000", Date.Weekday(), Date.Day(), Date.Month(), Date.Year(), Date.Hour(), Date.Minute(), Date.Second()) +} diff --git a/public/css/main.css b/public/css/main.css index 1eff2380..ee357997 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -2148,7 +2148,7 @@ table.multiple-upload { width: 150px; font-weight: bold; font-size: 14px!important; - padding: 5px 0; + padding: 5px 0; } .user-search { diff --git a/templates/admin/index.jet.html b/templates/admin/index.jet.html index a40e149f..7a70f0b7 100644 --- a/templates/admin/index.jet.html +++ b/templates/admin/index.jet.html @@ -24,7 +24,7 @@
- +
diff --git a/templates/admin/torrentlist.jet.html b/templates/admin/torrentlist.jet.html index dcabed90..4f3099c0 100644 --- a/templates/admin/torrentlist.jet.html +++ b/templates/admin/torrentlist.jet.html @@ -50,7 +50,7 @@ {{ if .Uploader }} - + {{ .Uploader.Username }} {{ else }}れんちょん{{end}} @@ -67,12 +67,12 @@
- +
{{ else }}
- +
{{ end }} diff --git a/templates/admin/userlist.jet.html b/templates/admin/userlist.jet.html index 9ca637a7..e2a5969e 100644 --- a/templates/admin/userlist.jet.html +++ b/templates/admin/userlist.jet.html @@ -19,7 +19,7 @@ {{if .ID > 0}}
- +
{{end}} diff --git a/templates/site/torrents/view.jet.html b/templates/site/torrents/view.jet.html index 32289a45..332d0f15 100644 --- a/templates/site/torrents/view.jet.html +++ b/templates/site/torrents/view.jet.html @@ -139,10 +139,16 @@ {{ if User.ID > 0}} {{ T("report_btn") }} {{ if User.HasAdmin()}} - {{ T("delete") }} +
+ + +
{{ T("edit") }} {{ else if User.CurrentUserIdentical(Torrent.UploaderID) }} - {{ T("delete") }} +
+ + +
{{ T("edit") }} {{end}} {{end}} @@ -184,7 +190,7 @@
{{idx}} - {{formatDateRFC(element.Date)}} + {{formatDate(element.Date, false)}}

0}}href="/user/{{element.UserID}}/{{element.Username}}"{{end}} class="comment-user">{{if element.Username == ""}}れんちょん{{else}}{{element.Username}}{{end}}

{{element.Content|raw}}

diff --git a/templates/site/user/edit.jet.html b/templates/site/user/edit.jet.html index 8a833574..715253ed 100644 --- a/templates/site/user/edit.jet.html +++ b/templates/site/user/edit.jet.html @@ -262,7 +262,7 @@ {{ if User.CurrentOrAdmin(UserProfile.ID) }}
- +
{{end}} {{end}}