Fix grouping
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -16,7 +17,7 @@ func loadV1Config(content []byte) (*ZurgConfigV1, error) {
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetVersion() string {
|
||||
return z.Version
|
||||
return "v1"
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetDirectories() []string {
|
||||
@@ -28,23 +29,15 @@ func (z *ZurgConfigV1) GetDirectories() []string {
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
||||
fmt.Println("Getting group map")
|
||||
var groupMap = make(map[string][]string)
|
||||
for directory, val := range z.Directories {
|
||||
fmt.Println(directory, val.Group)
|
||||
groupMap[val.Group] = append(groupMap[val.Group], directory)
|
||||
}
|
||||
return groupMap
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetDirectoriesByGroup(group string) []string {
|
||||
var groupDirs []string
|
||||
for directory := range z.Directories {
|
||||
if z.Directories[directory].Group == group {
|
||||
groupDirs = append(groupDirs, directory)
|
||||
}
|
||||
}
|
||||
return groupDirs
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) MeetsConditions(directory, fileID, torrentName string) bool {
|
||||
if _, ok := z.Directories[directory]; !ok {
|
||||
return false
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dav
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -16,6 +17,8 @@ func Router(mux *http.ServeMux) {
|
||||
log.Panicf("Config failed to load: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("config version", c.GetDirectories())
|
||||
|
||||
t := torrent.NewTorrentManager(os.Getenv("RD_TOKEN"), c)
|
||||
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package torrent
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -50,25 +51,29 @@ func (t *TorrentManager) getAll() []Torrent {
|
||||
return nil
|
||||
}
|
||||
var torrentsV2 []Torrent
|
||||
for _, torrent := range torrents {
|
||||
torrentV2 := Torrent{
|
||||
Torrent: torrent,
|
||||
SelectedFiles: nil,
|
||||
}
|
||||
torrentsV2 = append(torrentsV2, torrentV2)
|
||||
}
|
||||
|
||||
version := t.config.GetVersion()
|
||||
fmt.Println("config version", version)
|
||||
if version == "v1" {
|
||||
configV1 := t.config.(*config.ZurgConfigV1)
|
||||
groupMap := configV1.GetGroupMap()
|
||||
for _, directories := range groupMap {
|
||||
for _, torrent := range torrents {
|
||||
// process grouping
|
||||
torrentV2 := Torrent{
|
||||
Torrent: torrent,
|
||||
SelectedFiles: nil,
|
||||
}
|
||||
for group, directories := range groupMap {
|
||||
log.Printf("Processing group %s\n", group)
|
||||
for i := range torrents {
|
||||
for _, directory := range directories {
|
||||
if configV1.MeetsConditions(directory, torrent.ID, torrent.Name) {
|
||||
torrentV2.Directories = append(torrentV2.Directories, directory)
|
||||
if configV1.MeetsConditions(directory, torrentsV2[i].ID, torrentsV2[i].Name) {
|
||||
torrentsV2[i].Directories = append(torrentsV2[i].Directories, directory)
|
||||
fmt.Println(torrentsV2[i].Name, torrentsV2[i].Directories)
|
||||
break
|
||||
}
|
||||
}
|
||||
torrentsV2 = append(torrentsV2, torrentV2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,10 +81,6 @@ func (t *TorrentManager) getAll() []Torrent {
|
||||
return torrentsV2
|
||||
}
|
||||
|
||||
func (t *TorrentManager) GetAll() []Torrent {
|
||||
return t.torrents
|
||||
}
|
||||
|
||||
func (t *TorrentManager) GetByDirectory(directory string) []Torrent {
|
||||
var torrents []Torrent
|
||||
for _, torrent := range t.torrents {
|
||||
|
||||
Reference in New Issue
Block a user