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" mapset "github.com/deckarep/golang-set/v2" ) 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"` ImmediateBin mapset.Set[string] `json:"immediate_bin"` OnceDoneBin mapset.Set[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) 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(), ImmediateBin: zr.torMgr.ImmediateBin, OnceDoneBin: zr.torMgr.OnceDoneBin, } 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 | |
| Repair Every... | %d mins | |
| Delete Rar Files | %t | |
| API Timeout | %d secs | |
| Get torrents count | %d at a time | |
| Download Timeout | %d secs | |
| Use Download Mount | %t | |
| Refresh Download Mount Every... | %d mins | |
| Rate Limit Sleep for... | %d secs | |
| Retries Until Failed | %d | |
| Network Buffer Size | %d bytes | |
| Serve From Rclone | %t | |
| Force IPv6 | %t | |
| On Library Update | %v | |
| Immediate Bin | %s | |
| Once Done Bin | %s | |
| Utilities | ||