From aa1a514663445a30b7a41db5f8cf9368bdc5bbe2 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sat, 9 Dec 2023 15:52:19 +0100 Subject: [PATCH] Reformat debug page --- internal/router/router.go | 229 ++++++++++++++++++++++++++++++++++++-- pkg/realdebrid/types.go | 1 - 2 files changed, 222 insertions(+), 8 deletions(-) diff --git a/internal/router/router.go b/internal/router/router.go index 5e5d3a1..6d92cd3 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -5,6 +5,7 @@ import ( "net/http" "os" "runtime" + "strings" "github.com/debridmediamanager/zurg/internal/config" "github.com/debridmediamanager/zurg/internal/dav" @@ -15,12 +16,8 @@ import ( "github.com/debridmediamanager/zurg/pkg/logutil" "github.com/debridmediamanager/zurg/pkg/realdebrid" "github.com/julienschmidt/httprouter" - - jsoniter "github.com/json-iterator/go" ) -var json = jsoniter.ConfigCompatibleWithStandardLibrary - type ZurgRouter struct { getfile *universal.GetFile torMgr *torrent.TorrentManager @@ -192,6 +189,7 @@ type RootResponse struct { GitCommit string `json:"git_commit"` Dav string `json:"dav"` Html string `json:"html"` + 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 @@ -218,6 +216,7 @@ func (zr *ZurgRouter) rootHandler(resp http.ResponseWriter, req *http.Request, p GitCommit: version.GetGitCommit(), Dav: fmt.Sprintf("//%s/dav/", req.Host), Html: fmt.Sprintf("//%s/http/", req.Host), + Logs: fmt.Sprintf("//%s/logs/", req.Host), UserInfo: userInfo, MemAlloc: bToMb(mem.Alloc), TotalAlloc: bToMb(mem.TotalAlloc), @@ -232,9 +231,225 @@ func (zr *ZurgRouter) rootHandler(resp http.ResponseWriter, req *http.Request, p Config: zr.cfg.GetConfig(), } - if err := json.NewEncoder(resp).Encode(response); err != nil { - http.Error(resp, err.Error(), http.StatusInternalServerError) - } + out := ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
zurg
Version%s
Built At%s
Git Commit%s
DAV%s
HTML%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 ZurgPatreon%s
Github%s
Paypal%s
User InfoUsername%s
Points%d
Locale%s
Type%s
Premium%d seconds
Expiration%s
ConfigVersion%s
Token%s
Host%s
Port%s
Number of Workers%d
Refresh Every Seconds%d
Retain RD Torrent Name%t
Retain Folder Name Extension%t
Can Repair%t
Delete Rar Files%t
RealDebrid Timeout%d
Use Download Cache%t
Rate Limit Sleep Seconds%d
Retries Until Failed%d
Preferred Hosts%s
Network Buffer Size%d
Serve From Rclone%t
Verify Download Link%t
Force IPv6%t
On Library Update%s
+` + out = fmt.Sprintf(out, + version.GetVersion(), + version.GetBuiltAt(), + version.GetGitCommit(), + response.Dav, + response.Dav, + response.Html, + response.Html, + 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, + response.UserInfo.Expiration, + response.Config.Version, + strings.Replace(response.Config.Token, response.Config.Token[len(response.Config.Token)-48:], "*****", 1), + response.Config.Host, + response.Config.Port, + response.Config.NumOfWorkers, + response.Config.RefreshEverySeconds, + response.Config.RetainRDTorrentName, + response.Config.RetainFolderNameExtension, + response.Config.CanRepair, + response.Config.DeleteRarFiles, + response.Config.RealDebridTimeout, + response.Config.UseDownloadCache, + response.Config.RateLimitSleepSeconds, + response.Config.RetriesUntilFailed, + strings.Join(response.Config.PreferredHosts, ", "), + response.Config.NetworkBufferSize, + response.Config.ServeFromRclone, + response.Config.VerifyDownloadLink, + response.Config.ForceIPv6, + response.Config.OnLibraryUpdate, + ) + + fmt.Fprint(resp, out) } func (zr *ZurgRouter) logsHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) { diff --git a/pkg/realdebrid/types.go b/pkg/realdebrid/types.go index 42681a5..b56a62a 100644 --- a/pkg/realdebrid/types.go +++ b/pkg/realdebrid/types.go @@ -126,7 +126,6 @@ type User struct { Email string `json:"email"` Points int `json:"points"` // Fidelity points Locale string `json:"locale"` // User language - Avatar string `json:"avatar"` // URL Type string `json:"type"` // "premium" or "free" Premium int `json:"premium"` // seconds left as a Premium user Expiration string `json:"expiration"` // jsonDate