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