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/index.html b/index.html
index c54e8876..d140b72b 100644
--- a/index.html
+++ b/index.html
@@ -107,6 +107,8 @@
Id |
Name |
Hash |
+ Date |
+ Size |
Links |
{{ range .ListTorrents}}
@@ -114,8 +116,10 @@
{{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 402a5197..d0d32cfc 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"
@@ -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"]
@@ -197,6 +197,23 @@ func rssHandler(w http.ResponseWriter, r *http.Request) {
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)
@@ -245,9 +262,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/models.go b/models.go
index f83b1533..40f93fd7 100644
--- a/models.go
+++ b/models.go
@@ -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 {
@@ -194,11 +196,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
}
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
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}}
+
+ Id |
+ {{.Id}} |
+
+
+ Name |
+ {{.Name}} |
+
+
+ Hash |
+ {{.Hash}} |
+
+
+ Date |
+ {{.Date}} |
+
+
+ FileSize |
+ {{.Filesize}} |
+
+ tr
+
+ Links |
+
+
+ |
+
+ {{end}}
+
+
+
+
+
+
+
+
+
+
+
+
|