package handlers import ( "fmt" "net/http" "os" "runtime" "strings" "github.com/debridmediamanager/zurg/internal/config" "github.com/debridmediamanager/zurg/internal/version" "github.com/debridmediamanager/zurg/pkg/realdebrid" ) type SponsorResponse struct { Patreon string `json:"patreon"` Github string `json:"github"` 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"` // Replace UserInfoType with the actual type 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"` ImmediateBin []string `json:"immediate_bin"` OnceDoneBin []string `json:"once_done_bin"` } func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) { userInfo, err := zr.api.GetUserInformation() if err != nil { http.Error(resp, err.Error(), http.StatusInternalServerError) return } var mem runtime.MemStats runtime.ReadMemStats(&mem) allTorrents, _ := zr.torMgr.DirectoryMap.Get(config.ALL_TORRENTS) repairQueueStr := "" if zr.torMgr.RepairQueue == nil { repairQueueStr = "repair is disabled" } else if zr.torMgr.RepairQueue.IsEmpty() { repairQueueStr = "empty" } else { for _, torrent := range zr.torMgr.RepairQueue.ToSlice() { if torrent == nil { repairQueueStr += " ⬅ 'all torrents'" } else { repairQueueStr += fmt.Sprintf(" ⬅ %s", zr.torMgr.GetKey(torrent)) } } } 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, LibrarySize: allTorrents.Count(), RepairQueueStr: 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", Paypal: "https://paypal.me/yowmamasita", }, Config: zr.cfg.GetConfig(), ImmediateBin: zr.torMgr.ImmediateBin.ToSlice(), OnceDoneBin: zr.torMgr.OnceDoneBin.ToSlice(), } out := `
| zurg | ||
|---|---|---|
| Version | %s | |
| Built At | %s | |
| Git Commit | %s | |
| HTML | %s | |
| DAV | %s | |
| Infuse | %s | |
| Logs | %s | |
| Library Size | %d items | |
| Repair Queue | %s | |
| Memory Allocation | %d MB | |
| Total Memory Allocated | %d MB | |
| System Memory | %d MB | |
| Number of GC Cycles | %d | |
| Process ID | %d | |
| Sponsor Zurg | Patreon | %s |
| Github | %s | |
| Paypal | %s | |
| User Info | Username | %s |
| Points | %d | |
| Locale | %s | |
| Type | %s | |
| Premium | %d days | |
| Expiration | %s | |
| Config | Version | %s |
| Token | %s | |
| Host | %s | |
| Port | %s | |
| Workers | %d running / %d free / %d total | |
| Refresh Every... | %d secs | |
| Retain RD Torrent Name | %t | |
| Retain Folder Name Extension | %t | |
| Can Repair | %t | |
| Action to take on RAR'ed torrents | %s | |
| Repair Every... | %d mins | |
| Refresh Download Mount Every... | %d mins | |
| Dump Torrents Every... | %d mins | |
| API Timeout | %d secs | |
| Download Timeout | %d secs | |
| Retries Until Failed | %d | |
| Network Buffer Size | %d bytes | |
| Serve From Rclone | %t | |
| Force IPv6 | %t | |
| On Library Update | %v | |
| Immediate Bin | %v | |
| Once Done Bin | %v | |
| Utilities | ||
| Debug | ||