experimental

This commit is contained in:
Mukhtar Akere
2025-03-15 21:08:15 +01:00
parent b4e4db27fb
commit 2d29996d2c
11 changed files with 281 additions and 127 deletions

View File

@@ -11,6 +11,7 @@ import (
"net/http"
"os"
"path"
"sort"
"strings"
"sync"
"sync/atomic"
@@ -60,19 +61,23 @@ func (h *Handler) refreshRootListing() {
return
}
var files []os.FileInfo
h.cache.GetTorrents().Range(func(key, value interface{}) bool {
cachedTorrent := value.(*cache.CachedTorrent)
torrents := h.cache.GetTorrentNames()
files := make([]os.FileInfo, 0, len(torrents))
for name, cachedTorrent := range torrents {
if cachedTorrent != nil && cachedTorrent.Torrent != nil {
files = append(files, &FileInfo{
name: cachedTorrent.Torrent.Name,
name: name,
size: 0,
mode: 0755 | os.ModeDir,
modTime: time.Now(),
isDir: true,
})
}
return true
}
sort.Slice(files, func(i, j int) bool {
return files[i].Name() < files[j].Name()
})
h.rootListing.Store(files)

View File

@@ -4,8 +4,12 @@ import (
"context"
"fmt"
"github.com/go-chi/chi/v5"
"github.com/sirrobot01/debrid-blackhole/internal/config"
"github.com/sirrobot01/debrid-blackhole/internal/logger"
"github.com/sirrobot01/debrid-blackhole/pkg/service"
"html/template"
"net/http"
"os"
"sync"
)
@@ -14,15 +18,15 @@ type WebDav struct {
}
func New() *WebDav {
//svc := service.GetService()
//cfg := config.GetConfig()
svc := service.GetService()
cfg := config.GetConfig()
w := &WebDav{
Handlers: make([]*Handler, 0),
}
//for name, c := range svc.DebridCache.GetCaches() {
// h := NewHandler(name, c, logger.NewLogger(fmt.Sprintf("%s-webdav", name), cfg.LogLevel, os.Stdout))
// w.Handlers = append(w.Handlers, h)
//}
for name, c := range svc.DebridCache.GetCaches() {
h := NewHandler(name, c, logger.NewLogger(fmt.Sprintf("%s-webdav", name), cfg.LogLevel, os.Stdout))
w.Handlers = append(w.Handlers, h)
}
return w
}