Merge pull request #129 from azhao12345/upload-changes
Implement some stuff needed for upload
Cette révision appartient à :
révision
cd3dae3d5e
6 fichiers modifiés avec 42 ajouts et 17 suppressions
|
@ -1,5 +1,12 @@
|
|||
package config
|
||||
|
||||
const (
|
||||
Trackers = "&tr=udp://tracker.coppersurfer.tk:6969&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.internetwarriors.net:1337/announce&tr=udp://eddie4.nl:6969/announce&tr=http://mgtracker.org:6969/announce&tr=http://tracker.baka-sub.cf/announce"
|
||||
)
|
||||
var Trackers = []string{
|
||||
"udp://tracker.coppersurfer.tk:6969",
|
||||
"udp://zer0day.to:1337/announce",
|
||||
"udp://tracker.leechers-paradise.org:6969",
|
||||
"udp://explodie.org:6969",
|
||||
"udp://tracker.opentrackr.org:1337",
|
||||
"udp://tracker.internetwarriors.net:1337/announce",
|
||||
"udp://eddie4.nl:6969/announce",
|
||||
"http://mgtracker.org:6969/announce",
|
||||
"http://tracker.baka-sub.cf/announce"}
|
||||
|
|
|
@ -73,7 +73,7 @@ type TorrentsJson struct {
|
|||
/* Model Conversion to Json */
|
||||
|
||||
func (t *Torrents) ToJson() TorrentsJson {
|
||||
magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(t.Hash) + "&dn=" + t.Name + config.Trackers
|
||||
magnet := util.InfoHashToMagnet(strings.TrimSpace(t.Hash), t.Name, config.Trackers...)
|
||||
b := []CommentsJson{}
|
||||
_ = json.Unmarshal([]byte(t.Comments), &b)
|
||||
res := TorrentsJson{
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"github.com/ewhal/nyaa/util"
|
||||
"github.com/ewhal/nyaa/util/metainfo"
|
||||
"github.com/zeebo/bencode"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// UploadForm serializing HTTP form for torrent upload
|
||||
type UploadForm struct {
|
||||
Name string
|
||||
Magnet string
|
||||
Infohash string
|
||||
Category string
|
||||
Description string
|
||||
}
|
||||
|
@ -85,8 +89,23 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
}
|
||||
|
||||
// generate magnet
|
||||
f.Magnet = util.InfoHashToMagnet(torrent.Infohash(), f.Name)
|
||||
binInfohash := torrent.Infohash()
|
||||
f.Infohash = hex.EncodeToString(binInfohash[:])
|
||||
f.Magnet = util.InfoHashToMagnet(f.Infohash, f.Name)
|
||||
f.Infohash = strings.ToUpper(f.Infohash)
|
||||
} else {
|
||||
magnetUrl, parseErr := url.Parse(f.Magnet)
|
||||
if parseErr != nil {
|
||||
return metainfo.ErrInvalidTorrentFile
|
||||
}
|
||||
exactTopic := magnetUrl.Query().Get("xt")
|
||||
if !strings.HasPrefix(exactTopic, "urn:btih:") {
|
||||
return metainfo.ErrInvalidTorrentFile
|
||||
} else {
|
||||
f.Infohash = strings.ToUpper(strings.TrimPrefix(exactTopic, "urn:btih:"))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package torrentService
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/util"
|
||||
"github.com/jinzhu/gorm"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -30,7 +32,7 @@ func GetFeeds() []model.Feed {
|
|||
for rows.Next() {
|
||||
item := model.Feed{}
|
||||
rows.Scan(&item.Id, &item.Name, &item.Hash, &item.Timestamp)
|
||||
magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(item.Hash) + "&dn=" + item.Name + config.Trackers
|
||||
magnet := util.InfoHashToMagnet(strings.TrimSpace(item.Hash), item.Name, config.Trackers...)
|
||||
item.Magnet = magnet
|
||||
// memory hog
|
||||
result = append(result, item)
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
<div class="blockBody">
|
||||
{{with .Upload}}
|
||||
<hr>
|
||||
<form role="upload" method="POST">
|
||||
<form enctype="multipart/form-data" role="upload" method="POST">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="torrent">Torrent file upload</label>
|
||||
<input type="file" id="torrent">
|
||||
<input type="file" name="torrent" id="torrent" accept=".torrent">
|
||||
<p class="help-block">Upload a torrent file to pre-fill information</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -17,7 +17,7 @@
|
|||
<div class="form-group">
|
||||
<label for="Magnet">Magnet Link</label>
|
||||
<input type="text" name="magnet" class="form-control"
|
||||
style="width:60rem" placeholder="Magnet Link" value="{{.Magnet}}" required>
|
||||
style="width:60rem" placeholder="Magnet Link" value="{{.Magnet}}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="c">Category</label>
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// convert a binary infohash to a magnet uri given a display name and tracker urls
|
||||
func InfoHashToMagnet(ih [20]byte, name string, trackers ...url.URL) (str string) {
|
||||
str = hex.EncodeToString(ih[:])
|
||||
str = fmt.Sprintf("magnet:?xt=urn:btih:%s", str)
|
||||
func InfoHashToMagnet(ih string, name string, trackers ...string) (str string) {
|
||||
str = fmt.Sprintf("magnet:?xt=urn:btih:%s", ih)
|
||||
if len(name) > 0 {
|
||||
str += fmt.Sprintf("&dn=%s", name)
|
||||
}
|
||||
for idx := range trackers {
|
||||
str += fmt.Sprintf("&tr=%s", trackers[idx].String())
|
||||
str += fmt.Sprintf("&tr=%s", trackers[idx])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket