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 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"` } 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) 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, 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(), } out := `
zurg
Version %s
Built At %s
Git Commit %s
HTML %s
DAV %s
Infuse %s
Logs %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
Delete Rar Files %t
API Timeout %d secs
Download Timeout %d secs
Use Download Mount %t
Rate Limit Sleep for... %d secs
Retries Until Failed %d
Network Buffer Size %d bytes
Serve From Rclone %t
Verify Download Link %t
Force IPv6 %t
On Library Update %s
Utilities
` out = fmt.Sprintf(out, response.Version, response.BuiltAt, response.GitCommit, response.Html, response.Html, response.Dav, response.Dav, response.Infuse, response.Infuse, response.Logs, response.Logs, response.MemAlloc, response.TotalAlloc, response.Sys, response.NumGC, response.PID, response.Sponsor.Patreon, response.Sponsor.Patreon, response.Sponsor.Github, response.Sponsor.Github, response.Sponsor.Paypal, response.Sponsor.Paypal, response.UserInfo.Username, response.UserInfo.Points, response.UserInfo.Locale, response.UserInfo.Type, response.UserInfo.Premium/86400, strings.Replace(response.UserInfo.Expiration, "Z", "+01:00", 1), response.Config.Version, strings.Replace(response.Config.Token, response.Config.Token[len(response.Config.Token)-48:], "*****", 1), response.Config.GetHost(), response.Config.GetPort(), zr.workerPool.Running(), zr.workerPool.Free(), zr.workerPool.Cap(), response.Config.GetRefreshEverySecs(), response.Config.EnableRetainRDTorrentName(), response.Config.EnableRetainFolderNameExtension(), response.Config.EnableRepair(), response.Config.ShouldDeleteRarFiles(), response.Config.GetApiTimeoutSecs(), response.Config.GetDownloadTimeoutSecs(), response.Config.EnableDownloadMount(), response.Config.GetRateLimitSleepSecs(), response.Config.GetRetriesUntilFailed(), response.Config.GetNetworkBufferSize(), response.Config.ShouldServeFromRclone(), response.Config.ShouldVerifyDownloadLink(), response.Config.ShouldForceIPv6(), response.Config.GetOnLibraryUpdate(), ) fmt.Fprint(resp, out) } func (zr *Handlers) handleRebootWorkerPool(resp http.ResponseWriter, req *http.Request) { // zr.workerPool.Release() zr.workerPool.Reboot() zr.log.Infof("Rebooted worker pool") fmt.Fprint(resp, "Rebooted worker pool, please close this window") } func (zr *Handlers) handleRebootRefreshPool(resp http.ResponseWriter, req *http.Request) { zr.refreshPool.Release() // zr.refreshPool.Reboot() // zr.torMgr.StartRefreshJob() zr.log.Infof("Rebooted refresh pool") fmt.Fprint(resp, "Rebooted refresh pool, please close this window") } func (zr *Handlers) handleRebootRepairPool(resp http.ResponseWriter, req *http.Request) { zr.repairPool.Release() // zr.repairPool.Reboot() // zr.torMgr.StartRepairJob() zr.log.Infof("Rebooted repair pool") fmt.Fprint(resp, "Rebooted repair pool, please close this window") } func bToMb(b uint64) uint64 { return b / 1024 / 1024 }