This commit is contained in:
Ben Sarmiento
2023-11-27 21:50:00 +01:00
parent a7623de410
commit c8334ecb3b
15 changed files with 277 additions and 221 deletions

View File

@@ -4,13 +4,11 @@ import (
"fmt"
"os"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
)
func LoadZurgConfig(filename string) (ConfigInterface, error) {
log := logutil.NewLogger().Named("config")
func LoadZurgConfig(filename string, log *zap.SugaredLogger) (ConfigInterface, error) {
log.Debug("Loading config file ", filename)
content, err := os.ReadFile(filename)
if err != nil {

View File

@@ -12,6 +12,10 @@ import (
"gopkg.in/yaml.v3"
)
const (
ALL_TORRENTS = "__all__"
)
func loadV1Config(content []byte, log *zap.SugaredLogger) (*ZurgConfigV1, error) {
var configV1 ZurgConfigV1
if err := yaml.Unmarshal(content, &configV1); err != nil {
@@ -26,12 +30,13 @@ func (z *ZurgConfigV1) GetVersion() string {
}
func (z *ZurgConfigV1) GetDirectories() []string {
rootDirectories := make([]string, len(z.Directories))
rootDirectories := make([]string, len(z.Directories)+1)
i := 0
for directory := range z.Directories {
rootDirectories[i] = directory
i++
}
rootDirectories[i] = ALL_TORRENTS
return rootDirectories
}
@@ -63,11 +68,15 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
copy(temp, v)
result[k] = temp
}
result[ALL_TORRENTS] = []string{ALL_TORRENTS} // Add special group for all torrents
return result
}
func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentIDs, fileNames []string) bool {
if directory == ALL_TORRENTS {
return true
}
if _, ok := z.Directories[directory]; !ok {
return false
}