Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Prepare for storage of uploaded .torrent files

Cette révision appartient à :
sfan5 2017-05-09 16:42:12 +02:00
Parent 203c3734c8
révision 4d7b56df8c
4 fichiers modifiés avec 23 ajouts et 4 suppressions

Voir le fichier

@ -1,8 +1,14 @@
package config
const (
// TorrentFileStorage = "/var/tmp/torrent_outgoing"
// TorrentFileStorage = "/var/www/wherever/you/want"
// TorrentStorageLink = "https://your.site/somewhere/%s.torrent"
TorrentFileStorage = ""
TorrentStorageLink = ""
// TODO: deprecate this and move all files to the same server
TorrentCacheLink = "http://anicache.com/torrent/%s.torrent"
//disable uploads by default
UploadsDisabled = 1
)

Voir le fichier

@ -4,6 +4,7 @@ import (
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/util"
"fmt"
"html/template"
"strconv"
"strings"
@ -68,6 +69,7 @@ type TorrentsJson struct {
UploaderName template.HTML `json:"uploader_name"`
WebsiteLink template.URL `json:"website_link"`
Magnet template.URL `json:"magnet"`
TorrentLink template.URL `json:"torrent"`
}
/* Model Conversion to Json */
@ -85,6 +87,12 @@ func (t *Torrents) ToJson() TorrentsJson {
if t.Uploader != nil {
uploader = t.Uploader.Username
}
torrentlink := ""
if t.Id <= config.LastOldTorrentId && len(config.TorrentCacheLink) > 0 {
torrentlink = fmt.Sprintf(config.TorrentCacheLink, t.Hash)
} else if t.Id > config.LastOldTorrentId && len(config.TorrentStorageLink) > 0 {
torrentlink = fmt.Sprintf(config.TorrentStorageLink, t.Hash)
}
res := TorrentsJson{
Id: strconv.FormatUint(uint64(t.Id), 10),
Name: t.Name,
@ -100,7 +108,8 @@ func (t *Torrents) ToJson() TorrentsJson {
UploaderId: t.UploaderId,
UploaderName: util.SafeText(uploader),
WebsiteLink: util.Safe(t.WebsiteLink),
Magnet: util.Safe(magnet)}
Magnet: util.Safe(magnet),
TorrentLink: util.Safe(torrentlink)}
return res
}

Voir le fichier

@ -39,9 +39,11 @@
<a href="{{.Magnet}}" title="Magnet link">
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span>
</a>
<a href="http://anicache.com/torrent/{{.Hash}}.torrent" title="Torrent file">
{{if ne .TorrentLink ""}}
<a href="{{.TorrentLink}}" title="Torrent file">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span>
</a>
{{end}}
</td>
</tr>
{{end}}

Voir le fichier

@ -42,9 +42,11 @@
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!
</a>
<a style="padding-left: 0.5em"></a>
<a aria-label="Torrent file" href="http://anicache.com/torrent/{{.Hash}}.torrent" type="button" class="btn btn-success download-btn">
{{if ne .TorrentLink ""}}
<a aria-label="Torrent file" href="{{.TorrentLink}}" type="button" class="btn btn-success download-btn">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
</a>
{{end}}
</td>
</tr>
<tr>