fix and improve

This commit is contained in:
MHSanaei 2023-06-14 19:50:19 +03:30
parent c0f1a926e5
commit d40e61fc45
4 changed files with 21 additions and 24 deletions

View file

@ -145,12 +145,7 @@ func (a *InboundController) getClientIps(c *gin.Context) {
email := c.Param("email") email := c.Param("email")
ips, err := a.inboundService.GetInboundClientIps(email) ips, err := a.inboundService.GetInboundClientIps(email)
if err != nil { if err != nil || ips == "" {
jsonObj(c, "Failed to get client IPs", nil)
return
}
if ips == "" {
jsonObj(c, "No IP Record", nil) jsonObj(c, "No IP Record", nil)
return return
} }

View file

@ -124,12 +124,14 @@
try { try {
const msg = await HttpUtil.post(`/panel/inbound/clientIps/${email}`); const msg = await HttpUtil.post(`/panel/inbound/clientIps/${email}`);
if (!msg.success) { if (!msg.success) {
document.getElementById("clientIPs").value = msg.obj;
return; return;
} }
const ips = JSON.parse(msg.obj).join(",\n"); const ips = Array.isArray(msg.obj) ? msg.obj.join(",\n") : msg.obj;
document.getElementById("clientIPs").value = ips; document.getElementById("clientIPs").value = ips;
} catch (error) { } catch (error) {
document.getElementById("clientIPs").value = msg.obj; console.error(error);
document.getElementById("clientIPs").value = 'An error occurred while making the request';
} }
}, },
async clearDBClientIps(email) { async clearDBClientIps(email) {

View file

@ -449,9 +449,13 @@
this.loadingTip = tip; this.loadingTip = tip;
}, },
async getStatus() { async getStatus() {
const msg = await HttpUtil.post('/server/status'); try {
if (msg.success) { const msg = await HttpUtil.post('/server/status');
this.setStatus(msg.obj); if (msg.success) {
this.setStatus(msg.obj);
}
} catch (e) {
console.error("Failed to get status:", e);
} }
}, },
setStatus(data) { setStatus(data) {
@ -560,11 +564,14 @@
}, },
}, },
async mounted() { async mounted() {
while (true) { let retries = 0;
while (retries < 5) {
try { try {
await this.getStatus(); await this.getStatus();
retries = 0;
} catch (e) { } catch (e) {
console.error(e); console.error("Error occurred while fetching status:", e);
retries++;
} }
await PromiseUtil.sleep(2000); await PromiseUtil.sleep(2000);
} }

View file

@ -86,31 +86,24 @@ type ServerService struct {
inboundService InboundService inboundService InboundService
} }
const DebugMode = false // Set to true during development
func getPublicIP(url string) string { func getPublicIP(url string) string {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
if DebugMode {
logger.Warning("get public IP failed:", err)
}
return "N/A" return "N/A"
} }
defer resp.Body.Close() defer resp.Body.Close()
ip, err := io.ReadAll(resp.Body) ip, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
if DebugMode {
logger.Warning("read public IP failed:", err)
}
return "N/A" return "N/A"
} }
if string(ip) == "" { ipString := string(ip)
return "N/A" // default value if ipString == "" {
return "N/A"
} }
return string(ip) return ipString
} }
func (s *ServerService) GetStatus(lastStatus *Status) *Status { func (s *ServerService) GetStatus(lastStatus *Status) *Status {