Skip to content

Commit

Permalink
Add status as enum to the url
Browse files Browse the repository at this point in the history
  • Loading branch information
dangershony committed Nov 10, 2023
1 parent 90f30d1 commit 5a731d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Angor/Client/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{
<tr>
<td><a href="@indexer.Url" target="_blank">@indexer.Url</a></td>
<td style="color: @(indexer.IsOnline ? "green" : "red");">@(indexer.IsOnline ? "Online" : "Offline")</td>
<td style="color: @(indexer.Status == UrlStatus.Online ? "green" : indexer.Status == UrlStatus.NotReady ? "yellow" : "red");">@indexer.Status.ToString()</td>
<td>
@if (indexer.IsPrimary)
{
Expand Down Expand Up @@ -96,7 +96,7 @@
{
<tr>
<td><a href="@relay.Url" target="_blank">@relay.Url</a></td>
<td style="color: @(relay.IsOnline ? "green" : "red");">@(relay.IsOnline ? "Online" : "Offline")</td>
<td style="color: @(relay.Status == UrlStatus.Online ? "green" : relay.Status == UrlStatus.NotReady ? "yellow" : "red");">@relay.Status.ToString()</td>
<td>
@if (relay.IsPrimary)
{
Expand Down Expand Up @@ -229,7 +229,7 @@

if (res.IsPrimary && settingsInfo.Indexers.Any())
{
var next = settingsInfo.Indexers.OrderBy(a => a.IsOnline).First();
var next = settingsInfo.Indexers.OrderBy(a => a.Status).First();
next.IsPrimary = true;
}

Expand All @@ -247,7 +247,7 @@

if (res.IsPrimary && settingsInfo.Relays.Any())
{
var next = settingsInfo.Relays.OrderBy(a => a.IsOnline).First();
var next = settingsInfo.Relays.OrderBy(a => a.Status).First();
next.IsPrimary = true;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Angor/Client/Services/NetworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task CheckServices(bool force = false)

if (response.IsSuccessStatusCode)
{
indexerUrl.IsOnline = true;
indexerUrl.Status = UrlStatus.Online;
}
else
{
Expand All @@ -47,7 +47,7 @@ public async Task CheckServices(bool force = false)
}
catch (Exception ex)
{
indexerUrl.IsOnline = false;
indexerUrl.Status = UrlStatus.Offline;
_logger.LogError(ex, $"Failed to check indexer status url = {indexerUrl.Url}");
}
}
Expand All @@ -67,7 +67,7 @@ public async Task CheckServices(bool force = false)

if (response.IsSuccessStatusCode)
{
relayUrl.IsOnline = true;
relayUrl.Status = UrlStatus.Online;
}
else
{
Expand All @@ -76,7 +76,7 @@ public async Task CheckServices(bool force = false)
}
catch (Exception ex)
{
relayUrl.IsOnline = false;
relayUrl.Status = UrlStatus.Offline;
_logger.LogError(ex, $"Failed to check relay status url = {relayUrl.Url}");
}
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public void CheckAndHandleError(HttpResponseMessage httpResponseMessage)

if (host != null)
{
host.IsOnline = false;
host.Status = UrlStatus.Offline;
_networkStorage.SetSettings(settings);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/Angor/Shared/Models/SettingsUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ public class SettingsUrl

public bool IsPrimary { get; set; }

public bool IsOnline { get; set; }
public UrlStatus Status { get; set; }

public DateTime LastCheck { get; set; }
}

public enum UrlStatus
{
Offline,
NotReady,
Online
}

0 comments on commit 5a731d5

Please sign in to comment.