Fix traffic computation and optimize open ended requests

This commit is contained in:
Ben Adrian Sarmiento
2024-07-04 03:39:53 +02:00
parent 6deeb45db0
commit 49432dd810
5 changed files with 100 additions and 106 deletions

View File

@@ -6,7 +6,6 @@ import (
"net/url"
"path/filepath"
"strings"
"sync/atomic"
"github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/internal/dav"
@@ -21,14 +20,13 @@ import (
)
type Handlers struct {
downloader *universal.Downloader
torMgr *torrent.TorrentManager
cfg config.ConfigInterface
rd *realdebrid.RealDebrid
workerPool *ants.Pool
hosts []string
trafficOnStartup atomic.Uint64
log *logutil.Logger
downloader *universal.Downloader
torMgr *torrent.TorrentManager
cfg config.ConfigInterface
rd *realdebrid.RealDebrid
workerPool *ants.Pool
hosts []string
log *logutil.Logger
}
func init() {
@@ -48,16 +46,6 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
log: log,
}
trafficDetails, err := rd.GetTrafficDetails()
if err != nil {
log.Errorf("Failed to get traffic details: %v", err)
trafficDetails = make(map[string]int64)
}
hs.trafficOnStartup.Store(uint64(0))
if _, ok := trafficDetails["real-debrid.com"]; ok {
hs.trafficOnStartup.Store(uint64(trafficDetails["real-debrid.com"]))
}
if cfg.GetUsername() != "" {
router.Use(hs.basicAuth)
}