diff --git a/internal/config/v1.go b/internal/config/v1.go index 5812605..3d9e2dd 100644 --- a/internal/config/v1.go +++ b/internal/config/v1.go @@ -1,7 +1,6 @@ package config import ( - "fmt" "regexp" "strings" @@ -29,10 +28,8 @@ 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 diff --git a/internal/dav/router.go b/internal/dav/router.go index d9044de..79f8f22 100644 --- a/internal/dav/router.go +++ b/internal/dav/router.go @@ -1,7 +1,6 @@ package dav import ( - "fmt" "log" "net/http" "os" @@ -17,8 +16,6 @@ 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) { diff --git a/internal/dav/util.go b/internal/dav/util.go index c50bc5f..8a64963 100644 --- a/internal/dav/util.go +++ b/internal/dav/util.go @@ -23,9 +23,9 @@ func findAllTorrentsWithName(t *torrent.TorrentManager, directory, torrentName s var matchingTorrents []torrent.Torrent torrents := t.GetByDirectory(directory) - for _, torrent := range torrents { - if torrent.Name == torrentName || strings.HasPrefix(torrent.Name, torrentName) { - matchingTorrents = append(matchingTorrents, torrent) + for i := range torrents { + if torrents[i].Name == torrentName || strings.HasPrefix(torrents[i].Name, torrentName) { + matchingTorrents = append(matchingTorrents, torrents[i]) } } diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 365eb5c..fc49f82 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -2,7 +2,6 @@ package torrent import ( "encoding/gob" - "fmt" "log" "os" "strings" @@ -58,9 +57,9 @@ func (t *TorrentManager) getAll() []Torrent { } torrentsV2 = append(torrentsV2, torrentV2) } + log.Printf("Fetched %d torrents", len(torrentsV2)) version := t.config.GetVersion() - fmt.Println("config version", version) if version == "v1" { configV1 := t.config.(*config.ZurgConfigV1) groupMap := configV1.GetGroupMap() @@ -70,23 +69,23 @@ func (t *TorrentManager) getAll() []Torrent { for _, directory := range directories { 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 } } } } } - log.Printf("Fetched %d torrents", len(torrentsV2)) + log.Println("Finished mapping to groups") + return torrentsV2 } func (t *TorrentManager) GetByDirectory(directory string) []Torrent { var torrents []Torrent - for _, torrent := range t.torrents { - for _, dir := range torrent.Directories { + for i := range t.torrents { + for _, dir := range t.torrents[i].Directories { if dir == directory { - torrents = append(torrents, torrent) + torrents = append(torrents, t.torrents[i]) } } } @@ -174,17 +173,17 @@ func (t *TorrentManager) getInfo(torrentID string) *Torrent { } func (t *TorrentManager) GetInfo(torrentID string) *Torrent { - for _, torrent := range t.torrents { - if torrent.ID == torrentID { - return &torrent + for i := range t.torrents { + if t.torrents[i].ID == torrentID { + return &t.torrents[i] } } return t.getInfo(torrentID) } func (t *TorrentManager) getByID(torrentID string) *Torrent { - for i, torrent := range t.torrents { - if torrent.ID == torrentID { + for i := range t.torrents { + if t.torrents[i].ID == torrentID { return &t.torrents[i] } }