Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Add torrentFileExists function, check if torrent file exists and if it doesn't lower the opacity on the torrent download button (#1504)

* Add torrentFileExists function

* If torrent file doesn't exist, put torrent download button opacity at 50%

* ditto for listing

* Forgot an if

* attempt at fixing travis by adding function into test templates

* Attempt at fixing travis by having sex with my own mother

* fix wrong error message

* Add torrentFileExists as global function

* Update template_functions.go
Cette révision appartient à :
kilo 2017-09-06 04:30:49 +02:00 révisé par ewhal
Parent ea7d42210c
révision 35d4eb9ca8
4 fichiers modifiés avec 33 ajouts et 7 suppressions

Voir le fichier

@ -87,11 +87,9 @@
<a href="{{.Magnet}}" title="{{ T("magnet_link") }}">
<div class="icon-magnet"></div>
</a>
{{if .TorrentLink != ""}}
<a href="{{.TorrentLink}}" title="{{ T("torrent_file") }}">
<a href="{{.TorrentLink}}" title="{{ T("torrent_file") }}" {{if !torrentFileExists(.Hash)}}class="hidden"{{end}}>
<div class="icon-floppy"></div>
</a>
{{end}}
</td>
<td class="tr-size home-td hide-xs">
{{ fileSize(.Filesize, T) }}

Voir le fichier

@ -133,11 +133,9 @@
<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>
{{ if Torrent.TorrentLink != ""}}
<a href="{{Torrent.TorrentLink}}" class="form-input download" style="float:left;height: auto;">
<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>
{{end}}
{{ if User.ID > 0}}
<a id="reportPopup" href="#" class="form-input">{{ T("report_btn") }}</a>
{{ if User.HasAdmin()}}

Voir le fichier

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

Voir le fichier

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