Simple string sort on listing torrents
This commit is contained in:
@@ -38,17 +38,13 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||||
buf.WriteString(dav.BaseDirectory(directory, ""))
|
buf.WriteString(dav.BaseDirectory(directory, ""))
|
||||||
var allTorrents []*torrent.Torrent
|
torrentNames := torrents.Keys()
|
||||||
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
sort.Strings(torrentNames)
|
||||||
if tor.AllInProgress() {
|
for _, torrentName := range torrentNames {
|
||||||
return
|
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(dav.Directory(tor.AccessKey, tor.LatestAdded))
|
||||||
}
|
}
|
||||||
buf.WriteString("</d:multistatus>")
|
buf.WriteString("</d:multistatus>")
|
||||||
|
|||||||
@@ -37,17 +37,13 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
|
|||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString("<ol>")
|
buf.WriteString("<ol>")
|
||||||
var allTorrents []*torrent.Torrent
|
torrentNames := torrents.Keys()
|
||||||
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
sort.Strings(torrentNames)
|
||||||
if tor.AllInProgress() {
|
for _, torrentName := range torrentNames {
|
||||||
return
|
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("<li><a href=\"/http/%s/\">%s</a></li>", filepath.Join(directory, url.PathEscape(tor.AccessKey)), tor.AccessKey))
|
buf.WriteString(fmt.Sprintf("<li><a href=\"/http/%s/\">%s</a></li>", filepath.Join(directory, url.PathEscape(tor.AccessKey)), tor.AccessKey))
|
||||||
}
|
}
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
// torrents yet to be assigned in a directory
|
// torrents yet to be assigned in a directory
|
||||||
strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool {
|
strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool {
|
||||||
// assign to directories
|
// assign to directories
|
||||||
tor, _ := allTorrents.Get(accessKey)
|
tor, ok := allTorrents.Get(accessKey)
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
var directories []string
|
var directories []string
|
||||||
t.assignedDirectoryCb(tor, func(directory string) {
|
t.assignedDirectoryCb(tor, func(directory string) {
|
||||||
if strings.HasPrefix(directory, "int__") {
|
if strings.HasPrefix(directory, "int__") {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ func HandleHeadRequest(directory, torrentName, fileName string, w http.ResponseW
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
file, _ := torrent.SelectedFiles.Get(fileName)
|
file, ok := torrent.SelectedFiles.Get(fileName)
|
||||||
if file == nil {
|
if !ok {
|
||||||
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
|
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
|
||||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -68,7 +68,10 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, cfg config.Con
|
|||||||
if cfg.ShouldForceIPv6() {
|
if cfg.ShouldForceIPv6() {
|
||||||
dialer := &net.Dialer{}
|
dialer := &net.Dialer{}
|
||||||
dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
|
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 {
|
if ipv6Address, ok := client.ipv6.Get(address); ok {
|
||||||
return dialer.DialContext(ctx, network, ipv6Address)
|
return dialer.DialContext(ctx, network, ipv6Address)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ func (rd *RealDebrid) UnrestrictUntilOk(link string, serveFromRclone bool) *Down
|
|||||||
if !strings.HasPrefix(link, "http") {
|
if !strings.HasPrefix(link, "http") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
resp, _ := rd.UnrestrictLink(link, serveFromRclone)
|
resp, err := rd.UnrestrictLink(link, serveFromRclone)
|
||||||
if resp != nil {
|
if err != nil {
|
||||||
return resp
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rd *RealDebrid) CanFetchFirstByte(url string) bool {
|
func (rd *RealDebrid) CanFetchFirstByte(url string) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user