diff --git a/templates/site/torrents/listing.jet.html b/templates/site/torrents/listing.jet.html
index 539885c4..51afdb15 100644
--- a/templates/site/torrents/listing.jet.html
+++ b/templates/site/torrents/listing.jet.html
@@ -87,11 +87,9 @@
- {{if .TorrentLink != ""}}
-
+
- {{end}}
{{ fileSize(.Filesize, T) }}
diff --git a/templates/site/torrents/view.jet.html b/templates/site/torrents/view.jet.html
index 791acb3d..411ddf94 100644
--- a/templates/site/torrents/view.jet.html
+++ b/templates/site/torrents/view.jet.html
@@ -133,11 +133,9 @@
{{ T("magnet_link")}}
- {{ if Torrent.TorrentLink != ""}}
-
+
{{ T("torrent_file")}}
- {{end}}
{{ if User.ID > 0}}
{{ if User.HasAdmin()}}
diff --git a/templates/template_functions.go b/templates/template_functions.go
index 552e2e85..441884e9 100644
--- a/templates/template_functions.go
+++ b/templates/template_functions.go
@@ -6,6 +6,8 @@ import (
"net/url"
"strconv"
"time"
+ "os"
+ "fmt"
"strings"
@@ -30,7 +32,7 @@ func templateFunctions(vars jet.VarMap) jet.VarMap {
vars.Set("getDefaultLanguage", publicSettings.GetDefaultLanguage)
vars.Set("FlagCode", flagCode)
vars.Set("getAvatar", getAvatar)
-
+ vars.Set("torrentFileExists", torrentFileExists)
vars.Set("formatDateRFC", formatDateRFC)
vars.Set("GetHostname", format.GetHostname)
vars.Set("GetCategories", categories.GetSelect)
@@ -292,3 +294,13 @@ func contains(arr interface{}, comp string) bool {
}
return false
}
+
+func torrentFileExists(hash string) bool {
+
+ Openfile, err := os.Open(fmt.Sprintf("%s%c%s.torrent", config.Get().Torrents.FileStorage, os.PathSeparator, hash))
+ if err != nil {
+ return false
+ }
+ defer Openfile.Close()
+ return true
+}
diff --git a/templates/template_functions_test.go b/templates/template_functions_test.go
index 049d67cb..a38fbd65 100644
--- a/templates/template_functions_test.go
+++ b/templates/template_functions_test.go
@@ -588,6 +588,24 @@ func TestContains(t *testing.T) {
}
}
+func testTorrentFileExists(t *testing.T) {
+ var tests = []struct {
+ hash string
+ Expected bool
+ }{
+ {
+ hash: "",
+ Expected: false,
+ },
+ }
+ for _, test := range tests {
+ value := torrentFileExists(test.hash)
+ if value != test.Expected {
+ t.Errorf("Unexpected value from the function TorrentFileExists, got '%t', wanted '%t' for '%s'", value, test.Expected, test.hash)
+ }
+ }
+}
+
func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc {
conf := config.Get().I18n
conf.Directory = path.Join("..", conf.Directory)
|