Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge branch 'dev' into classic-theme

Cette révision appartient à :
kilo 2017-09-09 14:09:08 +02:00 révisé par GitHub
révision c0059bdb09
5 fichiers modifiés avec 49 ajouts et 7 suppressions

Voir le fichier

@ -84,7 +84,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,8 +133,8 @@
<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;">
<div class="icon-floppy"></div>{{ T("torrent_file")}}
<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}}
<a id="reportPopup" href="#" class="form-input">{{ T("report_btn") }}</a>

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