Merge branch 'master' of https://github.com/ewhal/nyaa
Cette révision appartient à :
révision
6d4af2d239
3 fichiers modifiés avec 33 ajouts et 14 suppressions
13
main.go
13
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)
|
||||
|
|
30
models.go
30
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Référencer dans un nouveau ticket