Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
kipukun 2017-05-04 22:03:26 -04:00
révision 6d4af2d239
3 fichiers modifiés avec 33 ajouts et 14 suppressions

13
main.go
Voir le fichier

@ -1,6 +1,8 @@
package main package main
import ( import (
"bytes"
"compress/zlib"
"encoding/json" "encoding/json"
"github.com/gorilla/feeds" "github.com/gorilla/feeds"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -8,6 +10,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/jinzhu/gorm/dialects/sqlite"
"html" "html"
"html/template" "html/template"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"strconv" "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) { func apiHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)

Voir le fichier

@ -67,13 +67,14 @@ type CategoryJson struct {
} }
type TorrentsJson struct { type TorrentsJson struct {
Id string `json: "id"` // Is there a need to put the ID? Id string `json: "id"` // Is there a need to put the ID?
Name string `json: "name"` Name string `json: "name"`
Status int `json: "status"` Status int `json: "status"`
Hash string `json: "hash"` Hash string `json: "hash"`
Date int `json: "date"` Date int `json: "date"`
Filesize string `json: "filesize"` Filesize string `json: "filesize"`
Magnet template.URL `json: "magnet"` Description string `json: "description"`
Magnet template.URL `json: "magnet"`
} }
type WhereParams struct { type WhereParams struct {
@ -196,13 +197,14 @@ func getAllCategories(populatedWithTorrents bool) []Categories {
func (t *Torrents) toJson() TorrentsJson { func (t *Torrents) toJson() TorrentsJson {
magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(t.Hash) + "&dn=" + t.Name + trackers magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(t.Hash) + "&dn=" + t.Name + trackers
res := TorrentsJson{ res := TorrentsJson{
Id: strconv.Itoa(t.Id), Id: strconv.Itoa(t.Id),
Name: html.UnescapeString(t.Name), Name: html.UnescapeString(t.Name),
Status: t.Status_id, Status: t.Status_id,
Hash: t.Hash, Hash: t.Hash,
Date: t.Date, Date: t.Date,
Filesize: t.Filesize, Filesize: t.Filesize,
Magnet: safe(magnet)} Description: unZlib(t.Description),
Magnet: safe(magnet)}
return res 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> <a href="https://itorrents.org/torrent/{{.Hash}}.torrent" title="Torrent file"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span></a>
</td> </td>
</tr> </tr>
<tr>
<td>Description</td>
<td>{{.Description}}</td>
</tr>
{{end}} {{end}}
</table> </table>