From 9d45926025f16ce3c6145018aaa31fdfa27f814e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 5 May 2017 12:59:56 +0200 Subject: [PATCH 1/6] Make spoiler tags work --- js/main.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/main.js b/js/main.js index 32833ac8..04089014 100644 --- a/js/main.js +++ b/js/main.js @@ -28,3 +28,11 @@ document.getElementById('page-next').href = pageString + next + query; document.getElementById('page-prev').href = pageString + prev + query; + +// Used by spoiler tags +function toggleLayer(elem) { + if (elem.classList.contains("hide")) + elem.classList.remove("hide"); + else + elem.classList.add("hide"); +} From e7a189f5893c072a2cb4ed237138878f951dcb20 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 5 May 2017 21:06:41 +1000 Subject: [PATCH 2/6] Comment out itorrents link --- templates/home.html | 8 ++++---- templates/view.html | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/templates/home.html b/templates/home.html index a27aa24c..0c47a7b9 100644 --- a/templates/home.html +++ b/templates/home.html @@ -32,9 +32,9 @@ - - - + {{end}} @@ -45,4 +45,4 @@ -{{end}} \ No newline at end of file +{{end}} diff --git a/templates/view.html b/templates/view.html index 3f085593..b113c36b 100644 --- a/templates/view.html +++ b/templates/view.html @@ -28,7 +28,8 @@ Links - + @@ -38,4 +39,4 @@ {{end}} -{{end}} \ No newline at end of file +{{end}} From e5247affbdd9589f0cefb9138b4a26f4e34ff272 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 5 May 2017 13:07:18 +0200 Subject: [PATCH 3/6] Reorder trackers Many torrents (notably: HorribleSubs) use coppersurfer as their primary tracker, knowing this it makes sense to put it first. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 9d69cc98..4335c4ab 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( var db *gorm.DB var router *mux.Router var debugLogger *log.Logger -var trackers = "&tr=udp://zer0day.to:1337/announce&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://explodie.org:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=http://tracker.baka-sub.cf/announce" +var trackers = "&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://zer0day.to:1337/announce&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://explodie.org:6969&tr=udp://tracker.opentrackr.org:1337&tr=http://tracker.baka-sub.cf/announce" func getDBHandle() *gorm.DB { dbInit, err := gorm.Open("sqlite3", "./nyaa.db") From 84e8ea53ad0847249f5534a666566d1de79d83e1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 5 May 2017 13:19:36 +0200 Subject: [PATCH 4/6] Update FAQ --- css/style.css | 2 +- templates/FAQ.html | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/css/style.css b/css/style.css index 8f43a117..1832da65 100644 --- a/css/style.css +++ b/css/style.css @@ -15,7 +15,7 @@ nav#mainmenu { position: fixed; color: white; width: 100%; - z-index: 2; + z-index: 3; } nav#mainmenu a { color: white; diff --git a/templates/FAQ.html b/templates/FAQ.html index 029256b8..f7403c6c 100644 --- a/templates/FAQ.html +++ b/templates/FAQ.html @@ -1,28 +1,31 @@ {{define "title"}}FAQ{{end}} {{define "content"}}
-

NOTICE: KEEP SEEDING YOU RETARD

+ +

NOTICE: KEEP SEEDING YOU RETARD

Official Nyaapocalypse FAQ

+

Links for the replacement/mirror

- Nyaa - nyaa.pantsu.cat + Nyaa - nyaa.pantsu.cat
Sukebei - sukebei.pantsu.cat

What happened?

    -
  • - nyaa.se and associated domains (such nyaatorrents.info) went offline on May 01, 2017.
  • -
  • - They were deactivated, so it's not a DDoS attack like usual.
  • -
  • - Future prospects for nyaa are not looking good.
  • -
  • - There is a recovery effort taking place.
  • +
  • nyaa.se and associated domains (such as nyaatorrents.info) went offline on May 01, 2017.
  • +
  • They were deactivated, so it's not a DDoS attack like usual.
  • +
  • Future prospects for nyaa are not looking good.
  • +
  • There is a recovery effort taking place.
-

Is everything Lost?

+

Is everything lost?

In short, No.

Are some things lost?

-

We have a database of the torrents on nyaa up to April 5. That means that everything past April 5 is gone. - Sukebei, however is in worse shape. We only have sukebei databases up to 2016.

+

We have a database of the torrents on nyaa up to April 5 May 1. That means almost nothing is lost.

+

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.

How are we recovering?

The aforementioned databases are being hosted at nyaa.pantsu.cat and sukebei.pantsu.cat. @@ -38,11 +41,16 @@

Just use the magnet link. The magnet link will used by your BitTorrent client to look up the file on the DHT network and it should download just fine.

If your magnet link starts with "magnet:magnet:", delete the first "magnet:". It should look like: - magnet:?xt=urn:btih:[hash]&dn=[name]&tr=[tracker]

