Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge branch 'dev' into dev

Cette révision appartient à :
PantsuDev 2017-05-13 12:24:55 +10:00 révisé par GitHub
révision 0ae488e7eb
15 fichiers modifiés avec 101 ajouts et 49 suppressions

Voir le fichier

@ -11,7 +11,7 @@ that anyone will be able to deploy locally or remotely.
# Installation
Ubuntu 17.04 fails to build, use a different OS or docker
* Install [Golang](https://golang.org/doc/install)
* Install [Golang](https://golang.org/doc/install) (version >=1.8)
* `go get github.com/ewhal/nyaa`
* `go build`
* Download DB and place it in your root folder named as "nyaa.db"

Voir le fichier

@ -16,4 +16,4 @@ const (
EmailTimeout = 10 * time.Second
)
var EmailTokenHashKey = []byte("CHANGE_THIS_BEFORE_DEPLOYING_YOU_RETARD")
var EmailTokenHashKey = []byte("CHANGE_THIS_BEFORE_DEPLOYING_YOU_GIT")

Voir le fichier

@ -38,8 +38,8 @@ func RunServer(conf *config.Config) {
// Set up server,
srv := &http.Server{
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
WriteTimeout: 24 * time.Second,
ReadTimeout: 8 * time.Second,
}
l, err := network.CreateHTTPListener(conf)
log.CheckError(err)

Voir le fichier

@ -33,7 +33,8 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
htv := PanelIndexVbs{torrents, model.TorrentReportsToJSON(torrentReports), users, comments, NewSearchForm(), currentUser, r.URL}
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
err := panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
log.CheckError(err)
} else {
http.Error(w, "admins only", http.StatusForbidden)
}
@ -217,7 +218,8 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
}
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
htv := PanelTorrentEdVbs{uploadForm, NewSearchForm(), currentUser, err, infos, r.URL}
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
err_ := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
log.CheckError(err_)
}
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {

Voir le fichier

@ -6,7 +6,6 @@ import (
"github.com/ewhal/nyaa/util/search"
"github.com/gorilla/feeds"
"net/http"
"strconv"
"time"
)
@ -31,7 +30,7 @@ func RSSHandler(w http.ResponseWriter, r *http.Request) {
for i, torrent := range torrents {
torrentJSON := torrent.ToJSON()
feed.Items[i] = &feeds.Item{
Id: "https://" + config.WebAddress + "/view/" + strconv.FormatUint(uint64(torrents[i].ID), 10),
Id: "https://" + config.WebAddress + "/view/" + torrentJSON.ID,
Title: torrent.Name,
Link: &feeds.Link{Href: string(torrentJSON.Magnet)},
Description: string(torrentJSON.Description),

Voir le fichier

@ -26,6 +26,16 @@ var FuncMap = template.FuncMap{
}
return "error"
},
"genViewTorrentRoute": func(torrent_id uint) string {
// Helper for when you have an uint while genRoute("view_torrent", ...) takes a string
// FIXME better solution?
s := strconv.FormatUint(uint64(torrent_id), 10)
url, err := Router.Get("view_torrent").URL("id", s)
if err == nil {
return url.String()
}
return "error"
},
"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
var ret = ""
if (nav.TotalItem > 0) {

Voir le fichier

@ -46,4 +46,4 @@ func (wh *wrappedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func wrapHandler(handler http.Handler) http.Handler {
return &wrappedHandler{handler}
}
}

Voir le fichier

@ -129,9 +129,10 @@ func getTorrentsOrderBy(parameters *serviceBase.WhereParams, orderBy string, lim
if conditions != "" {
dbQuery = dbQuery + " WHERE " + conditions
}
if strings.Contains(conditions, "torrent_name") {
/* This makes all queries take roughly the same amount of time (lots)...
if strings.Contains(conditions, "torrent_name") && offset > 0 {
dbQuery = "WITH t AS (SELECT * FROM torrents WHERE " + conditions + ") SELECT * FROM t"
}
}*/
if orderBy == "" { // default OrderBy
orderBy = "torrent_id DESC"

Voir le fichier

@ -7,9 +7,12 @@
<th class="col-xs-1">Uploader</th>
<th class="col-xs-1">Action</th>
</tr>
{{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userID={{.UploaderID}}">{{ .UploaderID }}</a></td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td></tr>
{{range .Torrents}}
<tr>
<td><a href="{{ genViewTorrentRoute .ID }}">{{ .Name }}</a> (<a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">Edit</a>)</td>
<td><a href="{{ genRoute "mod_tlist" }}?userID={{.UploaderID}}">{{ .UploaderID }}</a></td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td>
</tr>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">
@ -21,7 +24,6 @@
<h3 id="torrents">Last Torrents Report</h3>
<table class="table">
{{ range .TorrentReports}}
<tr>
<th class="col-xs-9">Torrent Name</th>
<th class="col-xs-1">User</th>
@ -29,8 +31,13 @@
<th class="col-xs-1">Action</th>
</tr>
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">{{ .Torrent.Name }}</a></td><td>{{.User.Username}}</td><td>{{.Description}}</td>
<td><a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td></tr>
{{range .TorrentReports}}
<tr>
<td><a href="{{ genRoute "view_torrent" "id" .Torrent.ID }}">{{ .Torrent.Name }}</a> (<a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">Edit</a>)</td>
<td>{{.User.Username}}</td>
<td>{{.Description}}</td>
<td><a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td>
</tr>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">

Voir le fichier

@ -8,12 +8,12 @@
<th class="col-xs-1">Action</th>
</tr>
{{ range .TorrentReports}}
{{range .TorrentReports}}
<tr>
<td><a href="{{ genRoute "mod_tedit"}}?id={{.Torrent.ID}}">{{.Torrent.Name}}</a></td>
<td><a href="{{ genRoute "view_torrent" "id" .Torrent.ID }}">{{ .Torrent.Name }}</a> (<a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">Edit</a>)</td>
<td>{{.User.Username}}</td>
<td>{{.Description}}</td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}" onclick="if (!confirm('Are you sure?')) return false;">Delete</a><br />
<a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}">Delete Report</a></td>
</tr>
{{end}}

Voir le fichier

@ -10,9 +10,11 @@
</tr>
{{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userID={{.UploaderID}}">{{ .UploaderID }}</a></td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td></tr>
<tr>
<td><a href="{{ genViewTorrentRoute .ID }}">{{ .Name }}</a> (<a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">Edit</a>)</td>
<td><a href="{{ genRoute "mod_tlist" }}?userID={{.UploaderID}}">{{ .UploaderID }}</a></td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td>
</tr>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">

Voir le fichier

@ -35,6 +35,7 @@
{{ if HasAdmin $.User}}
<a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i></a>
<a href="{{ genRoute "mod_tedit" }}?id={{ .ID }}" class="btn btn-warning btn-lg"><i class="glyphicon glyphicon-pencil"></i></a>
{{end}}
</div>
<div style="clear: both;"></div>

Voir le fichier

@ -225,7 +225,7 @@
},
{
"id": "notice_keep_seeding",
"translation": "NOTICE: KEEP SEEDING AND ENABLE DHT YOU RETARD"
"translation": "NOTICE: KEEP SEEDING AND ENABLE DHT YOU GIT"
},
{
"id": "official_nyaapocalipse_faq",
@ -273,7 +273,7 @@
},
{
"id": "answer_is_sukebei_db_lost",
"translation": "Sukebei, however might be in worse shape. Currently we only have sukebei databases up to 2016, but a newer database might be available for use."
"translation": "Sukebei is safe too, and almost nothing is lost either."
},
{
"id": "how_are_we_recovering",
@ -317,7 +317,7 @@
},
{
"id": "answer_how_can_i_help",
"translation": "If you have website development expertise, you can join the #nyaapantsu IRC channel on irc.rizon.net. If you have any current databases, especially for sukebei, <b>UPLOAD THEM</b>."
"translation": "If you have website development expertise, you can join the #nyaapantsu IRC channel on irc.rizon.net. If you have any current databases, especially for sukebei, please upload them."
},
{
"id": "your_design_sucks_found_a_bug",

Voir le fichier

@ -25,7 +25,7 @@
},
{
"id":"signup_box_title",
"translation": "登録しましょう。<small>ずっと無料です</small>"
"translation": "登録 <small>ずっと無料です</small>"
},
{
"id":"username",
@ -81,7 +81,7 @@
},
{
"id":"sign_in_box_title",
"translation": "ログインします"
"translation": "ログイン"
},
{
"id":"sign_in_title",
@ -125,7 +125,7 @@
},
{
"id":"see_more_torrents_from",
"translation": "%s の Torrent をもっと見る"
"translation": "%s の Torrent をもっと表示"
},
{
"id":"category",
@ -181,7 +181,7 @@
},
{
"id": "404_not_found",
"translation": "404 見つかりません"
"translation": "404 ページが見つかりません"
},
{
"id": "no_torrents_uploaded",
@ -197,7 +197,7 @@
},
{
"id": "member",
"translation": "メンバー"
"translation": "会員"
},
{
"id": "sign_in",
@ -217,11 +217,11 @@
},
{
"id": "official_nyaapocalipse_faq",
"translation": "nyaa.se の閉鎖についてよくある質問"
"translation": "公式 nyaa <ruby>黙示録<rp>(</rp><rt>アポカリプス</rt><rp>)</rp></ruby> のよくある質問"
},
{
"id": "links_replacement_mirror",
"translation": "nyaa.se のミラーリンク"
"translation": "代替 / ミラーリンク"
},
{
"id": "what_happened",
@ -233,7 +233,7 @@
},
{
"id": "its_not_a_ddos",
"translation": "以前のような DDoS 攻撃ではなく、ドメインが利用停止になった。"
"translation": "いつものような DDoS 攻撃ではなく、利用停止になった。"
},
{
"id": "future_not_looking_good",
@ -269,7 +269,7 @@
},
{
"id": "answer_how_are_we_recovering",
"translation": "上述のデータベースは nyaa.pantsu.cat と sukebei.pantsu.cat にホストされています。検索機能はすでにあり、nyaa.se にあったほぼすべての機能が近いうちに利用可能になるでしょう。また、Seeder / Leecher 統計はスクレイピングによって収集可能ですが、今は他に優先すべきことがあるため後回しにされます。"
"translation": "上述のデータベースは nyaa.pantsu.cat と sukebei.pantsu.cat にホストされています。検索機能はすでにあり、近いうちに nyaa.se にあったほぼすべての機能が利用可能になるでしょう。また、Seeder / Leecher 統計はスクレイピングによって収集可能ですが、今は他に優先すべきことがあるため後回しにされます。"
},
{
"id": "are_the_trackers_working",
@ -277,15 +277,15 @@
},
{
"id": "answer_are_the_trackers_working",
"translation": "トラッカーがダウンしたとしても、シーダーはまだ DHT ネットワークに接続しているはずです。ファイルが DHT ネットワーク上にリスティングされてさえいれば、いつも通り利用できます。"
"translation": "トラッカーがダウンしたとしても、Seeder はまだ DHT ネットワークに接続しているはずです。ファイルが DHT ネットワーク上にリスティングされてさえいれば、いつも通り利用できます。"
},
{
"id": "how_do_i_download_the_torrents",
"translation": "どうやって Torrent ファイルをダウンロードすればいいの?"
"translation": "どうやって Torrent をダウンロードすればいいの?"
},
{
"id": "answer_how_do_i_download_the_torrents",
"translation": "<b>magnet リンク</b> をご利用ください。magnet リンクは BitTorrent クライアントが DHT ネットワーク上のファイルを見つけるのに利用されます。もちろんいつも通りダウンロードすることができます。"
"translation": "<b>magnet リンク</b> をご利用ください。magnet リンクは BitTorrent クライアントが DHT ネットワーク上のファイルを検出するのに利用されます。もちろんいつも通りダウンロードすることができます。"
},
{
"id": "magnet_link_should_look_like",
@ -329,7 +329,7 @@
},
{
"id": "uploading_file_prefills_fields",
"translation": "Torrent ファイルをアップロードしている間にいくつかの項目を入力できます。そうすることをおすすめします。"
"translation": "Torrent ファイルをアップロードする前にいくつかの項目を入力できます。そうすることをお勧めします。"
},
{
"id": "magnet_link",
@ -521,7 +521,7 @@
},
{
"id": "trusted_member",
"translation": "信頼されたメンバー"
"translation": "信頼された会員"
},
{
"id": "moderator",
@ -594,5 +594,16 @@
{
"id": "language_name",
"translation": "日本語"
},
"id": "seeders",
"translation": "Seeder 数"
},
{
"id": "leechers",
"translation": "Leecher 数"
},
{
"id": "completed",
"translation": "完了数"
}
]

Voir le fichier

@ -18,17 +18,31 @@ import (
)
var searchOperator string
var useTSQuery bool
func Configure(conf *config.SearchConfig) (err error) {
// SQLite has case-insensitive LIKE, but no ILIKE
if db.ORM.Dialect().GetName() == "sqlite3" {
searchOperator = "LIKE ?"
} else {
useTSQuery = false
// Postgres needs ILIKE for case-insensitivity
if db.ORM.Dialect().GetName() == "postgres" {
searchOperator = "ILIKE ?"
//useTSQuery = true
// !!DISABLED!! because this makes search a lot stricter
// (only matches at word borders)
} else {
searchOperator = "LIKE ?"
}
return
}
func stringIsAscii(input string) bool {
for _, char := range input {
if char > 127 {
return false
}
}
return true
}
func SearchByQuery(r *http.Request, pagenum int) (search common.SearchParam, tor []model.Torrent, count int, err error) {
search, tor, count, err = searchByQuery(r, pagenum, true)
return
@ -164,7 +178,7 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool) (
}
searchQuerySplit := strings.Fields(search.Query)
for i, word := range searchQuerySplit {
for _, word := range searchQuerySplit {
firstRune, _ := utf8.DecodeRuneInString(word)
if len(word) == 1 && unicode.IsPunct(firstRune) {
// some queries have a single punctuation character
@ -175,9 +189,14 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool) (
continue
}
// TODO: make this faster ?
conditions = append(conditions, "torrent_name "+searchOperator)
parameters.Params = append(parameters.Params, "%"+searchQuerySplit[i]+"%")
if useTSQuery && stringIsAscii(word) {
conditions = append(conditions, "torrent_name @@ plainto_tsquery(?)")
parameters.Params = append(parameters.Params, word)
} else {
// TODO: possible to make this faster?
conditions = append(conditions, "torrent_name "+searchOperator)
parameters.Params = append(parameters.Params, "%"+word+"%")
}
}
parameters.Conditions = strings.Join(conditions[:], " AND ")
@ -194,4 +213,4 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool) (
return
})
return
}
}