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 fb07da18ec
révision 3b65df9cdd
4 fichiers modifiés avec 23 ajouts et 4 suppressions

Voir le fichier

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

Voir le fichier

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

Voir le fichier

@ -39,9 +39,11 @@
<a href="{{.Magnet}}" title="Magnet link"> <a href="{{.Magnet}}" title="Magnet link">
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> <span class="glyphicon glyphicon-magnet" aria-hidden="true"></span>
</a> </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> <span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span>
</a> </a>
{{end}}
</td> </td>
</tr> </tr>
{{end}} {{end}}

Voir le fichier

@ -42,9 +42,11 @@
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download! <span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!
</a> </a>
<a style="padding-left: 0.5em"></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 <span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
</a> </a>
{{end}}
</td> </td>
</tr> </tr>
<tr> <tr>