From 6939a7517dfde01962616dbb765a53f58a22ca90 Mon Sep 17 00:00:00 2001 From: Owner Date: Thu, 4 May 2017 21:48:40 +0200 Subject: [PATCH 01/17] RSS feed for home page. --- main.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ models.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/main.go b/main.go index 9528a674..4681626f 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "github.com/gorilla/feeds" "github.com/gorilla/mux" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/sqlite" @@ -139,6 +140,53 @@ 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() + if ( len(torrents) > 0 ) { + created = torrents[0].Timestamp + } + created_as_time, err := time.Parse("2006-01-02 15:04:05", created) + if err == nil { + ; + } + feed := &feeds.Feed{ + Title: "Nyaa Pantsu", + Link: &feeds.Link{Href: "https://nyaa.pantsu.cat/"}, + Created: created_as_time, + } + feed.Items = []*feeds.Item{} + 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, + } + } + } + + rss, err := feed.ToRss() + if err == nil { + w.Write( []byte( rss ) ) + } else { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} + func rootHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) page := vars["page"] @@ -188,6 +236,7 @@ func main() { router.HandleFunc("/api/{page}", apiHandler).Methods("GET") router.HandleFunc("/api/torrent/{id}", singleapiHandler).Methods("GET") router.HandleFunc("/faq", faqHandler) + router.HandleFunc("/feed.xml", rssHandler) http.Handle("/", router) diff --git a/models.go b/models.go index 4735d830..d090afd0 100644 --- a/models.go +++ b/models.go @@ -9,6 +9,14 @@ import ( "strings" ) +type Feed struct { + Id int + Name string + Hash string + Magnet string + Timestamp string +} + type Categories struct { Category_id int Category_name string @@ -79,6 +87,27 @@ type HomeTemplateVariables 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 72fc788d71b172ab956079780fac2fd94b060489 Mon Sep 17 00:00:00 2001 From: Owner Date: Thu, 4 May 2017 21:58:05 +0200 Subject: [PATCH 02/17] Travis rss feed dependency. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index aae111c2..6815c806 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: go go: - 1.x install: +- go get github.com/gorilla/feeds - go get github.com/gorilla/mux - go get github.com/mattn/go-sqlite3 - go get github.com/jinzhu/gorm From aba761972c445573a54f4bc0bd1e990566ec1334 Mon Sep 17 00:00:00 2001 From: bittebitte Date: Thu, 4 May 2017 16:10:16 -0500 Subject: [PATCH 03/17] iTorrents to replace defunct Torcache --- index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/index.html b/index.html index 82401407..6232c856 100644 --- a/index.html +++ b/index.html @@ -103,6 +103,7 @@ {{.Hash}} + From 2b677f2bbcbe75c1b1faee723c4b40846748f2bd Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 4 May 2017 18:18:27 -0400 Subject: [PATCH 04/17] =Updated models to match ilikecats' merged database --- main.go | 3 +-- models.go | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 9528a674..b637d8f8 100644 --- a/main.go +++ b/main.go @@ -23,8 +23,7 @@ func getDBHandle() *gorm.DB { dbInit, err := gorm.Open("sqlite3", "./nyaa.db") // Migrate the schema of Torrents - dbInit.AutoMigrate(&Torrents{}) - dbInit.AutoMigrate(&Sub_Categories{}) + dbInit.AutoMigrate(&Torrents{}, &Categories{}, &Sub_Categories{}, &Statuses{}) checkErr(err) return dbInit diff --git a/models.go b/models.go index 4735d830..6e62ba16 100644 --- a/models.go +++ b/models.go @@ -2,7 +2,6 @@ package main import ( "errors" - "github.com/jinzhu/gorm" "html" "html/template" "strconv" @@ -19,18 +18,28 @@ type Categories struct { type Sub_Categories struct { Sub_category_id int Sub_category_name string - Parent_id int + Parent_id int Torrents []Torrents `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` } +type Statuses struct { + Status_id int + Status_name string + Torrents []Torrents `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` +} + type Torrents struct { - gorm.Model Id int `gorm:"column:torrent_id"` Name string `gorm:"column:torrent_name"` Category_id int `gorm:"column:category_id"` Sub_category_id int `gorm:"column:sub_category_id"` - Status int `gorm:"column:status_id"` + Status_id int `gorm:"column:status_id"` Hash string `gorm:"column:torrent_hash"` + Date int `gorm:"column:date"` + Downloads int `gorm:"column:downloads"` + Filesize string `gorm:"column:filesize"` + Description []byte `gorm:"column:description"` + Statuses Statuses `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` Categories Categories `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"` Sub_Categories Sub_Categories `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` } @@ -134,7 +143,7 @@ func (t *Torrents) toJson() TorrentsJson { res := TorrentsJson{ Id: strconv.Itoa(t.Id), Name: html.UnescapeString(t.Name), - Status: t.Status, + Status: t.Status_id, Hash: t.Hash, Magnet: safe(magnet)} return res From 9be801c8a71f38565427672874d894f7694d33fa Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 5 May 2017 08:26:16 +1000 Subject: [PATCH 05/17] Update README.md --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 13345bb5..ac53bf64 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,22 @@ that anyone will be able to deploy locally or remotely. # Requirements * Golang - +#Installation +* Install golang +* go get github.com/ewhal/nyaa +* go build +* Download db +* place db in folder as "nyaa.d" +* ./nyaa +* go to localhost:9999 ## TODO -* RSS feeds -* status searching -* torrent sorting +* RSS feeds(work in progress) +* torrent sorting (work in progress) * Merge 5th of april dump with animetosho dump * API improvement * Site theme -* improve search by making it less strict and support non-english characters. -* Torrent view and description page +* improve search by making it less strict +* Torrent view and description page(work in progress) * accounts? * Adding new torrents * scraping From de5d45616c79ac9ac9bb34e9baf05537eef84ed5 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 5 May 2017 08:26:59 +1000 Subject: [PATCH 06/17] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac53bf64..f947ea79 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ that anyone will be able to deploy locally or remotely. # Requirements * Golang -#Installation +# Installation * Install golang * go get github.com/ewhal/nyaa * go build @@ -15,6 +15,7 @@ that anyone will be able to deploy locally or remotely. * place db in folder as "nyaa.d" * ./nyaa * go to localhost:9999 + ## TODO * RSS feeds(work in progress) * torrent sorting (work in progress) From 49ef02a8ff5bf2d1c9ea1391d7816d3a756e44c4 Mon Sep 17 00:00:00 2001 From: ayame-git Date: Fri, 5 May 2017 04:04:45 +0300 Subject: [PATCH 07/17] magnet link doesn't open tab now --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 7b1bf223..f031ca46 100644 --- a/index.html +++ b/index.html @@ -108,7 +108,7 @@ {{.Name}} {{.Hash}} - + From d273671ab01941591c0984e273ba620a92d8ecb6 Mon Sep 17 00:00:00 2001 From: Lietzu Date: Thu, 4 May 2017 18:52:46 -0400 Subject: [PATCH 08/17] Configured models to match ilikecats' merged db, and expanded automigration --- main.go | 1 + models.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6845edc5..27b3e64a 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ func getDBHandle() *gorm.DB { // Migrate the schema of Torrents dbInit.AutoMigrate(&Torrents{}, &Categories{}, &Sub_Categories{}, &Statuses{}) + checkErr(err) return dbInit } diff --git a/models.go b/models.go index 8fb5f467..2ceb83fd 100644 --- a/models.go +++ b/models.go @@ -135,7 +135,7 @@ func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs dbQuery = db.Model(&torrents).Where(parameters.conditions, parameters.params...) } else { dbQuery = db.Model(&torrents) - } + } if (orderBy == "") { orderBy = "torrent_id DESC" } // Default OrderBy if limit != 0 || offset != 0 { // if limits provided From 9f11bbd9f53c3797304858cc397db2ba61c07448 Mon Sep 17 00:00:00 2001 From: Lietzu Date: Thu, 4 May 2017 19:03:25 -0400 Subject: [PATCH 09/17] Changed models to reflect ilikecat's new merged db v2 --- models.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models.go b/models.go index 2ceb83fd..3fb9ff9a 100644 --- a/models.go +++ b/models.go @@ -2,6 +2,7 @@ package main import ( "errors" + "github.com/jinzhu/gorm" "html" "html/template" "strconv" From 8a513bcc01f353d923090721d1892e0326849b20 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 5 May 2017 09:52:56 +1000 Subject: [PATCH 10/17] Add filesize and dates to page --- index.html | 4 +++ models.go | 90 +++++++++++++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/index.html b/index.html index c926a3e6..e10be842 100644 --- a/index.html +++ b/index.html @@ -98,6 +98,8 @@ Id Name Hash + Date + Size Links {{ range .ListTorrents}} @@ -107,6 +109,8 @@ {{.Id}} {{.Name}} {{.Hash}} + {{.Date}} + {{.Filesize}} diff --git a/models.go b/models.go index 3fb9ff9a..afbe0e60 100644 --- a/models.go +++ b/models.go @@ -10,31 +10,31 @@ import ( ) type Feed struct { - Id int - Name string - Hash string - Magnet string - Timestamp string + Id int + Name string + Hash string + Magnet string + Timestamp string } type Categories struct { - Category_id int - Category_name string - Torrents []Torrents `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"` - Sub_Categories []Sub_Categories `gorm:"ForeignKey:category_id;AssociationForeignKey:parent_id"` + Category_id int + Category_name string + Torrents []Torrents `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"` + Sub_Categories []Sub_Categories `gorm:"ForeignKey:category_id;AssociationForeignKey:parent_id"` } type Sub_Categories struct { - Sub_category_id int + Sub_category_id int Sub_category_name string - Parent_id int - Torrents []Torrents `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` + Parent_id int + Torrents []Torrents `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` } type Statuses struct { - Status_id int - Status_name string - Torrents []Torrents `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` + Status_id int + Status_name string + Torrents []Torrents `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` } type Torrents struct { @@ -42,12 +42,12 @@ type Torrents struct { Name string `gorm:"column:torrent_name"` Category_id int `gorm:"column:category_id"` Sub_category_id int `gorm:"column:sub_category_id"` - Status_id int `gorm:"column:status_id"` + Status_id int `gorm:"column:status_id"` Hash string `gorm:"column:torrent_hash"` - Date int `gorm:"column:date"` - Downloads int `gorm:"column:downloads"` - Filesize string `gorm:"column:filesize"` - Description []byte `gorm:"column:description"` + Date int `gorm:"column:date"` + Downloads int `gorm:"column:downloads"` + Filesize string `gorm:"column:filesize"` + Description []byte `gorm:"column:description"` Statuses Statuses `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"` Categories Categories `gorm:"ForeignKey:category_id;AssociationForeignKey:category_id"` Sub_Categories Sub_Categories `gorm:"ForeignKey:sub_category_id;AssociationForeignKey:sub_category_id"` @@ -67,11 +67,13 @@ type CategoryJson struct { } type TorrentsJson struct { - Id string `json: "id"` // Is there a need to put the ID? - Name string `json: "name"` - Status int `json: "status"` - Hash string `json: "hash"` - Magnet template.URL `json: "magnet"` + Id string `json: "id"` // Is there a need to put the ID? + Name string `json: "name"` + Status int `json: "status"` + Hash string `json: "hash"` + Date int `json: "date"` + Filesize string `json: "filesize"` + Magnet template.URL `json: "magnet"` } type WhereParams struct { @@ -103,15 +105,15 @@ func getFeeds() []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 ) { + "ORDER BY `timestamp` desc LIMIT 50") + if err == nil { for rows.Next() { item := Feed{} - rows.Scan( &item.Id, &item.Name, &item.Hash, &item.Timestamp ) + 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 ) + result = append(result, item) } rows.Close() } @@ -131,23 +133,25 @@ func getTorrentById(id string) (Torrents, error) { func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offset int) []Torrents { var torrents []Torrents var dbQuery *gorm.DB - - if (parameters != nil) { // if there is where parameters + + if parameters != nil { // if there is where parameters dbQuery = db.Model(&torrents).Where(parameters.conditions, parameters.params...) } else { dbQuery = db.Model(&torrents) } - - if (orderBy == "") { orderBy = "torrent_id DESC" } // Default OrderBy + + if orderBy == "" { + orderBy = "torrent_id DESC" + } // Default OrderBy if limit != 0 || offset != 0 { // if limits provided dbQuery = dbQuery.Limit(limit).Offset(offset) } - dbQuery.Order(orderBy).Preload("Categories").Preload("Sub_Categories").Find(&torrents) + dbQuery.Order(orderBy).Preload("Categories").Preload("Sub_Categories").Find(&torrents) return torrents } -/* Functions to simplify the get parameters of the main function - * +/* Functions to simplify the get parameters of the main function + * * Get Torrents with where parameters and limits, order by default */ func getTorrents(parameters WhereParams, limit int, offset int) []Torrents { @@ -163,7 +167,7 @@ func getTorrentsDB(parameters WhereParams) []Torrents { /* Function to get all torrents */ -func getAllTorrentsOrderBy(orderBy string, limit int, offset int) [] Torrents { +func getAllTorrentsOrderBy(orderBy string, limit int, offset int) []Torrents { return getTorrentsOrderBy(nil, orderBy, limit, offset) } @@ -190,11 +194,13 @@ func getAllCategories(populatedWithTorrents bool) []Categories { func (t *Torrents) toJson() TorrentsJson { magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(t.Hash) + "&dn=" + t.Name + trackers res := TorrentsJson{ - Id: strconv.Itoa(t.Id), - Name: html.UnescapeString(t.Name), - Status: t.Status_id, - Hash: t.Hash, - Magnet: safe(magnet)} + Id: strconv.Itoa(t.Id), + Name: html.UnescapeString(t.Name), + Status: t.Status_id, + Hash: t.Hash, + Date: t.Date, + Filesize: t.Filesize, + Magnet: safe(magnet)} return res } From 17a62c8ed261c7c3a25163d8e5c607b048ff3ba8 Mon Sep 17 00:00:00 2001 From: bakape Date: Fri, 5 May 2017 03:41:47 +0300 Subject: [PATCH 11/17] Script for binary package cross-compilation --- .gitignore | 4 +++- package.sh | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 package.sh diff --git a/.gitignore b/.gitignore index ece147f5..8248a38a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ *.db main nyaa -nyaa-master.exe \ No newline at end of file +nyaa.exe +nyaa-master.exe +*.zip diff --git a/package.sh b/package.sh new file mode 100755 index 00000000..973f219d --- /dev/null +++ b/package.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Helper script to ease building binary packages for multiple targets. +# Requires the linux64 and mingw64 gcc compilers and zip. +# On Debian-based distros install mingw-w64. + +version=$(git describe --tags) +declare -a OSes +OSes[0]='linux;x86_64-linux-gnu-gcc' +OSes[1]='windows;x86_64-w64-mingw32-gcc' + +for i in "${OSes[@]}"; do + arr=(${i//;/ }) + os=${arr[0]} + cc=${arr[1]} + rm -f nyaa nyaa.exe + echo -e "\nBuilding $os..." + echo GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v + GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v + zip -9 -q nyaa-${version}_${os}_amd64.zip css js *.md *.html nyaa nyaa.exe +done From c513e926bbf9b82bbd09b0783edaaac818dd5fa6 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 5 May 2017 10:54:37 +1000 Subject: [PATCH 12/17] Add view page --- index.html | 2 +- main.go | 50 +++++++++++++------ view.html | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 17 deletions(-) create mode 100644 view.html diff --git a/index.html b/index.html index e10be842..8ec6630d 100644 --- a/index.html +++ b/index.html @@ -107,7 +107,7 @@ {{if eq .Status 3}}class="trusted"{{end}} {{if eq .Status 4}}class="aplus"{{end}}> {{.Id}} - {{.Name}} + {{.Name}} {{.Hash}} {{.Date}} {{.Filesize}} diff --git a/main.go b/main.go index 27b3e64a..9e30cb19 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ import ( ) var db *gorm.DB -var templates = template.Must(template.ParseFiles("index.html", "FAQ.html")) +var templates = template.Must(template.ParseFiles("index.html", "FAQ.html", "view.html")) 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" @@ -25,7 +25,7 @@ func getDBHandle() *gorm.DB { // Migrate the schema of Torrents dbInit.AutoMigrate(&Torrents{}, &Categories{}, &Sub_Categories{}, &Statuses{}) - + checkErr(err) return dbInit } @@ -64,7 +64,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { } } -func singleapiHandler(w http.ResponseWriter, r *http.Request) { +func apiViewHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := vars["id"] @@ -149,43 +149,60 @@ func rssHandler(w http.ResponseWriter, r *http.Request) { torrents := getFeeds() created := time.Now().String() - if ( len(torrents) > 0 ) { + if len(torrents) > 0 { created = torrents[0].Timestamp } created_as_time, err := time.Parse("2006-01-02 15:04:05", created) if err == nil { - ; + } feed := &feeds.Feed{ - Title: "Nyaa Pantsu", - Link: &feeds.Link{Href: "https://nyaa.pantsu.cat/"}, - Created: created_as_time, + Title: "Nyaa Pantsu", + Link: &feeds.Link{Href: "https://nyaa.pantsu.cat/"}, + Created: created_as_time, } feed.Items = []*feeds.Item{} - feed.Items = make( []*feeds.Item, len(torrents)) + 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{ + 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)}, + Title: torrents[i].Name, + Link: &feeds.Link{Href: string(torrents[i].Magnet)}, Description: "", - Created: timestamp_as_time, - Updated: timestamp_as_time, + Created: timestamp_as_time, + Updated: timestamp_as_time, } } } rss, err := feed.ToRss() if err == nil { - w.Write( []byte( rss ) ) + w.Write([]byte(rss)) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } } +func viewHandler(w http.ResponseWriter, r *http.Request) { + + vars := mux.Vars(r) + id := vars["id"] + b := []TorrentsJson{} + + torrent, err := getTorrentById(id) + res := torrent.toJson() + b = append(b, res) + + htv := HomeTemplateVariables{b, getAllCategories(false), "", "", "_", 1, 1} + + err = templates.ExecuteTemplate(w, "view.html", htv) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} func rootHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) @@ -234,9 +251,10 @@ func main() { router.HandleFunc("/search", searchHandler) router.HandleFunc("/search/{page}", searchHandler) router.HandleFunc("/api/{page}", apiHandler).Methods("GET") - router.HandleFunc("/api/torrent/{id}", singleapiHandler).Methods("GET") + router.HandleFunc("/api/view/{id}", apiViewHandler).Methods("GET") router.HandleFunc("/faq", faqHandler) router.HandleFunc("/feed.xml", rssHandler) + router.HandleFunc("/view/{id}", viewHandler) http.Handle("/", router) diff --git a/view.html b/view.html new file mode 100644 index 00000000..cc1f9664 --- /dev/null +++ b/view.html @@ -0,0 +1,139 @@ + + + + + + + + Nyaa Pantsu + + + + + + + + + + + + + + + +
+ + {{ range .ListTorrents}} + + + + + + + + + + + + + + + + + + + + + tr + + + + + {{end}} + +
Id{{.Id}}
Name{{.Name}}
Hash{{.Hash}}
Date{{.Date}}
FileSize{{.Filesize}}
Links + +
+
+ + + + + + + + + From d8cfa78b4d54bcaa440750e334a0d6447d8a7a68 Mon Sep 17 00:00:00 2001 From: ayame-git Date: Fri, 5 May 2017 07:24:58 +0300 Subject: [PATCH 13/17] basic sort --- index.html | 13 ++++++++-- main.go | 46 ++++++++++++++++++++-------------- models.go | 72 ++++++++++++++++++++++++++++++++---------------------- 3 files changed, 82 insertions(+), 49 deletions(-) diff --git a/index.html b/index.html index c926a3e6..c54e8876 100644 --- a/index.html +++ b/index.html @@ -67,8 +67,17 @@ + +