Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

fix "torrent file button grayed out for old torrents (anicache.com link)" (#1542)

* add strfind function & check for pantsu.cat when checking torrent file exists

* test

* Update listing.jet.html

* Update view.jet.html

* Update torrents.jet.html

* Update template_functions_test.go
Cette révision appartient à :
kilo 2017-09-09 14:05:51 +02:00 révisé par GitHub
Parent 5b1c6aed4e
révision f8112723f8
5 fichiers modifiés avec 48 ajouts et 6 suppressions

Voir le fichier

@ -83,7 +83,7 @@
<a href="{{.Magnet}}" title="{{ T("magnet_link") }}">
<div class="icon-magnet"></div>
</a>
<a href="{{.TorrentLink}}" title="{{ T("torrent_file") }}" {{if !torrentFileExists(.Hash)}}class="hidden"{{end}}>
<a href="{{.TorrentLink}}" title="{{ T("torrent_file") }}" {{if !torrentFileExists(.Hash, .TorrentLink)}}class="hidden"{{end}}>
<div class="icon-floppy"></div>
</a>
</td>

Voir le fichier

@ -133,7 +133,7 @@
<a href="{{Torrent.Magnet}}" class="form-input btn-green download" style="float:left;height: auto;margin-right: 0.5em;">
<div class="icon-magnet"></div> {{ T("magnet_link")}}
</a>
<a href="{{Torrent.TorrentLink}}" class="form-input download{{ if !torrentFileExists(Torrent.Hash)}} hidden{{end}}" style="float:left;height: auto;">
<a href="{{Torrent.TorrentLink}}" class="form-input download{{ if !torrentFileExists(Torrent.Hash, Torrent.TorrentLink)}} hidden{{end}}" style="float:left;height: auto;">
<div class="icon-floppy"></div> {{ T("torrent_file")}}
</a>
{{ if User.ID > 0}}

Voir le fichier

@ -36,7 +36,7 @@
<a href="{{torrent.Magnet}}" title="{{ T("magnet_link") }}">
<div class="icon-magnet"></div>
</a>
<a href="{{torrent.TorrentLink}}" title="{{ T("torrent_file") }}" {{if !torrentFileExists(torrent.Hash)}}class="hidden"{{end}}>
<a href="{{torrent.TorrentLink}}" title="{{ T("torrent_file") }}" {{if !torrentFileExists(torrent.Hash, torrent.TorrentLink)}}class="hidden"{{end}}>
<div class="icon-floppy"></div>
</a>
</td>

Voir le fichier

@ -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)
}

Voir le fichier

@ -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