+ magnet:?xt=urn:btih:[hash]&dn=[name]&tr=[tracker]&tr=[...]

-

How can I help?

-

If you have website development expertise, you can join the #nyaapantsu IRC channel on irc.rizon.net. If you have any current databases, UPLOAD THEM.

+

How can I help?

+

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, UPLOAD THEM.

-

nyaa.pantsu.cat and sukebei.pantsu.cat do not host any files.

+

Your design sucks / I found a bug

+

https://github.com/ewhal/nyaa/issues.

+ +
+

nyaa.pantsu.cat and sukebei.pantsu.cat do not host any files.

-{{end}} \ No newline at end of file +{{end}} From 6304c447fd48606aaeb1b10129bcc49ba5c0fe74 Mon Sep 17 00:00:00 2001 From: Owner Date: Fri, 5 May 2017 13:37:22 +0200 Subject: [PATCH 5/6] RSS feeds for specific search queries. --- main.go | 135 ++++++++++++++++++++++++++++++------------------------ models.go | 29 ------------ 2 files changed, 74 insertions(+), 90 deletions(-) diff --git a/main.go b/main.go index 9d69cc98..3c669d7f 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,15 @@ import ( "time" ) +type SearchParam struct { + Category string + Order string + Query string + Max int + Status string + Sort string +} + var db *gorm.DB var router *mux.Router var debugLogger *log.Logger @@ -108,38 +117,64 @@ func searchHandler(w http.ResponseWriter, r *http.Request) { page := vars["page"] // db params url - maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")) - if errConv != nil { - maxPerPage = 50 // default Value maxPerPage - } pagenum, _ := strconv.Atoi(html.EscapeString(page)) if pagenum == 0 { pagenum = 1 } - searchQuery := r.URL.Query().Get("q") - cat := r.URL.Query().Get("c") - stat := r.URL.Query().Get("s") - sort := r.URL.Query().Get("sort") - order := r.URL.Query().Get("order") + + b := []TorrentsJson{} + + search_param, torrents, nbTorrents := searchByQuery( r, pagenum ) - catsSplit := strings.Split(cat, "_") + for i, _ := range torrents { + res := torrents[i].toJson() + b = append(b, res) + } + + navigationTorrents := Navigation{nbTorrents, search_param.Max, pagenum, "search_page"} + searchForm := SearchForm{ + search_param.Query, + search_param.Status, + search_param.Category, + search_param.Sort, + search_param.Order, + } + htv := HomeTemplateVariables{b, getAllCategories(false), searchForm, navigationTorrents, r.URL, mux.CurrentRoute(r)} + + err := templates.ExecuteTemplate(w, "index.html", htv) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} + +func searchByQuery(r *http.Request, pagenum int) (SearchParam, []Torrents, int) { + maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")) + if errConv != nil { + maxPerPage = 50 // default Value maxPerPage + } + + search_param := SearchParam{} + search_param.Max = maxPerPage + search_param.Query = r.URL.Query().Get("q") + search_param.Category = r.URL.Query().Get("c") + search_param.Status = r.URL.Query().Get("s") + search_param.Sort = r.URL.Query().Get("sort") + search_param.Order = r.URL.Query().Get("order") + + catsSplit := strings.Split(search_param.Category, "_") // need this to prevent out of index panics var searchCatId, searchSubCatId string if len(catsSplit) == 2 { searchCatId = html.EscapeString(catsSplit[0]) searchSubCatId = html.EscapeString(catsSplit[1]) } - if sort == "" { - sort = "torrent_id" + if search_param.Sort == "" { + search_param.Sort = "torrent_id" } - if order == "" { - order = "desc" + if search_param.Order == "" { + search_param.Order = "desc" } - order_by := sort + " " + order - - nbTorrents := 0 - - b := []TorrentsJson{} + order_by := search_param.Sort + " " + search_param.Order parameters := WhereParams{} conditions := []string{} @@ -151,11 +186,11 @@ func searchHandler(w http.ResponseWriter, r *http.Request) { conditions = append(conditions, "sub_category_id = ?") parameters.params = append(parameters.params, searchSubCatId) } - if stat != "" { + if search_param.Status != "" { conditions = append(conditions, "status_id = ?") - parameters.params = append(parameters.params, stat) + parameters.params = append(parameters.params, search_param.Status) } - searchQuerySplit := strings.Split(searchQuery, " ") + searchQuerySplit := strings.Split(search_param.Query, " ") for i, _ := range searchQuerySplit { conditions = append(conditions, "torrent_name LIKE ?") parameters.params = append(parameters.params, "%"+searchQuerySplit[i]+"%") @@ -163,22 +198,10 @@ func searchHandler(w http.ResponseWriter, r *http.Request) { parameters.conditions = strings.Join(conditions[:], " AND ") log.Printf("SQL query is :: %s\n", parameters.conditions) - torrents, nbTorrents := getTorrentsOrderBy(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1)) - - for i, _ := range torrents { - res := torrents[i].toJson() - b = append(b, res) - } - - navigationTorrents := Navigation{nbTorrents, maxPerPage, pagenum, "search_page"} - searchForm := SearchForm{searchQuery, stat, cat, sort, order} - htv := HomeTemplateVariables{b, getAllCategories(false), searchForm, navigationTorrents, r.URL, mux.CurrentRoute(r)} - - err := templates.ExecuteTemplate(w, "index.html", htv) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } + torrents, n := getTorrentsOrderBy(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1)) + return search_param, torrents, n } + func safe(s string) template.URL { return template.URL(s) } @@ -193,20 +216,10 @@ func faqHandler(w http.ResponseWriter, r *http.Request) { } func rssHandler(w http.ResponseWriter, r *http.Request) { - //vars := mux.Vars(r) - //category := vars["c"] - - // db params url - //maxPerPage := 50 // default Value maxPerPage - - torrents := getFeeds() - created := time.Now().String() + _, torrents, _ := searchByQuery( r, 1 ) + created_as_time := time.Now() if len(torrents) > 0 { - created = torrents[0].Timestamp - } - created_as_time, err := time.Parse("2006-01-02 15:04:05", created) - if err == nil { - + created_as_time = time.Unix(torrents[0].Date, 0) } feed := &feeds.Feed{ Title: "Nyaa Pantsu", @@ -217,17 +230,16 @@ func rssHandler(w http.ResponseWriter, r *http.Request) { feed.Items = make([]*feeds.Item, len(torrents)) for i, _ := range torrents { - timestamp_as_time, err := time.Parse("2006-01-02 15:04:05", torrents[i].Timestamp) - if err == nil { - feed.Items[i] = &feeds.Item{ - // need a torrent view first - //Id: URL + torrents[i].Hash, - Title: torrents[i].Name, - Link: &feeds.Link{Href: string(torrents[i].Magnet)}, - Description: "", - Created: timestamp_as_time, - Updated: timestamp_as_time, - } + timestamp_as_time := time.Unix(torrents[0].Date, 0) + torrent_json := torrents[i].toJson() + feed.Items[i] = &feeds.Item{ + // need a torrent view first + //Id: URL + torrents[i].Hash, + Title: torrents[i].Name, + Link: &feeds.Link{Href: string(torrent_json.Magnet)}, + Description: "", + Created: timestamp_as_time, + Updated: timestamp_as_time, } } @@ -238,6 +250,7 @@ func rssHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) } } + func viewHandler(w http.ResponseWriter, r *http.Request) { var templates = template.Must(template.ParseFiles("templates/index.html", "templates/view.html")) templates.ParseGlob("templates/_*.html") // common diff --git a/models.go b/models.go index 8580932c..52cf0ba3 100644 --- a/models.go +++ b/models.go @@ -10,14 +10,6 @@ import ( "time" ) -type Feed struct { - Id int - Name string - Hash string - Magnet string - Timestamp string -} - type Categories struct { Id int `gorm:"column:category_id"` Name string `gorm:"column:category_name"` @@ -97,27 +89,6 @@ type WhereParams struct { * */ -// don't need raw SQL once we get MySQL -func getFeeds() []Feed { - var result []Feed - rows, err := db.DB(). - Query( - "SELECT `torrent_id` AS `id`, `torrent_name` AS `name`, `torrent_hash` AS `hash`, `timestamp` FROM `torrents` " + - "ORDER BY `timestamp` desc LIMIT 50") - if err == nil { - for rows.Next() { - item := Feed{} - rows.Scan(&item.Id, &item.Name, &item.Hash, &item.Timestamp) - magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(item.Hash) + "&dn=" + item.Name + trackers - item.Magnet = magnet - // memory hog - result = append(result, item) - } - rows.Close() - } - return result -} - func getTorrentById(id string) (Torrents, error) { var torrent Torrents From 5bad947a78a46d02c716eb5415243a2658fbc804 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 5 May 2017 22:02:40 +1000 Subject: [PATCH 6/6] Add styles from /g/anon to fix table responsiveness --- css/style.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/css/style.css b/css/style.css index 1832da65..5eb9efb2 100644 --- a/css/style.css +++ b/css/style.css @@ -63,3 +63,10 @@ a { .torrent-info .filesize { white-space: nowrap; } + +div.container div.blockBody:nth-of-type(2) table{table-layout:fixed;} +div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:first-of-type, div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:nth-of-type(5){width:10%;} +div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:nth-of-type(3){width:15%;} +div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:nth-of-type(4){width:19%;} +div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-type{width:6%;} +tr.torrent-info td.hash,tr.torrent-info td.date{word-wrap:break-word;}