diff --git a/templates/site/torrents/listing.jet.html b/templates/site/torrents/listing.jet.html index 24ff9bca..844606fa 100644 --- a/templates/site/torrents/listing.jet.html +++ b/templates/site/torrents/listing.jet.html @@ -83,7 +83,7 @@
- +
diff --git a/templates/site/torrents/view.jet.html b/templates/site/torrents/view.jet.html index 8dadc6e6..c4c70b7f 100644 --- a/templates/site/torrents/view.jet.html +++ b/templates/site/torrents/view.jet.html @@ -133,7 +133,7 @@
{{ T("magnet_link")}}
- +
{{ T("torrent_file")}}
{{ if User.ID > 0}} diff --git a/templates/site/user/torrents.jet.html b/templates/site/user/torrents.jet.html index fb6ceec2..d01272ad 100644 --- a/templates/site/user/torrents.jet.html +++ b/templates/site/user/torrents.jet.html @@ -36,7 +36,7 @@
- +
diff --git a/templates/template_functions.go b/templates/template_functions.go index fecce525..8eb69534 100644 --- a/templates/template_functions.go +++ b/templates/template_functions.go @@ -50,6 +50,7 @@ func templateFunctions(vars jet.VarMap) jet.VarMap { vars.Set("genActivityContent", genActivityContent) vars.Set("contains", contains) vars.Set("kilo_strcmp", kilo_strcmp) + vars.Set("kilo_strfind", kilo_strfind) return vars } func getRawQuery(currentURL *url.URL) string { @@ -296,8 +297,10 @@ func contains(arr interface{}, comp string) bool { return false } -func torrentFileExists(hash string) bool { - +func torrentFileExists(hash string, TorrentLink string) bool { + if(len(TorrentLink) > 30 && !kilo_strfind(TorrentLink, ".pantsu.cat", 8)) { + return true + } Openfile, err := os.Open(fmt.Sprintf("%s%c%s.torrent", config.Get().Torrents.FileStorage, os.PathSeparator, hash)) if err != nil { return false @@ -329,3 +332,17 @@ func kilo_strcmp(str1 string, str2 string, end int, start int) bool { return strings.Compare(str1[start:end], str2[start:end]) == 0 } + +func kilo_strfind(str1 string, searchfor string, start int) bool { + //Search a string inside another with start parameter + //start parameter indicates where we start searching + + len1 := len(str1) + + if start >= len1 { + return false + } + + + return strings.Contains(str1[start:len1], searchfor) +} diff --git a/templates/template_functions_test.go b/templates/template_functions_test.go index 035506a5..39b143ca 100644 --- a/templates/template_functions_test.go +++ b/templates/template_functions_test.go @@ -599,7 +599,7 @@ func testTorrentFileExists(t *testing.T) { }, } for _, test := range tests { - value := torrentFileExists(test.hash) + 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) } @@ -630,6 +630,31 @@ func Testkilo_strcmp(t *testing.T) { } } } + + func Testkilo_strfind(t *testing.T) { + var tests = []struct { + TestString string + TestString2 string + Expected bool + }{ + { + TestString: "kilo", + TestString2: "kilo", + Expected: true, + }, + { + TestString: "kilo", + TestString2: "loki", // Clearly not the same level + Expected: false, + }, + } + for _, test := range tests { + value := kilo_strfind(test.TestString, test.TestString2, 0) + if value != test.Expected { + t.Errorf("Unexpected value from the function languageName, got '%t', wanted '%t'", value, test.Expected, test.TestString, test.TestString) + } + } + } func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc { conf := config.Get().I18n