diff --git a/main.go b/main.go index f2024df1..4fad0ccb 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "bytes" + "compress/zlib" "encoding/json" "github.com/gorilla/feeds" "github.com/gorilla/mux" @@ -8,6 +10,7 @@ import ( _ "github.com/jinzhu/gorm/dialects/sqlite" "html" "html/template" + "io/ioutil" "log" "net/http" "strconv" @@ -36,6 +39,16 @@ func checkErr(err error) { } } +func unZlib(description []byte) string { + b := bytes.NewReader(description) + z, err := zlib.NewReader(b) + checkErr(err) + defer z.Close() + p, err := ioutil.ReadAll(z) + checkErr(err) + return string(p) +} + func apiHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/models.go b/models.go index 40f93fd7..c57367e4 100644 --- a/models.go +++ b/models.go @@ -67,13 +67,14 @@ 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"` - Date int `json: "date"` - Filesize string `json: "filesize"` - 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"` + Description string `json: "description"` + Magnet template.URL `json: "magnet"` } type WhereParams struct { @@ -196,13 +197,14 @@ 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, - Date: t.Date, - Filesize: t.Filesize, - 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, + Description: unZlib(t.Description), + Magnet: safe(magnet)} return res } diff --git a/view.html b/view.html index cc1f9664..da9a0ecb 100644 --- a/view.html +++ b/view.html @@ -124,6 +124,10 @@ + + Description + {{.Description}} + {{end}}