Skip to content

Commit

Permalink
Merge branch 'dev' into generatetorrent
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiloutre committed Oct 16, 2017
2 parents edea8a8 + 2f0e06c commit 4ae6944
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 80 deletions.
31 changes: 24 additions & 7 deletions controllers/torrent/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/config"
"github.com/Stephen304/goscrape"
"github.com/gin-gonic/gin"
)
Expand All @@ -26,14 +27,21 @@ func GetStatsHandler(c *gin.Context) {
}

var Trackers []string
for _, line := range strings.Split(torrent.Trackers[3:], "&tr=") {
//Starts at character 3 because the three first characters are always "tr=" so we need to dismiss them
tracker, error := url.QueryUnescape(line)
if error == nil && tracker[:6] == "udp://" {
Trackers = append(Trackers, tracker)
if len(Trackers) > 3 {
for _, line := range strings.Split(torrent.Trackers[3:], "&tr=") {
tracker, error := url.QueryUnescape(line)
if error == nil && strings.Contains(tracker, "udp://") {
Trackers = append(Trackers, tracker)
}
//Cannot scrape from http trackers so don't put them in the array
}
//Cannot scrape from http trackers so don't put them in the array
}
}

for _, line := range config.Get().Torrents.Trackers.Default {
if !contains(Trackers, line) {
Trackers = append(Trackers, line)
}
}

stats := goscrape.Single(Trackers, []string{
torrent.Hash,
Expand Down Expand Up @@ -73,3 +81,12 @@ func GetStatsHandler(c *gin.Context) {

return
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
1 change: 1 addition & 0 deletions controllers/user/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
// User Profile specific routes
userRoutes := router.Get().Group("/user")
{
userRoutes.GET("", UserProfileHandler)
userRoutes.GET("/:id", UserProfileHandler)
userRoutes.GET("/:id/:username", UserProfileHandler)
userRoutes.GET("/:id/:username/follow", UserFollowHandler)
Expand Down
59 changes: 29 additions & 30 deletions models/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,37 +364,36 @@ func (t *Torrent) ToJSON() TorrentJSON {

t.ParseLanguages()
res := TorrentJSON{

ID: t.ID,
Name: t.Name,
Status: t.Status,
Hidden: t.Hidden,
Hash: t.Hash,
Date: t.Date.Format(time.RFC3339),
FullDate: t.Date,
Filesize: t.Filesize,
Description: sanitize.MarkdownToHTML(t.Description),
Comments: commentsJSON,
SubCategory: strconv.Itoa(t.SubCategory),
Category: strconv.Itoa(t.Category),
UploaderID: uploaderID,
UploaderName: sanitize.SafeText(uploader),
WebsiteLink: sanitize.Safe(t.WebsiteLink),
Languages: t.Languages,
Magnet: template.URL(magnet),
TorrentLink: sanitize.Safe(torrentlink),
Leechers: scrape.Leechers,
Seeders: scrape.Seeders,
Completed: scrape.Completed,
LastScrape: scrape.LastScrape,
ID: t.ID,
Name: t.Name,
Status: t.Status,
Hidden: t.Hidden,
Hash: t.Hash,
Date: t.Date.Format(time.RFC3339),
FullDate: t.Date,
Filesize: t.Filesize,
Description: sanitize.MarkdownToHTML(t.Description),
Comments: commentsJSON,
SubCategory: strconv.Itoa(t.SubCategory),
Category: strconv.Itoa(t.Category),
UploaderID: uploaderID,
UploaderName: sanitize.SafeText(uploader),
WebsiteLink: sanitize.Safe(t.WebsiteLink),
Languages: t.Languages,
Magnet: template.URL(magnet),
TorrentLink: sanitize.Safe(torrentlink),
Leechers: scrape.Leechers,
Seeders: scrape.Seeders,
Completed: scrape.Completed,
LastScrape: scrape.LastScrape,
StatsObsolete: statsObsolete,
FileList: fileListJSON,
Tags: t.Tags,
AnidbID: t.AnidbID,
VndbID: t.VndbID,
VgmdbID: t.VgmdbID,
Dlsite: t.Dlsite,
VideoQuality: t.VideoQuality,
FileList: fileListJSON,
Tags: t.Tags,
AnidbID: t.AnidbID,
VndbID: t.VndbID,
VgmdbID: t.VgmdbID,
Dlsite: t.Dlsite,
VideoQuality: t.VideoQuality,
}

// Split accepted tags
Expand Down
70 changes: 52 additions & 18 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ th {
width: 90px;
}

.tr-se, .tr-le, .tr-st, .torrent-view-data .tr-dl {
.tr-se, .tr-le, .tr-st, .torrent-view-data .tr-dl {
font-weight: bold;
}

Expand Down Expand Up @@ -854,7 +854,7 @@ html, body {
}
td.torrent-view-td.torrent-info-data {
padding-left: 5px;
width: auto;
width: auto;
}
.torrent-info-data {
width: 100%;
Expand Down Expand Up @@ -999,11 +999,11 @@ html, body {
display: none;
}
.torrent-view-data {
display: table!important;
}
.torrent-view-data td, .torrent-view-data table {
width: 100%!important;
}
display: table!important;
}
.torrent-view-data td, .torrent-view-data table {
width: 100%!important;
}
}

@media (max-width: 440px) {
Expand Down Expand Up @@ -1131,6 +1131,9 @@ html, body {
padding: 0 14px;
}

.comment-box blockquote {
margin: 0;
}
.comment-box blockquote>p {
opacity: 0.5;
}
Expand Down Expand Up @@ -2164,16 +2167,36 @@ table.multiple-upload {
}

.user-search {
word-spacing: -7px;;
word-spacing: -7px;
padding: 0 1rem;
position: relative;
}
.profile-panel .user-search {
padding: 0;
max-width: 170px;
}

.user-search [type="text"] {
vertical-align: top;
width: calc(100% - 28px);
width: calc(100% - 30px);
border-radius: 3px 0 0 3px;
}
.profile-panel .user-search [type="text"] {
margin-right: 28px;
}
.user-search button {
border-left: none;
border-radius: 0 3px 3px 0;
float: right;
position: absolute;
right: 0;
}
.box > .user-search button {
float: none;
position: relative;
}
.profile-content .user-search button {
right: 16px;
}

.torrent-info-row .tr-se span, .torrent-info-row .tr-le span, .torrent-info-row .tr-dl span {
Expand All @@ -2182,18 +2205,18 @@ table.multiple-upload {
}

.torrent-view-data {
display: flex;
display: flex;
}
.torrent-view-data table:first-child {
width: 65%;
.torrent-view-data table:first-child {
width: 65%;
}
.torrent-view-data table:last-child {
width: 35%;
.torrent-view-data table:last-child {
width: 35%;
}
.torrent-view-data table:last-child .torrent-info-label {
width: 42%;
.torrent-view-data table:last-child .torrent-info-label {
width: 42%;
}

.admin-content tr:hover a {
color: #d45a5a;
}
Expand All @@ -2202,7 +2225,7 @@ table.multiple-upload {
}

button [class^="icon-"], button [class*=" icon-"] {
vertical-align: top;
vertical-align: top;
}

form.delete-form {
Expand All @@ -2213,6 +2236,17 @@ form.delete-form button.form-input.btn-red {
height: 28px;
}

.user-torrent-table {
margin-bottom: 80px
}

.user-torrent-search {
width: 100%;
position: absolute;
right: 0;
left: 0;
bottom: 9px;
}

/* Language specific CSS */

Expand Down
6 changes: 3 additions & 3 deletions public/css/themes/classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ th.tr-name a {

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

.icon-floppy::before {
.icon-floppy:before {
content: '';
}
.icon-floppy {
Expand Down Expand Up @@ -425,7 +425,7 @@ span.comment-index+p a:hover {
float: right;
margin-top: 7px;
}
.torrent-buttons a{
.torrent-buttons a, .torrent-buttons button {
height: 26px!important;
background: linear-gradient(to bottom, #33ca98 0%, #336867 72%);
color: white!important;
Expand Down
5 changes: 5 additions & 0 deletions public/css/themes/g.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,8 @@ td.tr-le, .error-text {
background-color: #F7F8F9;
border-color: #cbbdd7;
}

.sukebei #cookie-warning {
background: hsla(297, 40%, 90%, 0.89);
border-top: 1px solid #c48cbe;
}
26 changes: 17 additions & 9 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var farFutureString
//Array that will contain the themes that the user will switch between when triggering the function a few lines under
var UserTheme

var Mirror = false

// Switches between themes when a new one is selected
function switchThemes() {
var themeName = document.getElementById("theme-selector").value
Expand Down Expand Up @@ -92,15 +94,16 @@ function resetCookies() {
//Get HostName without subDomain
var hostName = window.location.host

var lastDotIndex = hostName.lastIndexOf(".")
var secondLast = -1

for(var index = 0; index < lastDotIndex; index++) {
if(hostName[index] == '.')
secondLast = index
if(!Mirror) {
var lastDotIndex = hostName.lastIndexOf(".")
var secondLast = -1

for(var index = 0; index < lastDotIndex; index++) {
if(hostName[index] == '.')
secondLast = index
}
hostName = hostName.substr(secondLast == -1 ? 0 : secondLast)
}
hostName = hostName.substr(secondLast == -1 ? 0 : secondLast)
if(!hostName.includes(domain)) domain = window.location.host

for (var i = 0; i < cookies.length; i++) {
var cookieName = (cookies[i].split("=")[0]).trim()
Expand Down Expand Up @@ -152,14 +155,19 @@ function startupCode() {
if (location.hash) shiftWindow()
window.addEventListener("hashchange", shiftWindow)


if(!window.location.host.includes(domain)) {
domain = window.location.host
Mirror = true
}

if (!document.cookie.includes("commit") && !document.cookie.includes("version"))
resetCookies()
else {
var userCommitVersion = getCookieValue("commit"), userWebsiteVersion = getCookieValue("version");
if (userCommitVersion != commitVersion || userWebsiteVersion != websiteVersion)
resetCookies()
}
if(!window.location.host.includes(domain)) domain = window.location.host

if(document.getElementById("cookie-warning-close") != null) {
document.getElementById("cookie-warning-close").addEventListener("click", function (e) {
Expand Down
2 changes: 1 addition & 1 deletion templates/errors/user_not_found.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h1>{{T("user_not_found")}}</h1>
<p>{{if isset(Search.User) && Search.User != ""}}{{T("usersearch_user_not_found", Search.User)}}{{else}}{{T("user_search_explanation")}}{{end}}</p>
<div class="user-search">
<form role="search" action="/username" id="header-form" method="get">'
<form role="search" action="/username" id="header-form" method="get">
<input class="form-input" name="username" type="text" value="{{if isset(Search.User) && Search.User != ""}}{{Search.User}}{{end}}" placeholder="Search username..." style="width: calc(50% - 30px)">
<button type="submit" class="form-input icon-search"></button>
</form>
Expand Down
16 changes: 9 additions & 7 deletions templates/site/torrents/view.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,17 @@ <h1 style="text-align: center;" class="torrent-hr">{{Torrent.Name}}</h1>
<a id="reportPopup" href="#" class="form-input">{{ T("report_btn") }}</a>
{{ if User.HasAdmin()}}
<form method="POST" action="/mod/torrent/delete" class="delete-form">
<input type="hidden" name="id" value="{{ Torrent.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>
{{ yield csrf_field()}}
<input type="hidden" name="id" value="{{ Torrent.ID }}">
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }}{{ T("delete") }}')) return false;"><i class="icon-trash"></i>{{ T("delete") }}</button>
</form>
<a href="/mod/torrent?id={{ Torrent.ID }}" class="form-input btn-orange">{{ T("edit") }}</a>
{{ else if User.CurrentUserIdentical(Torrent.UploaderID) }}
<form method="POST" action="/torrent/delete" class="delete-form">
<input type="hidden" name="id" value="{{ Torrent.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>
{{ yield csrf_field()}}
<input type="hidden" name="id" value="{{ Torrent.ID }}">
<button type="submit" class="form-input btn-red" onclick="if (!confirm('{{ T(" are_you_sure ") }}{{ T("delete") }}')) return false;"><i class="icon-trash"></i>{{ T("delete") }}</button>
</form>
<a href="/torrent?id={{ Torrent.ID }}" class="form-input btn-orange">{{ T("edit") }}</a>
{{end}}
{{end}}
Expand Down Expand Up @@ -202,7 +204,7 @@ <h1 style="text-align: center;" class="torrent-hr">{{Torrent.Name}}</h1>
<div class="torrent-info-box comment-box">
<span class="comment-index">
<a href="#comment_{{idx}}">{{idx}}</a>
<small style="padding-left: 4px;" class="date-full" title="{{element.Date}}">{{formatDate(element.Date, false)}}</small>
<small style="padding-left: 4px;" class="date-short" title="{{formatDateRFC(element.Date)}}">{{formatDate(element.Date, false)}}</small>
</span>
<p><img src="https://www.gravatar.com/avatar/{{ element.UserAvatar }}"/><a {{if element.UserID > 0}}href="/user/{{element.UserID}}/{{element.Username}}"{{end}} class="comment-user">{{if element.Username == ""}}れんちょん{{else}}{{element.Username}}{{end}}</a></p>
<p class="comment-content">{{element.Content|raw}}</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/site/user/edit.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ <h2>{{ T("moderation")}}</h2>
<table class="user-edit-table">
<tbody>
<tr>
<td><label for="username">{{ T("moderation") }}:</label></td>
<td><label for="username">{{ T("username") }}:</label></td>
<td><input class="form-input up-input" name="username" id="username" type="text" value="{{UserProfile.Username}}"></td>
</tr>
<tr>
Expand Down
Loading

0 comments on commit 4ae6944

Please sign in to comment.