Skip to content

Commit

Permalink
Merge branch 'dev' into generatetorrent
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhal committed Oct 15, 2017
2 parents 447f89e + d3e50b8 commit edea8a8
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 71 deletions.
5 changes: 2 additions & 3 deletions controllers/feed/magnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/utils/feeds"
Expand All @@ -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))

Expand All @@ -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),
Expand Down
11 changes: 9 additions & 2 deletions controllers/feed/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"time"
"fmt"

"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/utils/feeds"
Expand All @@ -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))

Expand All @@ -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),
Expand All @@ -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())
}
32 changes: 21 additions & 11 deletions controllers/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"html"
"net/http"
"strconv"
"fmt"

"math"

Expand All @@ -14,15 +15,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)

// UserSearchHandler : Controller called when search done through user profile URL, userID parameters are accessed differently so we need this
func UserSearchHandler(c *gin.Context) {
query := c.Request.URL.Query()
query.Set("userID", c.Param("id"))
c.Request.URL.RawQuery = query.Encode()
SearchHandler(c)
}

// SearchHandler : Controller for displaying search result page, accepting common search arguments
func SearchHandler(c *gin.Context) {
var err error
Expand All @@ -44,25 +36,43 @@ func SearchHandler(c *gin.Context) {
return
}
}


searchForm := templates.NewSearchForm(c)

if c.Param("id") != "" {
query := c.Request.URL.Query()
query.Set("userID", c.Param("id"))
c.Request.URL.RawQuery = query.Encode()
searchForm.SearchURL = fmt.Sprintf("/user/%s/%s/search", c.Param("id"), c.Param("username"))
searchForm.UserName = c.Param("username") //Only add username if user search route
}

userID, err := strconv.ParseUint(c.Query("userID"), 10, 32)
if err != nil {
userID = 0
}

if userID == 0 && c.Param("id") != "" && c.Param("id") != "0" {
c.Redirect(http.StatusSeeOther, fmt.Sprintf("/user/%s/%s", c.Param("id"), c.Param("username")))
//User is trying to use the user search route with an inexisting user
//Must redirect him to user search instead of simply showing "no torrents found!"
}


searchParam, torrents, nbTorrents, err := search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrAdmin(uint(userID)))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}


// Convert back to strings for now.
category := ""
if len(searchParam.Category) > 0 {
category = searchParam.Category[0].String()
}
nav := templates.Navigation{int(nbTorrents), int(searchParam.Max), int(searchParam.Offset), "search"}
searchForm := templates.NewSearchForm(c)

searchForm.TorrentParam, searchForm.Category = searchParam, category

