Changelog 0.3.0

This commit is contained in:
Mukhtar Akere
2024-11-30 15:46:58 +01:00
parent df2aa4e361
commit a51364d150
53 changed files with 2019 additions and 679 deletions

View File

@@ -2,6 +2,7 @@ package cmd
import (
"cmp"
"context"
"goBlack/common"
"goBlack/pkg/debrid"
"goBlack/pkg/proxy"
@@ -9,32 +10,44 @@ import (
"sync"
)
func Start(config *common.Config) {
func Start(ctx context.Context, config *common.Config) error {
maxCacheSize := cmp.Or(config.MaxCacheSize, 1000)
cache := common.NewCache(maxCacheSize)
deb := debrid.NewDebrid(config.Debrids, cache)
var wg sync.WaitGroup
errChan := make(chan error, 2)
if config.Proxy.Enabled {
p := proxy.NewProxy(*config, deb, cache)
wg.Add(1)
go func() {
defer wg.Done()
p.Start()
if err := proxy.NewProxy(*config, deb, cache).Start(ctx); err != nil {
errChan <- err
}
}()
}
if config.QBitTorrent.Port != "" {
qb := qbit.NewQBit(config, deb, cache)
wg.Add(1)
go func() {
defer wg.Done()
qb.Start()
if err := qbit.Start(ctx, config, deb, cache); err != nil {
errChan <- err
}
}()
}
// Wait indefinitely
wg.Wait()
go func() {
wg.Wait()
close(errChan)
}()
// Wait for context cancellation or completion or error
select {
case err := <-errChan:
return err
case <-ctx.Done():
return ctx.Err()
}
}