diff --git a/internal/dav/listing.go b/internal/dav/listing.go
index 0aed8df..5e0ec27 100644
--- a/internal/dav/listing.go
+++ b/internal/dav/listing.go
@@ -38,17 +38,13 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
var buf bytes.Buffer
buf.WriteString("")
buf.WriteString(dav.BaseDirectory(directory, ""))
- var allTorrents []*torrent.Torrent
- torrents.IterCb(func(_ string, tor *torrent.Torrent) {
- if tor.AllInProgress() {
- return
+ torrentNames := torrents.Keys()
+ sort.Strings(torrentNames)
+ for _, torrentName := range torrentNames {
+ tor, ok := torrents.Get(torrentName)
+ if !ok || tor.AllInProgress() {
+ continue
}
- allTorrents = append(allTorrents, tor)
- })
- sort.Slice(allTorrents, func(i, j int) bool {
- return allTorrents[i].AccessKey < allTorrents[j].AccessKey
- })
- for _, tor := range allTorrents {
buf.WriteString(dav.Directory(tor.AccessKey, tor.LatestAdded))
}
buf.WriteString("")
diff --git a/internal/http/listing.go b/internal/http/listing.go
index df21f04..8a31c19 100644
--- a/internal/http/listing.go
+++ b/internal/http/listing.go
@@ -37,17 +37,13 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
var buf bytes.Buffer
buf.WriteString("
")
- var allTorrents []*torrent.Torrent
- torrents.IterCb(func(_ string, tor *torrent.Torrent) {
- if tor.AllInProgress() {
- return
+ torrentNames := torrents.Keys()
+ sort.Strings(torrentNames)
+ for _, torrentName := range torrentNames {
+ tor, ok := torrents.Get(torrentName)
+ if !ok || tor.AllInProgress() {
+ continue
}
- allTorrents = append(allTorrents, tor)
- })
- sort.Slice(allTorrents, func(i, j int) bool {
- return allTorrents[i].AccessKey < allTorrents[j].AccessKey
- })
- for _, tor := range allTorrents {
buf.WriteString(fmt.Sprintf("- %s
", filepath.Join(directory, url.PathEscape(tor.AccessKey)), tor.AccessKey))
}
return buf.Bytes(), nil
diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go
index 3fbeb5f..f6f976c 100644
--- a/internal/torrent/refresh.go
+++ b/internal/torrent/refresh.go
@@ -58,7 +58,10 @@ func (t *TorrentManager) RefreshTorrents() []string {
// torrents yet to be assigned in a directory
strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool {
// assign to directories
- tor, _ := allTorrents.Get(accessKey)
+ tor, ok := allTorrents.Get(accessKey)
+ if !ok {
+ return true
+ }
var directories []string
t.assignedDirectoryCb(tor, func(directory string) {
if strings.HasPrefix(directory, "int__") {
diff --git a/internal/universal/head.go b/internal/universal/head.go
index f7680ed..5cd6106 100644
--- a/internal/universal/head.go
+++ b/internal/universal/head.go
@@ -25,8 +25,8 @@ func HandleHeadRequest(directory, torrentName, fileName string, w http.ResponseW
return
}
- file, _ := torrent.SelectedFiles.Get(fileName)
- if file == nil {
+ file, ok := torrent.SelectedFiles.Get(fileName)
+ if !ok {
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
http.Error(w, "Cannot find file", http.StatusNotFound)
return
diff --git a/pkg/http/client.go b/pkg/http/client.go
index a003b66..ffed4ba 100644
--- a/pkg/http/client.go
+++ b/pkg/http/client.go
@@ -68,7 +68,10 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, cfg config.Con
if cfg.ShouldForceIPv6() {
dialer := &net.Dialer{}
dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
- host, port, _ := net.SplitHostPort(address)
+ host, port, err := net.SplitHostPort(address)
+ if err != nil {
+ return nil, err
+ }
if ipv6Address, ok := client.ipv6.Get(address); ok {
return dialer.DialContext(ctx, network, ipv6Address)
}
diff --git a/pkg/realdebrid/unrestrict.go b/pkg/realdebrid/unrestrict.go
index 0a2d9d8..f9e705b 100644
--- a/pkg/realdebrid/unrestrict.go
+++ b/pkg/realdebrid/unrestrict.go
@@ -9,11 +9,11 @@ func (rd *RealDebrid) UnrestrictUntilOk(link string, serveFromRclone bool) *Down
if !strings.HasPrefix(link, "http") {
return nil
}
- resp, _ := rd.UnrestrictLink(link, serveFromRclone)
- if resp != nil {
- return resp
+ resp, err := rd.UnrestrictLink(link, serveFromRclone)
+ if err != nil {
+ return nil
}
- return nil
+ return resp
}
func (rd *RealDebrid) CanFetchFirstByte(url string) bool {