diff --git a/config/upload.go b/config/upload.go index dd4d85aa..d38a3526 100644 --- a/config/upload.go +++ b/config/upload.go @@ -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 ) diff --git a/model/torrent.go b/model/torrent.go index 5d407537..58920334 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -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 } diff --git a/templates/home.html b/templates/home.html index 0b469a0d..58adca26 100644 --- a/templates/home.html +++ b/templates/home.html @@ -39,9 +39,11 @@ - + {{if ne .TorrentLink ""}} + + {{end}} {{end}} diff --git a/templates/view.html b/templates/view.html index 2bbe93ff..5ac14a66 100644 --- a/templates/view.html +++ b/templates/view.html @@ -42,9 +42,11 @@ Download! - + {{if ne .TorrentLink ""}} + Torrent file + {{end}}