From 7509f0fa590b38934dba286d5d9f50169a39d5d0 Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Thu, 11 Jul 2024 22:33:20 +0200 Subject: [PATCH] Refactors 2 --- internal/torrent/bins.go | 11 ----------- internal/torrent/manager.go | 1 - internal/torrent/refresh.go | 15 +++++++++++---- internal/torrent/repair.go | 1 - pkg/dav/response.go | 3 +-- pkg/dav/util.go | 29 ----------------------------- 6 files changed, 12 insertions(+), 48 deletions(-) diff --git a/internal/torrent/bins.go b/internal/torrent/bins.go index 7c64ceb..fb52a39 100644 --- a/internal/torrent/bins.go +++ b/internal/torrent/bins.go @@ -64,17 +64,6 @@ func (t *TorrentManager) willDeleteOnceDone(torrentId string) { t.persistBins() } -func (t *TorrentManager) cleanupBins(freshIDs mapset.Set[string]) { - t.OnceDoneBin.Clone().Each(func(entry string) bool { - // check for: delete once done cases - if !freshIDs.ContainsOne(entry) { - t.OnceDoneBin.Remove(entry) - } - return false - }) - t.persistBins() -} - // deleteOnceDone checks if the torrent is in the OnceDoneBin and deletes it if it is. // returns true if the torrent was in the bin and was deleted, false otherwise func (t *TorrentManager) deleteOnceDone(completedTorrentId string, failed bool) { diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 8e25461..ad461dd 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -52,7 +52,6 @@ type TorrentManager struct { latestState *LibraryState - repairChan chan *Torrent RepairQueue mapset.Set[*Torrent] repairRunning bool repairRunningMu sync.Mutex diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index b055299..c6c2334 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -71,10 +71,6 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) { }) } - t.workerPool.Submit(func() { - t.cleanupBins(freshIDs) - }) - wg.Wait() close(mergeChan) @@ -116,6 +112,17 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) { t.log.Infof("Compiled into %d unique torrents", allTorrents.Count()) + t.workerPool.Submit(func() { + t.OnceDoneBin.Clone().Each(func(entry string) bool { + // check for: delete once done cases + if !freshIDs.ContainsOne(entry) { + t.OnceDoneBin.Remove(entry) + } + return false + }) + t.persistBins() + }) + // delete info files that are no longer present // it also runs binOnceDone (needed for cleanup every refresh) t.getInfoFiles().Each(func(path string) bool { diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index 1358ebc..86f09b4 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -26,7 +26,6 @@ func (t *TorrentManager) StartRepairJob() { return } - t.repairChan = make(chan *Torrent) t.RepairQueue = mapset.NewSet[*Torrent]() t.RepairAllTrigger = make(chan struct{}) diff --git a/pkg/dav/response.go b/pkg/dav/response.go index cdcfa10..69dd133 100644 --- a/pkg/dav/response.go +++ b/pkg/dav/response.go @@ -66,10 +66,9 @@ func VidHubFile(path string, fileSize int64, added string) string { %s %d %s - %s HTTP/1.1 200 OK -`, customPathEscape(path), html.EscapeString(filename), fileSize, added, getContentType(filename)) +`, customPathEscape(path), html.EscapeString(filename), fileSize, added) } diff --git a/pkg/dav/util.go b/pkg/dav/util.go index 0d30dbf..da86918 100644 --- a/pkg/dav/util.go +++ b/pkg/dav/util.go @@ -2,7 +2,6 @@ package dav import ( "net/url" - "path/filepath" "strings" ) @@ -27,31 +26,3 @@ func escapeForXML(input string) string { input = strings.ReplaceAll(input, "@", "%40") return input } - -func getContentType(filename string) string { - filename = strings.ToLower(filename) - switch filepath.Ext(filename) { - case ".avi": - return "video/x-msvideo" - case ".m2ts": - return "video/mp2t" - case ".m4v": - return "video/x-m4v" - case ".mkv": - return "video/x-matroska" - case ".mov": - return "video/quicktime" - case ".mp4": - return "video/mp4" - case ".mpg": - return "video/mpeg" - case ".mpeg": - return "video/mpeg" - case ".ts": - return "video/mp2t" - case ".wmv": - return "video/x-ms-wmv" - default: - return "application/octet-stream" - } -}