Reformat debug page

This commit is contained in:
Ben Sarmiento
2023-12-09 15:52:19 +01:00
parent 2b5e3d16ad
commit aa1a514663
2 changed files with 222 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"os" "os"
"runtime" "runtime"
"strings"
"github.com/debridmediamanager/zurg/internal/config" "github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/internal/dav" "github.com/debridmediamanager/zurg/internal/dav"
@@ -15,12 +16,8 @@ import (
"github.com/debridmediamanager/zurg/pkg/logutil" "github.com/debridmediamanager/zurg/pkg/logutil"
"github.com/debridmediamanager/zurg/pkg/realdebrid" "github.com/debridmediamanager/zurg/pkg/realdebrid"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
jsoniter "github.com/json-iterator/go"
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type ZurgRouter struct { type ZurgRouter struct {
getfile *universal.GetFile getfile *universal.GetFile
torMgr *torrent.TorrentManager torMgr *torrent.TorrentManager
@@ -192,6 +189,7 @@ type RootResponse struct {
GitCommit string `json:"git_commit"` GitCommit string `json:"git_commit"`
Dav string `json:"dav"` Dav string `json:"dav"`
Html string `json:"html"` Html string `json:"html"`
Logs string `json:"logs"`
UserInfo *realdebrid.User `json:"user_info"` // Replace UserInfoType with the actual type UserInfo *realdebrid.User `json:"user_info"` // Replace UserInfoType with the actual type
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
@@ -218,6 +216,7 @@ func (zr *ZurgRouter) rootHandler(resp http.ResponseWriter, req *http.Request, p
GitCommit: version.GetGitCommit(), GitCommit: version.GetGitCommit(),
Dav: fmt.Sprintf("//%s/dav/", req.Host), Dav: fmt.Sprintf("//%s/dav/", req.Host),
Html: fmt.Sprintf("//%s/http/", req.Host), Html: fmt.Sprintf("//%s/http/", req.Host),
Logs: fmt.Sprintf("//%s/logs/", req.Host),
UserInfo: userInfo, UserInfo: userInfo,
MemAlloc: bToMb(mem.Alloc), MemAlloc: bToMb(mem.Alloc),
TotalAlloc: bToMb(mem.TotalAlloc), TotalAlloc: bToMb(mem.TotalAlloc),
@@ -232,9 +231,225 @@ func (zr *ZurgRouter) rootHandler(resp http.ResponseWriter, req *http.Request, p
Config: zr.cfg.GetConfig(), Config: zr.cfg.GetConfig(),
} }
if err := json.NewEncoder(resp).Encode(response); err != nil { out := `<table border="1px">
http.Error(resp, err.Error(), http.StatusInternalServerError) <tr>
} <th colspan="3">zurg</th>
</tr>
<tr>
<td>Version</td>
<td colspan="2">%s</td>
</tr>
<tr>
<td>Built At</td>
<td colspan="2">%s</td>
</tr>
<tr>
<td>Git Commit</td>
<td colspan="2">%s</td>
</tr>
<tr>
<td>DAV</td>
<td colspan="2"><a href="%s">%s</a></td>
</tr>
<tr>
<td>HTML</td>
<td colspan="2"><a href="%s">%s</a></td>
</tr>
<tr>
<td>Logs</td>
<td colspan="2"><a href="%s">%s</a></td>
</tr>
<tr>
<td>Memory Allocation</td>
<td colspan="2">%d MB</td>
</tr>
<tr>
<td>Total Memory Allocated</td>
<td colspan="2">%d MB</td>
</tr>
<tr>
<td>System Memory</td>
<td colspan="2">%d MB</td>
</tr>
<tr>
<td>Number of GC Cycles</td>
<td colspan="2">%d</td>
</tr>
<tr>
<td>Process ID</td>
<td colspan="2">%d</td>
</tr>
<tr>
<td rowspan="3">Sponsor Zurg</td>
<td>Patreon</td>
<td><a href="%s">%s</a></td>
</tr>
<tr>
<td>Github</td>
<td><a href="%s">%s</a></td>
</tr>
<tr>
<td>Paypal</td>
<td><a href="%s">%s</a></td>
</tr>
<tr>
<td rowspan="6">User Info</td>
<td>Username</td>
<td>%s</td>
</tr>
<tr>
<td>Points</td>
<td>%d</td>
</tr>
<tr>
<td>Locale</td>
<td>%s</td>
</tr>
<tr>
<td>Type</td>
<td>%s</td>
</tr>
<tr>
<td>Premium</td>
<td>%d seconds</td>
</tr>
<tr>
<td>Expiration</td>
<td>%s</td>
</tr>
<tr>
<td rowspan="20">Config</td>
<td>Version</td>
<td>%s</td>
</tr>
<tr>
<td>Token</td>
<td>%s</td>
</tr>
<tr>
<td>Host</td>
<td>%s</td>
</tr>
<tr>
<td>Port</td>
<td>%s</td>
</tr>
<tr>
<td>Number of Workers</td>
<td>%d</td>
</tr>
<tr>
<td>Refresh Every Seconds</td>
<td>%d</td>
</tr>
<tr>
<td>Retain RD Torrent Name</td>
<td>%t</td>
</tr>
<tr>
<td>Retain Folder Name Extension</td>
<td>%t</td>
</tr>
<tr>
<td>Can Repair</td>
<td>%t</td>
</tr>
<tr>
<td>Delete Rar Files</td>
<td>%t</td>
</tr>
<tr>
<td>RealDebrid Timeout</td>
<td>%d</td>
</tr>
<tr>
<td>Use Download Cache</td>
<td>%t</td>
</tr>
<tr>
<td>Rate Limit Sleep Seconds</td>
<td>%d</td>
</tr>
<tr>
<td>Retries Until Failed</td>
<td>%d</td>
</tr>
<tr>
<td>Preferred Hosts</td>
<td>%s</td>
</tr>
<tr>
<td>Network Buffer Size</td>
<td>%d</td>
</tr>
<tr>
<td>Serve From Rclone</td>
<td>%t</td>
</tr>
<tr>
<td>Verify Download Link</td>
<td>%t</td>
</tr>
<tr>
<td>Force IPv6</td>
<td>%t</td>
</tr>
<tr>
<td>On Library Update</td>
<td>%s</td>
</tr>
</table>
`
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) { func (zr *ZurgRouter) logsHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {

View File

@@ -126,7 +126,6 @@ type User struct {
Email string `json:"email"` Email string `json:"email"`
Points int `json:"points"` // Fidelity points Points int `json:"points"` // Fidelity points
Locale string `json:"locale"` // User language Locale string `json:"locale"` // User language
Avatar string `json:"avatar"` // URL
Type string `json:"type"` // "premium" or "free" Type string `json:"type"` // "premium" or "free"
Premium int `json:"premium"` // seconds left as a Premium user Premium int `json:"premium"` // seconds left as a Premium user
Expiration string `json:"expiration"` // jsonDate Expiration string `json:"expiration"` // jsonDate