Increment traffic monitors async

This commit is contained in:
Ben Adrian Sarmiento
2024-06-25 02:19:54 +02:00
parent 7fc8a4e0c5
commit d095bf2dbf
3 changed files with 40 additions and 26 deletions

View File

@@ -20,13 +20,14 @@ import (
)
type Handlers struct {
downloader *universal.Downloader
torMgr *torrent.TorrentManager
cfg config.ConfigInterface
api *realdebrid.RealDebrid
workerPool *ants.Pool
hosts []string
log *logutil.Logger
downloader *universal.Downloader
torMgr *torrent.TorrentManager
cfg config.ConfigInterface
api *realdebrid.RealDebrid
workerPool *ants.Pool
hosts []string
initialTraffic int64
log *logutil.Logger
}
func init() {
@@ -46,6 +47,16 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
log: log,
}
trafficDetails, err := api.GetTrafficDetails()
if err != nil {
log.Errorf("Failed to get traffic details: %v", err)
trafficDetails = make(map[string]int64)
}
hs.initialTraffic = 0
if _, ok := trafficDetails["real-debrid.com"]; ok {
hs.initialTraffic = trafficDetails["real-debrid.com"]
}
if cfg.GetUsername() != "" {
router.Use(hs.basicAuth)
}