Fix chunk manager

This commit is contained in:
Ben Sarmiento
2023-11-14 16:55:24 +01:00
parent 16505ec33f
commit 4da9416bec
4 changed files with 24 additions and 25 deletions

View File

@@ -8,7 +8,6 @@ import (
"syscall"
"time"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"go.uber.org/zap"
@@ -22,15 +21,14 @@ type Downloader struct {
callbacks map[RequestID][]DownloadCallback
lock sync.Mutex
storage *Storage
c config.ConfigInterface
t *torrent.TorrentManager
torMgr *torrent.TorrentManager
log *zap.SugaredLogger
}
type DownloadCallback func(error, []byte)
// NewDownloader creates a new download manager
func NewDownloader(threads int, storage *Storage, bufferSize int64, t *torrent.TorrentManager, c config.ConfigInterface) (*Downloader, error) {
func NewDownloader(threads int, storage *Storage, bufferSize int64, torMgr *torrent.TorrentManager) (*Downloader, error) {
rlog := logutil.NewLogger()
log := rlog.Named("downloader")
@@ -39,8 +37,7 @@ func NewDownloader(threads int, storage *Storage, bufferSize int64, t *torrent.T
queue: make(chan *Request, 100),
callbacks: make(map[RequestID][]DownloadCallback, 100),
storage: storage,
c: c,
t: t,
torMgr: torMgr,
log: log,
}
@@ -105,7 +102,7 @@ func (d *Downloader) downloadFromAPI(request *Request, buffer []byte, delay int6
time.Sleep(time.Duration(delay) * time.Second)
}
resp := d.t.UnrestrictUntilOk(request.file.Link)
resp := d.torMgr.UnrestrictUntilOk(request.file.Link)
if resp == nil {
return fmt.Errorf("cannot unrestrict file %s %s", request.file.Path, request.file.Link)
}