if c.Query("refine") == "1" {
Expand Down
4 changes: 2 additions & 2 deletions controllers/user/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func init() {
userRoutes.GET("/:id/:username/edit", UserDetailsHandler)
userRoutes.POST("/:id/:username/edit", UserProfileFormHandler)
userRoutes.GET("/:id/:username/apireset", UserAPIKeyResetHandler)
userRoutes.GET("/:id/:username/search", searchController.UserSearchHandler)
userRoutes.GET("/:id/:username/search/:page", searchController.UserSearchHandler)
userRoutes.GET("/:id/:username/search", searchController.SearchHandler)
userRoutes.GET("/:id/:username/search/:page", searchController.SearchHandler)
userRoutes.GET("/:id/:username/feed", feedController.RSSHandler)
userRoutes.GET("/:id/:username/feed/:page", feedController.RSSHandler)
userRoutes.POST("/:id/:username/delete", UserProfileDelete)
Expand Down
17 changes: 16 additions & 1 deletion public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,10 @@ input.filelist-checkbox:checked+table.table-filelist {

/* Mod Tools */

.content-admin .modtools {
display: block;
}

.modtools {
position: fixed;
top: 65px;
Expand All @@ -1375,6 +1379,8 @@ input.filelist-checkbox:checked+table.table-filelist {
border-style: solid;
height: 50px;
border-radius: 5px;
z-index: 1;
display: none;
}

.tr-cb {
Expand Down Expand Up @@ -2154,7 +2160,7 @@ table.multiple-upload {
width: 150px;
font-weight: bold;
font-size: 14px!important;
padding: 5px 0;
padding: 5px 0;
}

.user-search {
Expand Down Expand Up @@ -2199,6 +2205,15 @@ button [class^="icon-"], button [class*=" icon-"] {
vertical-align: top;
}

form.delete-form {
display: inline;
}

form.delete-form button.form-input.btn-red {
height: 28px;
}


/* Language specific CSS */

html[lang="ja-jp"] .form-refine span.spacing {
Expand Down
20 changes: 13 additions & 7 deletions public/css/themes/classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ body, .header {
margin-top: 0!important;
}
}
.modtools {
top: 43px;
}
.torrent-info-data {
font-family: Arial, sans-serif!important;
}
Expand Down Expand Up @@ -58,9 +61,6 @@ a:hover {
text-decoration: underline;
}

#content {
top: 31px!important;
}
.upload-form-table .checkbox-container+input {
width: 385px;
}
Expand Down Expand Up @@ -123,14 +123,20 @@ th.tr-name a {

.icon-magnet:before {
font-size: 14px;
}
}.upload-tag-table

.icon-floppy::before {
content: '';
}
.icon-floppy {
background: url("/img/dl-link.png") no-repeat center;
}

.upload-tag-table .input-label {
font-size: 12px;
}
.header, #header-height-offset {
height: 40px;
}
.header {
background: url("/img/topbar.png") repeat-x black;
background: linear-gradient(to bottom, #6d6d6d 0%, #000000 72%);
Expand Down Expand Up @@ -677,9 +683,9 @@ span.tag {
padding: 7px 3px;
}
.upload-tag-table .form-group {
margin-right: 8px;
margin-right: 11px;
}
.upload-tag-table .form-group input, .upload-tag-table .form-group select {
width: 118px!important;
width: 128px!important;
height: 20px;
}
6 changes: 6 additions & 0 deletions public/css/themes/tomorrow.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ a.form-input[class*="btn"]:hover {
background: #141517;
color: #c5c8c6;
}
.sukebei .pagination .active {
color: #ff5252;
}

.pagination .disabled {
color: #141517;
Expand Down Expand Up @@ -337,3 +340,6 @@ span.tag {
.admin-content tr:hover a {
color: #bbd2e6;
}
.sukebei .admin-content tr:hover a {
color: #ea8c8c;
}
6 changes: 4 additions & 2 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ function humanFileSize(bytes, si) {
}

function getCookieValue(cookieName) {
var startPos = document.cookie.indexOf(cookieName + "=") + cookieName.length + 1
var startPos = document.cookie.indexOf(cookieName + "=")
if(startPos == -1) return ""
startPos += cookieName.length + 1
var endPos = document.cookie.substring(startPos).indexOf(";")
return endPos == "-1" ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos)
return endPos == -1 ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos)
}

// @license-end
6 changes: 3 additions & 3 deletions templates/admin/announcements.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h1>{{ T("announcements") }}</h1>
<thead class="torrent-info">
<tr>
<th class="tr-name">{{ T("message") }}</th>
<th class="tr-links">{{ T("expire") }}</th>
<th class="tr-links" style="width: 120px;">{{ T("expire") }}</th>
<th class="tr-actions">{{ T("actions") }}</th>
</tr>
</thead>
Expand All @@ -18,7 +18,7 @@ <h1>{{ T("announcements") }}</h1>
<a href="/mod/announcement/form?id={{ .ID }}">{{ .Content }}</a>
</td>
<td class="tr-name home-td">
<a href="/mod/announcement/form?id={{ .ID }}">{{ .Expire }}</a>
<a href="/mod/announcement/form?id={{ .ID }}" class="date-full">{{ formatDate(.Expire, false) }}</a>
</td>
<td class="tr-actions home-td">
<form method="POST" action="/mod/announcement/delete">
Expand All @@ -30,6 +30,6 @@ <h1>{{ T("announcements") }}</h1>
{{end}}
</tbody>
</table>
<a href="/mod/announcement/form" class="form-input btn-green">{{ T("add") }}</a>
<div style="margin: 10px 0;"><a href="/mod/announcement/form" class="form-input btn-green">{{ T("add") }}</a></div>
</div>
{{end}}
4 changes: 3 additions & 1 deletion templates/admin/index.jet.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ extends "layouts/index_admin" }}
{{ import "layouts/partials/helpers/csrf" }}
{{ block title()}}{{ T("moderation_overview") }}{{end}}
{{ block content_body()}}
<div class="results box">
Expand All @@ -24,7 +25,7 @@ <h3 id="torrents">{{ T("last_torrents") }}</h3>
<td class="tr-size home-td">
<form method="POST" action="/mod/torrent/delete">
<input type="hidden" name="id" value="{{ .ID }}">
<button type="submit" class="form-input btn-red"onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete") }}</button>
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete") }}</button>
</form>
</td>
</tr>
Expand Down Expand Up @@ -89,6 +90,7 @@ <h3 id="users">{{ T("last_users") }}</h3>
</td>
<td class="tr-size home-td">{{if .ID > 0}}
<form method="POST" action="/user/{{.ID}}/{{.Username }}/delete" >
{{ yield csrf_field()}}
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete") }}</button>
</form>
{{end}}
Expand Down
16 changes: 8 additions & 8 deletions templates/admin/torrent_report.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ <h1>{{ T("reports_list") }}</h1>
<td class="tr-size home-td">{{.User.Username}}</td>
<td class="tr-actions home-td">{{ getReportDescription(.Description, T) }}</td>
<td class="tr-actions home-td">
<form method="POST" action="/mod/torrent/delete">
<input type="hidden" name="id" value="{{ .Torrent }}">
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete_torrent") }}</button>
</form>
<form method="POST" action="/mod/report/delete">
<input type="hidden" name="id" value="{{ .ID }}">
<button type="submit" class="form-input btn-red"><i class="icon-trash"></i> {{ T("delete_report") }}</button>
</form>
<form method="POST" action="/mod/torrent/delete">
<input type="hidden" name="id" value="{{ .Torrent }}">
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete_torrent") }}</button>
</form>
<form method="POST" action="/mod/report/delete">
<input type="hidden" name="id" value="{{ .ID }}">
<button type="submit" class="form-input btn-red"><i class="icon-attention"></i> {{ T("delete_report") }}</button>
</form>
</td>
</tr>
{{end}}
Expand Down
21 changes: 7 additions & 14 deletions templates/admin/torrentlist.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h1>{{ T("torrents_list") }}</h1>
</td>
<td class="tr-size home-td">
{{ if .Uploader }}
<a href="/torrents{{ if .IsDeleted }}/deleted{{end}}?userID={{.UploaderID}}">
<a href="/user/{{.UploaderID}}/{{.Uploader.Username}}">
{{ .Uploader.Username }}
</a> {{ else }}れんちょん{{end}}
</td>
Expand All @@ -62,19 +62,12 @@ <h1>{{ T("torrents_list") }}</h1>
{{ T("torrent_block") }}
{{end}}
</a>
{{ if .IsDeleted }}
<br/>
<form method="POST" action="/mod/torrent/delete">
<input type="hidden" name="id" value="{{ .ID }}">
<input type="hidden" name="definitely" value="true">
<button type="submit" class="form-input btn-red"onclick="if (!confirm('{{ T(" are_you_sure ") }} {{ T("delete_definitely_torrent_warning ")}}')) return false;"><i class="icon-trash"></i> {{ T("delete_definitely") }}</button>
</form>
{{ else }}
<form method="POST" action="/mod/torrent/delete">
<input type="hidden" name="id" value="{{ .ID }}">
<button type="submit" class="form-input btn-red"onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete") }}</button>
</form>
{{ end }}
<form method="POST" action="/mod/torrent/delete" class="delete-form">
<input type="hidden" name="id" value="{{ .ID }}">
{{ if .IsDeleted }}<input type="hidden" name="definitely" value="true">{{ end }}
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }} {{ if !.IsDeleted }}{{ T("delete") }}{{else}}{{ T("delete_definitely_torrent_warning ")}}{{end}}')) return false;"><i class="icon-trash"></i>{{ if .IsDeleted }}{{ T("delete_definitely") }}{{else}}{{ T("delete") }}{{end}}</button>
</form>

</td>
</tr>
{{end}}
Expand Down
4 changes: 3 additions & 1 deletion templates/admin/userlist.jet.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ extends "layouts/index_admin" }}
{{ import "layouts/partials/helpers/csrf" }}
{{block title()}}{{ T("users_list") }}{{end}}
{{ block content_body()}}
<div class="results box">
Expand All @@ -19,7 +20,8 @@ <h1>{{ T("users_list") }}</h1>
<td class="tr-actions home-td">
{{if .ID > 0}}
<form method="POST" action="/user/{{.ID}}/{{.Username }}/delete">
<button type="submit" class="form-input btn-red"onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete") }}</button>
{{ yield csrf_field()}}
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }}')) return false;"><i class="icon-trash"></i> {{ T("delete") }}</button>
</form>
{{end}}
</td>
Expand Down
Loading

0 comments on commit edea8a8

Please sign in to comment.