Refactors 2
This commit is contained in:
@@ -64,17 +64,6 @@ func (t *TorrentManager) willDeleteOnceDone(torrentId string) {
|
|||||||
t.persistBins()
|
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.
|
// 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
|
// returns true if the torrent was in the bin and was deleted, false otherwise
|
||||||
func (t *TorrentManager) deleteOnceDone(completedTorrentId string, failed bool) {
|
func (t *TorrentManager) deleteOnceDone(completedTorrentId string, failed bool) {
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ type TorrentManager struct {
|
|||||||
|
|
||||||
latestState *LibraryState
|
latestState *LibraryState
|
||||||
|
|
||||||
repairChan chan *Torrent
|
|
||||||
RepairQueue mapset.Set[*Torrent]
|
RepairQueue mapset.Set[*Torrent]
|
||||||
repairRunning bool
|
repairRunning bool
|
||||||
repairRunningMu sync.Mutex
|
repairRunningMu sync.Mutex
|
||||||
|
|||||||
@@ -71,10 +71,6 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
t.workerPool.Submit(func() {
|
|
||||||
t.cleanupBins(freshIDs)
|
|
||||||
})
|
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
close(mergeChan)
|
close(mergeChan)
|
||||||
|
|
||||||
@@ -116,6 +112,17 @@ func (t *TorrentManager) refreshTorrents(initialRun bool) {
|
|||||||
|
|
||||||
t.log.Infof("Compiled into %d unique torrents", allTorrents.Count())
|
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
|
// delete info files that are no longer present
|
||||||
// it also runs binOnceDone (needed for cleanup every refresh)
|
// it also runs binOnceDone (needed for cleanup every refresh)
|
||||||
t.getInfoFiles().Each(func(path string) bool {
|
t.getInfoFiles().Each(func(path string) bool {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ func (t *TorrentManager) StartRepairJob() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t.repairChan = make(chan *Torrent)
|
|
||||||
t.RepairQueue = mapset.NewSet[*Torrent]()
|
t.RepairQueue = mapset.NewSet[*Torrent]()
|
||||||
t.RepairAllTrigger = make(chan struct{})
|
t.RepairAllTrigger = make(chan struct{})
|
||||||
|
|
||||||
|
|||||||
@@ -66,10 +66,9 @@ func VidHubFile(path string, fileSize int64, added string) string {
|
|||||||
<d:displayname>%s</d:displayname>
|
<d:displayname>%s</d:displayname>
|
||||||
<d:getcontentlength>%d</d:getcontentlength>
|
<d:getcontentlength>%d</d:getcontentlength>
|
||||||
<d:getlastmodified>%s</d:getlastmodified>
|
<d:getlastmodified>%s</d:getlastmodified>
|
||||||
<d:getcontenttype>%s</d:getcontenttype>
|
|
||||||
<d:resourcetype></d:resourcetype>
|
<d:resourcetype></d:resourcetype>
|
||||||
</d:prop>
|
</d:prop>
|
||||||
<d:status>HTTP/1.1 200 OK</d:status>
|
<d:status>HTTP/1.1 200 OK</d:status>
|
||||||
</d:propstat>
|
</d:propstat>
|
||||||
</d:response>`, customPathEscape(path), html.EscapeString(filename), fileSize, added, getContentType(filename))
|
</d:response>`, customPathEscape(path), html.EscapeString(filename), fileSize, added)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package dav
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,31 +26,3 @@ func escapeForXML(input string) string {
|
|||||||
input = strings.ReplaceAll(input, "@", "%40")
|
input = strings.ReplaceAll(input, "@", "%40")
|
||||||
return input
|
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user