Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Start work on descriptions

Cette révision appartient à :
Eliot Whalan 2017-05-05 11:57:08 +10:00
Parent 09954e4c86
révision 38e5413c42
Aucune clé n'a été trouvée pour cette signature dans la base de données
ID de la clé GPG: C0A42175139840D6
3 fichiers modifiés avec 33 ajouts et 14 suppressions

13
main.go
Voir le fichier

@ -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)

Voir le fichier

@ -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
}

Voir le fichier

@ -124,6 +124,10 @@
<a href="https://itorrents.org/torrent/{{.Hash}}.torrent" title="Torrent file"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span></a>
</td>
</tr>
<tr>
<td>Description</td>
<td>{{.Description}}</td>
</tr>
{{end}}
</table>