Sort repair queue

This commit is contained in:
Ben Adrian Sarmiento
2024-06-24 17:22:43 +02:00
parent 4049fa7d83
commit 08867d8fea

View File

@@ -19,26 +19,26 @@ type SponsorResponse struct {
Paypal string `json:"paypal"`
}
type RootResponse struct {
Version string `json:"version"`
BuiltAt string `json:"built_at"`
GitCommit string `json:"git_commit"`
Html string `json:"html"`
Dav string `json:"dav"`
Infuse string `json:"infuse"`
Logs string `json:"logs"`
UserInfo *realdebrid.User `json:"user_info"`
RDTrafficUsed uint64 `json:"rd_traffic_used"`
LibrarySize int `json:"library_size"` // Number of torrents in the library
RepairQueueStr string `json:"repair_queue"` // List of torrents in the repair queue
MemAlloc uint64 `json:"mem_alloc"` // Memory allocation in MB
TotalAlloc uint64 `json:"total_alloc"` // Total memory allocated in MB
Sys uint64 `json:"sys"` // System memory in MB
NumGC uint32 `json:"num_gc"` // Number of completed GC cycles
PID int `json:"pid"` // Process ID
Sponsor SponsorResponse `json:"sponsor_zurg"` // Sponsorship links
Config config.ZurgConfig `json:"config"`
IDsToDelete []string `json:"ids_to_delete"`
Hosts []string `json:"hosts"`
Version string `json:"version"`
BuiltAt string `json:"built_at"`
GitCommit string `json:"git_commit"`
Html string `json:"html"`
Dav string `json:"dav"`
Infuse string `json:"infuse"`
Logs string `json:"logs"`
UserInfo *realdebrid.User `json:"user_info"`
RDTrafficUsed uint64 `json:"rd_traffic_used"`
LibrarySize int `json:"library_size"` // Number of torrents in the library
TorrentsToRepair string `json:"repair_queue"` // List of torrents in the repair queue
MemAlloc uint64 `json:"mem_alloc"` // Memory allocation in MB
TotalAlloc uint64 `json:"total_alloc"` // Total memory allocated in MB
Sys uint64 `json:"sys"` // System memory in MB
NumGC uint32 `json:"num_gc"` // Number of completed GC cycles
PID int `json:"pid"` // Process ID
Sponsor SponsorResponse `json:"sponsor_zurg"` // Sponsorship links
Config config.ZurgConfig `json:"config"`
IDsToDelete []string `json:"ids_to_delete"`
Hosts []string `json:"hosts"`
}
func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
@@ -61,17 +61,18 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
repairQueueStr := ""
if zr.torMgr.RepairQueue == nil {
repairQueueStr = "repair is disabled"
repairQueueStr = "uninitialized"
} else if zr.torMgr.RepairQueue.IsEmpty() {
repairQueueStr = "empty"
} else {
var repairList []string
for _, torrent := range zr.torMgr.RepairQueue.ToSlice() {
if torrent == nil {
repairQueueStr += " ⬅ 'all torrents'"
} else {
repairQueueStr += fmt.Sprintf(" ⬅ %s", zr.torMgr.GetKey(torrent))
if torrent != nil {
repairList = append(repairList, zr.torMgr.GetKey(torrent))
}
}
sort.Strings(repairList)
repairQueueStr = strings.Join(repairList, ", ")
}
sortedIDs := zr.torMgr.OnceDoneBin.ToSlice()
@@ -85,22 +86,22 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
}
response := RootResponse{
Version: version.GetVersion(),
BuiltAt: version.GetBuiltAt(),
GitCommit: version.GetGitCommit(),
Html: fmt.Sprintf("//%s/http/", req.Host),
Dav: fmt.Sprintf("//%s/dav/", req.Host),
Infuse: fmt.Sprintf("//%s/infuse/", req.Host),
Logs: fmt.Sprintf("//%s/logs/", req.Host),
UserInfo: userInfo,
RDTrafficUsed: bToGb(uint64(rdTrafficUsed)),
LibrarySize: allTorrents.Count(),
RepairQueueStr: repairQueueStr,
MemAlloc: bToMb(mem.Alloc),
TotalAlloc: bToMb(mem.TotalAlloc),
Sys: bToMb(mem.Sys),
NumGC: mem.NumGC,
PID: os.Getpid(),
Version: version.GetVersion(),
BuiltAt: version.GetBuiltAt(),
GitCommit: version.GetGitCommit(),
Html: fmt.Sprintf("//%s/http/", req.Host),
Dav: fmt.Sprintf("//%s/dav/", req.Host),
Infuse: fmt.Sprintf("//%s/infuse/", req.Host),
Logs: fmt.Sprintf("//%s/logs/", req.Host),
UserInfo: userInfo,
RDTrafficUsed: bToGb(uint64(rdTrafficUsed)),
LibrarySize: allTorrents.Count(),
TorrentsToRepair: repairQueueStr,
MemAlloc: bToMb(mem.Alloc),
TotalAlloc: bToMb(mem.TotalAlloc),
Sys: bToMb(mem.Sys),
NumGC: mem.NumGC,
PID: os.Getpid(),
Sponsor: SponsorResponse{
Patreon: "https://www.patreon.com/debridmediamanager",
Github: "https://github.com/sponsors/debridmediamanager",
@@ -307,7 +308,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
<td colspan="2">%v</td>
</tr>
<tr>
<td>Repair Queue</td>
<td>Torrents to be repaired</td>
<td colspan="2">%s</td>
</tr>
<tr>
@@ -409,7 +410,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
response.Config.ShouldForceIPv6(),
response.Config.GetOnLibraryUpdate(),
response.IDsToDelete,
response.RepairQueueStr,
response.TorrentsToRepair,
response.Hosts,
)