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