diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0c6de1c..0da9e29 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,7 +46,7 @@ jobs: run: dotnet publish -c Release -p:Version=${{ github.event.release.tag_name }} DragonFruit.Sakura - name: Package Output - run: dotnet pack -c Release -p:Version=${{ github.event.inputs.version }} -o ./packages --no-build DragonFruit.Sakura + run: dotnet pack -c Release -p:PackageVersion=${{ github.event.inputs.version }} -o ./packages --no-build DragonFruit.Sakura - name: Upload Package run: dotnet nuget push -s https://nuget.pkg.github.com/dragonfruitnetwork/index.json -k ${{ github.token }} ./packages/*.nupkg diff --git a/DragonFruit.Sakura.sln.DotSettings b/DragonFruit.Sakura.sln.DotSettings index dec38fa..64a45e3 100644 --- a/DragonFruit.Sakura.sln.DotSettings +++ b/DragonFruit.Sakura.sln.DotSettings @@ -355,6 +355,7 @@ Licensed under GNU AGPLv3. Refer to the LICENSE file for more info False False API + AS GUID IL IOS diff --git a/DragonFruit.Sakura/Administration/Changelogs.razor.cs b/DragonFruit.Sakura/Administration/Changelogs.razor.cs index 3c8df07..39ff5f3 100644 --- a/DragonFruit.Sakura/Administration/Changelogs.razor.cs +++ b/DragonFruit.Sakura/Administration/Changelogs.razor.cs @@ -31,7 +31,7 @@ public partial class Changelogs protected override async Task OnParametersSetAsync() { - var versionsRequest = new AdminApiChangelogVersionListingRequest(TargetApp.Id); + var versionsRequest = new ChangelogVersionListingRequest(TargetApp.Id); var releases = await Client.PerformAsync>(versionsRequest).ConfigureAwait(false); VersionHints = releases.Select(x => x.VersionName).ToList(); @@ -65,7 +65,7 @@ private async Task LoadRelease() { try { - var changelogs = new ApiChangelogsRequest(TargetApp.Id, RequestVersion); + var changelogs = new ChangelogsRequest(TargetApp.Id, RequestVersion); Target = await Client.PerformAsync(changelogs).ConfigureAwait(false); IsTargetNew = false; @@ -89,7 +89,7 @@ private async Task SaveNewRelease() Target.Release = DateTime.UtcNow; - var request = new AdminApiChangelogsCreationRequest(TargetApp.Id, Target); + var request = new ChangelogsCreationRequest(TargetApp.Id, Target); Target = await Client.PerformAsync(request).ConfigureAwait(false); IsTargetNew = false; @@ -101,7 +101,7 @@ private async Task DeleteRelease() // todo add confirmation if (!IsTargetNew) { - var deletionRequest = new AdminApiChangelogsDeletionRequest(TargetApp.Id, Target.VersionName); + var deletionRequest = new ChangelogsDeletionRequest(TargetApp.Id, Target.VersionName); using var deletionResponse = await Client.PerformAsync(deletionRequest); deletionResponse.EnsureSuccessStatusCode(); } @@ -115,8 +115,8 @@ private async Task SaveModification(ApiChangelogModification modification) throw new InvalidCastException($"{nameof(SaveModification)} can only be called on live changelog releases"); var request = modification.Id > 0 - ? new AdminApiChangelogModificationEditRequest(Target.AppId, Target.VersionName, modification) - : new AdminApiChangelogModificationCreationRequest(Target.AppId, Target.VersionName, modification) as YunaApiRequest; + ? new ChangelogModificationEditRequest(Target.AppId, Target.VersionName, modification) + : new ChangelogModificationCreationRequest(Target.AppId, Target.VersionName, modification) as YunaApiRequest; var newModification = await Client.PerformAsync(request).ConfigureAwait(false); @@ -129,7 +129,7 @@ private async ValueTask DeleteModification(ApiChangelogModification modification if (modification.Id > 1) { // if the id is non-zero, it is on the server and needs to be deleted there first - var request = new AdminApiChangelogModificationDeletionRequest(Target.AppId, Target.VersionName, modification.Id); + var request = new ChangelogModificationDeletionRequest(Target.AppId, Target.VersionName, modification.Id); using var response = await Client.PerformAsync(request).ConfigureAwait(false); response.EnsureSuccessStatusCode(); diff --git a/DragonFruit.Sakura/Administration/Distribution.razor.cs b/DragonFruit.Sakura/Administration/Distribution.razor.cs index ca0274b..fc4bfb8 100644 --- a/DragonFruit.Sakura/Administration/Distribution.razor.cs +++ b/DragonFruit.Sakura/Administration/Distribution.razor.cs @@ -33,7 +33,7 @@ protected override async Task OnParametersSetAsync() Branches = null; SelectedBranch = null; - var request = new AdminApiDistributionBranchesRequest(TargetApp.Id); + var request = new DistributionBranchesRequest(TargetApp.Id); Branches = await Client.PerformAsync>(request).ConfigureAwait(false); // load first branch in to fill page with data @@ -44,13 +44,13 @@ private async Task SwitchToBranch(ApiDistributionBranch branch) { SelectedBranch = null; - var request = new AdminApiDistributionBranchRequest(TargetApp.Id, branch.Name); + var request = new DistributionBranchRequest(TargetApp.Id, branch.Name); SelectedBranch = await Client.PerformAsync(request).ConfigureAwait(false); } private async Task CreateBranch(string name) { - var request = new AdminApiDistributionBranchCreationRequest(TargetApp.Id, name); + var request = new DistributionBranchCreationRequest(TargetApp.Id, name); var branch = await Client.PerformAsync(request).ConfigureAwait(false); Branches.Add(branch); @@ -58,7 +58,7 @@ private async Task CreateBranch(string name) private async Task DeleteBranch(ApiDistributionBranch branch) { - var request = new AdminApiDistributionBranchDeletionRequest(TargetApp.Id, branch.Name); + var request = new DistributionBranchDeletionRequest(TargetApp.Id, branch.Name); using var response = await Client.PerformAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) @@ -69,7 +69,7 @@ private async Task DeleteBranch(ApiDistributionBranch branch) private async Task PromoteRelease(ApiDistributionRelease release) { - var request = new AdminApiDistributionActiveReleaseRequest(TargetApp.Id, SelectedBranch.Name, release.Id); + var request = new DistributionActiveReleaseRequest(TargetApp.Id, SelectedBranch.Name, release.Id); using var response = await Client.PerformAsync(request).ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.OK) @@ -89,7 +89,7 @@ private async Task DeleteRelease(ApiDistributionRelease release) return; } - var request = new AdminApiDistributionReleaseDeletionRequest(TargetApp.Id, SelectedBranch.Name, release.Id); + var request = new DistributionReleaseDeletionRequest(TargetApp.Id, SelectedBranch.Name, release.Id); using var response = await Client.PerformAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) diff --git a/DragonFruit.Sakura/Administration/Index.razor.cs b/DragonFruit.Sakura/Administration/Index.razor.cs index 9bea79e..3bfa3d3 100644 --- a/DragonFruit.Sakura/Administration/Index.razor.cs +++ b/DragonFruit.Sakura/Administration/Index.razor.cs @@ -40,7 +40,7 @@ private AppFeatures SelectedAppFeature protected override async Task OnInitializedAsync() { - Apps = await Client.PerformAsync>(new AdminApiAppsListingRequest()).ConfigureAwait(false); + Apps = await Client.PerformAsync>(new AppsListingRequest()).ConfigureAwait(false); Name = await AuthenticationStateProvider.GetAuthenticationStateAsync().ContinueWith(t => t.Result.User.Identity?.Name).ConfigureAwait(false); } } diff --git a/DragonFruit.Sakura/Administration/Keychain.razor.cs b/DragonFruit.Sakura/Administration/Keychain.razor.cs index fc67f56..30817f7 100644 --- a/DragonFruit.Sakura/Administration/Keychain.razor.cs +++ b/DragonFruit.Sakura/Administration/Keychain.razor.cs @@ -33,7 +33,7 @@ private async Task LoadNextPage() if (!AllowLoadingMoreKeys) return; - var request = new AdminApiKeychainListingRequest { Limit = PageSize, Offset = (_currentPage++ - 1) * PageSize }; + var request = new KeychainListingRequest { Limit = PageSize, Offset = (_currentPage++ - 1) * PageSize }; var nextPageContents = await Client.PerformAsync>(request).ConfigureAwait(false); Keys.AddRange(nextPageContents); @@ -42,7 +42,7 @@ private async Task LoadNextPage() private async Task AddKey(InputFileChangeEventArgs args) { - var request = new AdminApiKeychainAdditionRequest(args.File.OpenReadStream(80000), NewKeyExpiry); + var request = new KeychainItemAdditionRequest(args.File.OpenReadStream(80000), NewKeyExpiry); var newKey = await Client.PerformAsync(request).ConfigureAwait(false); Keys.Add(newKey); @@ -55,7 +55,7 @@ private async Task DeleteKey(ApiUserKeychainEntry key) return; } - using var response = await Client.PerformAsync(new AdminApiKeychainDeletionRequest(key.KeyId)).ConfigureAwait(false); + using var response = await Client.PerformAsync(new KeychainItemDeletionRequest(key.KeyId)).ConfigureAwait(false); if (response.IsSuccessStatusCode) { diff --git a/DragonFruit.Sakura/Changelogs/Index.razor.cs b/DragonFruit.Sakura/Changelogs/Index.razor.cs index b7a107a..7d1068d 100644 --- a/DragonFruit.Sakura/Changelogs/Index.razor.cs +++ b/DragonFruit.Sakura/Changelogs/Index.razor.cs @@ -2,7 +2,6 @@ // Licensed under GNU AGPLv3. Refer to the LICENSE file for more info using System.Net; -using DragonFruit.Data; using DragonFruit.Sakura.Network; using DragonFruit.Sakura.Network.Requests; using Microsoft.AspNetCore.Components; @@ -35,13 +34,9 @@ protected override async Task OnParametersSetAsync() return; } - var releaseRequest = string.IsNullOrEmpty(AppName) - ? new ApiDefaultChangelogsRequest() - : new ApiChangelogsRequest(AppName, VersionName) as ApiRequest; - try { - Release = await Client.PerformAsync(releaseRequest).ConfigureAwait(false); + Release = await Client.PerformAsync(new ChangelogsRequest(AppName, VersionName)).ConfigureAwait(false); } catch (HttpRequestException e) when (e.StatusCode == HttpStatusCode.NotFound) { diff --git a/DragonFruit.Sakura/DragonFruit.Sakura.csproj b/DragonFruit.Sakura/DragonFruit.Sakura.csproj index 3450408..72c73a0 100644 --- a/DragonFruit.Sakura/DragonFruit.Sakura.csproj +++ b/DragonFruit.Sakura/DragonFruit.Sakura.csproj @@ -5,14 +5,14 @@ enable true - + DragonFruit Sakura DragonFruit Network Copyright (c) DragonFruit Network The face of DragonFruit Network - + icon.png DragonFruit.Sakura @@ -22,18 +22,26 @@ - - - - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + - + diff --git a/DragonFruit.Sakura/Network/OnionCountryInfo.cs b/DragonFruit.Sakura/Network/OnionCountryInfo.cs deleted file mode 100644 index 0799a1d..0000000 --- a/DragonFruit.Sakura/Network/OnionCountryInfo.cs +++ /dev/null @@ -1,38 +0,0 @@ -// DragonFruit Sakura Copyright (c) DragonFruit Network -// Licensed under GNU AGPLv3. Refer to the LICENSE file for more info - -using System.Text.Json.Serialization; - -namespace DragonFruit.Sakura.Network -{ - [Serializable] - public class OnionCountryInfo - { - [JsonPropertyName("country_name")] - public string CountryName { get; set; } - - [JsonPropertyName("country_code")] - public string CountryCode { get; set; } - - [JsonPropertyName("node_count")] - public int TotalNodeCount { get; set; } - - [JsonPropertyName("node_count_exit")] - public int ExitNodeCount { get; set; } - - [JsonPropertyName("node_count_entry")] - public int EntryNodeCount { get; set; } - - [JsonPropertyName("node_count_online")] - public int OnlineNodeCount { get; set; } - - [JsonPropertyName("node_count_stable")] - public int StableNodeCount { get; set; } - - [JsonPropertyName("node_count_fast")] - public int FastNodeCount { get; set; } - - [JsonPropertyName("node_share")] - public decimal GlobalShare { get; set; } - } -} diff --git a/DragonFruit.Sakura/Network/ApiGeolocationInfo.cs b/DragonFruit.Sakura/Network/OnionFruitGeolocationInfo.cs similarity index 57% rename from DragonFruit.Sakura/Network/ApiGeolocationInfo.cs rename to DragonFruit.Sakura/Network/OnionFruitGeolocationInfo.cs index 135102b..17211ba 100644 --- a/DragonFruit.Sakura/Network/ApiGeolocationInfo.cs +++ b/DragonFruit.Sakura/Network/OnionFruitGeolocationInfo.cs @@ -5,13 +5,22 @@ namespace DragonFruit.Sakura.Network { - public class ApiGeolocationInfo + public class OnionFruitGeolocationInfo { [JsonPropertyName("ip_address")] public string IPAddress { get; set; } + [JsonPropertyName("country_code")] + public string CountryCode { get; set; } + [JsonPropertyName("country_name")] - public string Country { get; set; } + public string CountryName { get; set; } + + [JsonPropertyName("as_number")] + public int? AS { get; set; } + + [JsonPropertyName("as_name")] + public string ASName { get; set; } [JsonPropertyName("is_tor")] public bool? IsConnectedToTor { get; set; } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogVersionListingRequest.cs b/DragonFruit.Sakura/Network/Requests/AdminApiChangelogVersionListingRequest.cs deleted file mode 100644 index 2a120f8..0000000 --- a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogVersionListingRequest.cs +++ /dev/null @@ -1,17 +0,0 @@ -// DragonFruit Sakura Copyright (c) DragonFruit Network -// Licensed under GNU AGPLv3. Refer to the LICENSE file for more info - -namespace DragonFruit.Sakura.Network.Requests -{ - public partial class AdminApiChangelogVersionListingRequest : YunaApiRequest - { - protected override string Stub => $"/{AppId}/changelogs/list"; - - public AdminApiChangelogVersionListingRequest(string appId) - { - AppId = appId; - } - - public string AppId { get; } - } -} diff --git a/DragonFruit.Sakura/Network/Requests/ApiGeolocationInfoRequest.cs b/DragonFruit.Sakura/Network/Requests/ApiGeolocationInfoRequest.cs deleted file mode 100644 index 1d52cac..0000000 --- a/DragonFruit.Sakura/Network/Requests/ApiGeolocationInfoRequest.cs +++ /dev/null @@ -1,10 +0,0 @@ -// DragonFruit Sakura Copyright (c) DragonFruit Network -// Licensed under GNU AGPLv3. Refer to the LICENSE file for more info - -namespace DragonFruit.Sakura.Network.Requests -{ - public partial class ApiGeolocationInfoRequest : YunaApiRequest - { - protected override string Stub => "/onionfruit/status"; - } -} diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiAppsListingRequest.cs b/DragonFruit.Sakura/Network/Requests/AppsListingRequest.cs similarity index 83% rename from DragonFruit.Sakura/Network/Requests/AdminApiAppsListingRequest.cs rename to DragonFruit.Sakura/Network/Requests/AppsListingRequest.cs index 3a02b7e..74cfaae 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiAppsListingRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/AppsListingRequest.cs @@ -3,7 +3,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiAppsListingRequest : YunaApiRequest + public partial class AppsListingRequest : YunaApiRequest { protected override string Stub => "/apps"; diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationCreationRequest.cs b/DragonFruit.Sakura/Network/Requests/ChangelogModificationCreationRequest.cs similarity index 81% rename from DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationCreationRequest.cs rename to DragonFruit.Sakura/Network/Requests/ChangelogModificationCreationRequest.cs index dd1ec34..54273a4 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationCreationRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/ChangelogModificationCreationRequest.cs @@ -5,7 +5,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiChangelogModificationCreationRequest(string appId, string version, ApiChangelogModification modification) : YunaApiRequest + public partial class ChangelogModificationCreationRequest(string appId, string version, ApiChangelogModification modification) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Post; protected override string Stub => $"/{AppId}/changelogs/{Version}/modifications"; diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationDeletionRequest.cs b/DragonFruit.Sakura/Network/Requests/ChangelogModificationDeletionRequest.cs similarity index 82% rename from DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationDeletionRequest.cs rename to DragonFruit.Sakura/Network/Requests/ChangelogModificationDeletionRequest.cs index 9a586b1..1b1f3f7 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationDeletionRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/ChangelogModificationDeletionRequest.cs @@ -3,7 +3,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiChangelogModificationDeletionRequest(string appId, string version, int modificationId) : YunaApiRequest + public partial class ChangelogModificationDeletionRequest(string appId, string version, int modificationId) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Delete; protected override string Stub => $"/{AppId}/changelogs/{Version}/modifications/{ModificationId}"; diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationEditRequest.cs b/DragonFruit.Sakura/Network/Requests/ChangelogModificationEditRequest.cs similarity index 53% rename from DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationEditRequest.cs rename to DragonFruit.Sakura/Network/Requests/ChangelogModificationEditRequest.cs index 26d85df..c660596 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogModificationEditRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/ChangelogModificationEditRequest.cs @@ -5,24 +5,17 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiChangelogModificationEditRequest : YunaApiRequest + public partial class ChangelogModificationEditRequest(string appId, string version, ApiChangelogModification modification) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Patch; protected override string Stub => $"/{AppId}/changelogs/{Version}/modifications/{Modification.Id}"; protected internal override bool RequiresAuthentication => true; - public AdminApiChangelogModificationEditRequest(string appId, string version, ApiChangelogModification modification) - { - AppId = appId; - Version = version; - Modification = modification; - } - - public string AppId { get; } - public string Version { get; } + public string AppId { get; } = appId; + public string Version { get; } = version; [RequestBody] - public ApiChangelogModification Modification { get; } + public ApiChangelogModification Modification { get; } = modification; } } diff --git a/DragonFruit.Sakura/Network/Requests/ApiChangelogsRequest.cs b/DragonFruit.Sakura/Network/Requests/ChangelogVersionListingRequest.cs similarity index 64% rename from DragonFruit.Sakura/Network/Requests/ApiChangelogsRequest.cs rename to DragonFruit.Sakura/Network/Requests/ChangelogVersionListingRequest.cs index ced2f87..e4a737d 100644 --- a/DragonFruit.Sakura/Network/Requests/ApiChangelogsRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/ChangelogVersionListingRequest.cs @@ -3,11 +3,10 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class ApiChangelogsRequest(string appId, string versionName) : YunaApiRequest + public partial class ChangelogVersionListingRequest(string appId) : YunaApiRequest { - protected override string Stub => $"/{AppId}/changelogs/{VersionName}"; + protected override string Stub => $"/{AppId}/changelogs/list"; public string AppId { get; } = appId; - public string VersionName { get; } = versionName ?? "latest"; } } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogsCreationRequest.cs b/DragonFruit.Sakura/Network/Requests/ChangelogsCreationRequest.cs similarity index 83% rename from DragonFruit.Sakura/Network/Requests/AdminApiChangelogsCreationRequest.cs rename to DragonFruit.Sakura/Network/Requests/ChangelogsCreationRequest.cs index 031d1d8..2a7788a 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogsCreationRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/ChangelogsCreationRequest.cs @@ -5,7 +5,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiChangelogsCreationRequest(string appId, ApiChangelogRelease release) : YunaApiRequest + public partial class ChangelogsCreationRequest(string appId, ApiChangelogRelease release) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Post; protected override string Stub => $"/{AppId}/changelogs"; diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogsDeletionRequest.cs b/DragonFruit.Sakura/Network/Requests/ChangelogsDeletionRequest.cs similarity index 83% rename from DragonFruit.Sakura/Network/Requests/AdminApiChangelogsDeletionRequest.cs rename to DragonFruit.Sakura/Network/Requests/ChangelogsDeletionRequest.cs index 6b22a64..0f323cd 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiChangelogsDeletionRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/ChangelogsDeletionRequest.cs @@ -3,7 +3,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiChangelogsDeletionRequest(string appId, string versionName) : YunaApiRequest + public partial class ChangelogsDeletionRequest(string appId, string versionName) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Delete; protected override string Stub => $"/{AppId}/changelogs/{VersionName}"; diff --git a/DragonFruit.Sakura/Network/Requests/ChangelogsRequest.cs b/DragonFruit.Sakura/Network/Requests/ChangelogsRequest.cs new file mode 100644 index 0000000..68fe323 --- /dev/null +++ b/DragonFruit.Sakura/Network/Requests/ChangelogsRequest.cs @@ -0,0 +1,13 @@ +// DragonFruit Sakura Copyright (c) DragonFruit Network +// Licensed under GNU AGPLv3. Refer to the LICENSE file for more info + +namespace DragonFruit.Sakura.Network.Requests +{ + public partial class ChangelogsRequest(string appId, string versionName) : YunaApiRequest + { + protected override string Stub => AppId == null ? "/changelogs/latest" : $"/{AppId}/changelogs/{VersionName}"; + + public string AppId { get; } = appId; + public string VersionName { get; } = versionName ?? "latest"; + } +} diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionActiveReleaseRequest.cs b/DragonFruit.Sakura/Network/Requests/DistributionActiveReleaseRequest.cs similarity index 59% rename from DragonFruit.Sakura/Network/Requests/AdminApiDistributionActiveReleaseRequest.cs rename to DragonFruit.Sakura/Network/Requests/DistributionActiveReleaseRequest.cs index 46db028..3b41e3b 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionActiveReleaseRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/DistributionActiveReleaseRequest.cs @@ -5,25 +5,18 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiDistributionActiveReleaseRequest : YunaApiRequest + public partial class DistributionActiveReleaseRequest(string appId, string branchName, int activeReleaseId) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Put; protected override string Stub => $"/{AppId}/dist/{BranchName}/releases/active"; protected internal override bool RequiresAuthentication => true; - public AdminApiDistributionActiveReleaseRequest(string appId, string branchName, int activeReleaseId) - { - AppId = appId; - BranchName = branchName; - ActiveReleaseId = activeReleaseId; - } - - public string AppId { get; } - public string BranchName { get; } + public string AppId { get; } = appId; + public string BranchName { get; } = branchName; [RequestParameter(ParameterType.Form, "release_id")] - public int ActiveReleaseId { get; } + public int ActiveReleaseId { get; } = activeReleaseId; [RequestParameter(ParameterType.Form, "force")] protected bool Force => true; diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchCreationRequest.cs b/DragonFruit.Sakura/Network/Requests/DistributionBranchCreationRequest.cs similarity index 84% rename from DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchCreationRequest.cs rename to DragonFruit.Sakura/Network/Requests/DistributionBranchCreationRequest.cs index 608eab0..f5e4a91 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchCreationRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/DistributionBranchCreationRequest.cs @@ -5,7 +5,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiDistributionBranchCreationRequest(string appId, string branchName) : YunaApiRequest + public partial class DistributionBranchCreationRequest(string appId, string branchName) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Post; protected override string Stub => $"/{AppId}/dist/branches"; diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchDeletionRequest.cs b/DragonFruit.Sakura/Network/Requests/DistributionBranchDeletionRequest.cs similarity index 56% rename from DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchDeletionRequest.cs rename to DragonFruit.Sakura/Network/Requests/DistributionBranchDeletionRequest.cs index 7b16b28..5a6e707 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchDeletionRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/DistributionBranchDeletionRequest.cs @@ -3,20 +3,14 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiDistributionBranchDeletionRequest : YunaApiRequest + public partial class DistributionBranchDeletionRequest(string appId, string branchName) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Delete; protected override string Stub => $"/{AppId}/dist/branches/{BranchName}"; protected internal override bool RequiresAuthentication => true; - public AdminApiDistributionBranchDeletionRequest(string appId, string branchName) - { - AppId = appId; - BranchName = branchName; - } - - public string AppId { get; } - public string BranchName { get; } + public string AppId { get; } = appId; + public string BranchName { get; } = branchName; } } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchRequest.cs b/DragonFruit.Sakura/Network/Requests/DistributionBranchRequest.cs similarity index 53% rename from DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchRequest.cs rename to DragonFruit.Sakura/Network/Requests/DistributionBranchRequest.cs index 323b07f..b8fcd6f 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/DistributionBranchRequest.cs @@ -3,19 +3,13 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiDistributionBranchRequest : YunaApiRequest + public partial class DistributionBranchRequest(string appId, string branchName) : YunaApiRequest { protected override string Stub => $"/{AppId}/dist/{BranchName}"; protected internal override bool RequiresAuthentication => true; - public AdminApiDistributionBranchRequest(string appId, string branchName) - { - AppId = appId; - BranchName = branchName; - } - - public string AppId { get; } - public string BranchName { get; } + public string AppId { get; } = appId; + public string BranchName { get; } = branchName; } } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchesRequest.cs b/DragonFruit.Sakura/Network/Requests/DistributionBranchesRequest.cs similarity index 61% rename from DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchesRequest.cs rename to DragonFruit.Sakura/Network/Requests/DistributionBranchesRequest.cs index 3fbb2fc..b773d1d 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionBranchesRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/DistributionBranchesRequest.cs @@ -3,17 +3,12 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiDistributionBranchesRequest : YunaApiRequest + public partial class DistributionBranchesRequest(string appId) : YunaApiRequest { protected override string Stub => $"/{AppId}/dist/branches"; protected internal override bool RequiresAuthentication => true; - public AdminApiDistributionBranchesRequest(string appId) - { - AppId = appId; - } - - public string AppId { get; } + public string AppId { get; } = appId; } } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionReleaseDeletionRequest.cs b/DragonFruit.Sakura/Network/Requests/DistributionReleaseDeletionRequest.cs similarity index 51% rename from DragonFruit.Sakura/Network/Requests/AdminApiDistributionReleaseDeletionRequest.cs rename to DragonFruit.Sakura/Network/Requests/DistributionReleaseDeletionRequest.cs index 4f436e9..3d1566d 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiDistributionReleaseDeletionRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/DistributionReleaseDeletionRequest.cs @@ -3,22 +3,15 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiDistributionReleaseDeletionRequest : YunaApiRequest + public partial class DistributionReleaseDeletionRequest(string appId, string branchName, int releaseId) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Delete; protected override string Stub => $"/{AppId}/dist/{BranchName}/releases/{ReleaseId}"; protected internal override bool RequiresAuthentication => true; - public AdminApiDistributionReleaseDeletionRequest(string appId, string branchName, int releaseId) - { - AppId = appId; - BranchName = branchName; - ReleaseId = releaseId; - } - - public string AppId { get; } - public string BranchName { get; } - public int ReleaseId { get; } + public string AppId { get; } = appId; + public string BranchName { get; } = branchName; + public int ReleaseId { get; } = releaseId; } } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiKeychainAdditionRequest.cs b/DragonFruit.Sakura/Network/Requests/KeychainItemAdditionRequest.cs similarity index 65% rename from DragonFruit.Sakura/Network/Requests/AdminApiKeychainAdditionRequest.cs rename to DragonFruit.Sakura/Network/Requests/KeychainItemAdditionRequest.cs index 8d17efc..abb464a 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiKeychainAdditionRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/KeychainItemAdditionRequest.cs @@ -6,23 +6,17 @@ namespace DragonFruit.Sakura.Network.Requests { [FormBodyType(FormBodyType.Multipart)] - public partial class AdminApiKeychainAdditionRequest : YunaApiRequest + public partial class KeychainItemAdditionRequest(Stream pemFile, DateTime? expiry) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Post; protected override string Stub => "/users/me/keychain"; protected internal override bool RequiresAuthentication => true; - public AdminApiKeychainAdditionRequest(Stream pemFile, DateTime? expiry) - { - PublicKey = pemFile; - Expiry = expiry; - } - [RequestParameter(ParameterType.Form, "pem")] - public Stream PublicKey { get; } + public Stream PublicKey { get; } = pemFile; [RequestParameter(ParameterType.Form, "expiry")] - public DateTime? Expiry { get; } + public DateTime? Expiry { get; } = expiry; } } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiKeychainDeletionRequest.cs b/DragonFruit.Sakura/Network/Requests/KeychainItemDeletionRequest.cs similarity index 66% rename from DragonFruit.Sakura/Network/Requests/AdminApiKeychainDeletionRequest.cs rename to DragonFruit.Sakura/Network/Requests/KeychainItemDeletionRequest.cs index baee85f..e1b4699 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiKeychainDeletionRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/KeychainItemDeletionRequest.cs @@ -3,18 +3,13 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiKeychainDeletionRequest : YunaApiRequest + public partial class KeychainItemDeletionRequest(string keyId) : YunaApiRequest { public override HttpMethod RequestMethod => HttpMethod.Delete; protected override string Stub => $"/users/me/keychain/{KeyId}"; protected internal override bool RequiresAuthentication => true; - public AdminApiKeychainDeletionRequest(string keyId) - { - KeyId = keyId; - } - - public string KeyId { get; } + public string KeyId { get; } = keyId; } } diff --git a/DragonFruit.Sakura/Network/Requests/AdminApiKeychainListingRequest.cs b/DragonFruit.Sakura/Network/Requests/KeychainListingRequest.cs similarity index 88% rename from DragonFruit.Sakura/Network/Requests/AdminApiKeychainListingRequest.cs rename to DragonFruit.Sakura/Network/Requests/KeychainListingRequest.cs index 288c843..805dffe 100644 --- a/DragonFruit.Sakura/Network/Requests/AdminApiKeychainListingRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/KeychainListingRequest.cs @@ -5,7 +5,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class AdminApiKeychainListingRequest : YunaApiRequest + public partial class KeychainListingRequest : YunaApiRequest { protected override string Stub => "/users/me/keychain"; protected internal override bool RequiresAuthentication => true; diff --git a/DragonFruit.Sakura/Network/Requests/ApiDefaultChangelogsRequest.cs b/DragonFruit.Sakura/Network/Requests/OnionFruitDatabaseRequest.cs similarity index 52% rename from DragonFruit.Sakura/Network/Requests/ApiDefaultChangelogsRequest.cs rename to DragonFruit.Sakura/Network/Requests/OnionFruitDatabaseRequest.cs index 0a2b88e..51b2e0a 100644 --- a/DragonFruit.Sakura/Network/Requests/ApiDefaultChangelogsRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/OnionFruitDatabaseRequest.cs @@ -1,10 +1,12 @@ // DragonFruit Sakura Copyright (c) DragonFruit Network // Licensed under GNU AGPLv3. Refer to the LICENSE file for more info +using DragonFruit.Data; + namespace DragonFruit.Sakura.Network.Requests { - public partial class ApiDefaultChangelogsRequest : YunaApiRequest + public partial class OnionFruitDatabaseRequest : ApiRequest { - protected override string Stub => "/changelogs/latest"; + public override string RequestPath => "https://onionfruit-api.dragonfruit.network/assets/onion.lite.db"; } } diff --git a/DragonFruit.Sakura/Network/Requests/OnionCountryInfoRequest.cs b/DragonFruit.Sakura/Network/Requests/OnionFruitStatusRequest.cs similarity index 58% rename from DragonFruit.Sakura/Network/Requests/OnionCountryInfoRequest.cs rename to DragonFruit.Sakura/Network/Requests/OnionFruitStatusRequest.cs index 9cdf150..c9295ac 100644 --- a/DragonFruit.Sakura/Network/Requests/OnionCountryInfoRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/OnionFruitStatusRequest.cs @@ -5,8 +5,8 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class OnionCountryInfoRequest : ApiRequest + public partial class OnionFruitStatusRequest : ApiRequest { - public override string RequestPath => "https://onioncdn.dragonfruit.network/country-details.json"; + public override string RequestPath => "https://onionfruit-api.dragonfruit.network/connectionstatus"; } } diff --git a/DragonFruit.Sakura/Network/Requests/ApiWikiPageRequest.cs b/DragonFruit.Sakura/Network/Requests/WikiPageRequest.cs similarity index 81% rename from DragonFruit.Sakura/Network/Requests/ApiWikiPageRequest.cs rename to DragonFruit.Sakura/Network/Requests/WikiPageRequest.cs index a5de850..9e73f1b 100644 --- a/DragonFruit.Sakura/Network/Requests/ApiWikiPageRequest.cs +++ b/DragonFruit.Sakura/Network/Requests/WikiPageRequest.cs @@ -3,7 +3,7 @@ namespace DragonFruit.Sakura.Network.Requests { - public partial class ApiWikiPageRequest(string pagePath) : YunaApiRequest + public partial class WikiPageRequest(string pagePath) : YunaApiRequest { protected override string Stub => $"/wiki/en/{PagePath?.TrimStart('/')}"; diff --git a/DragonFruit.Sakura/OnionFruit/Countries.razor b/DragonFruit.Sakura/OnionFruit/Countries.razor index cffa2c7..2d9b34e 100644 --- a/DragonFruit.Sakura/OnionFruit/Countries.razor +++ b/DragonFruit.Sakura/OnionFruit/Countries.razor @@ -1,5 +1,4 @@ @page "/onionfruit/countries" -@using DragonFruit.Sakura.Network @using DragonFruit.Sakura.Utils OnionFruit™ Countries List · DragonFruit Network @@ -17,16 +16,16 @@ Choose where you would like to go next with OnionFruit™ Connect - Powered by the OnionFruit™ API - an open-source Tor® network status library - + Powered by onionfruit-web, providing up-to-date Tor® and geolocation databases for OnionFruit™ clients + View on GitHub - @context.TotalNodeCount.ToString("N0") @(context.EntryNodeCount == 0 ? "❌" : context.EntryNodeCount.ToString("N0")) @(context.ExitNodeCount == 0 ? "❌" : context.ExitNodeCount.ToString("N0")) - @((context.GlobalShare * 100).ToString("F2"))% + @(((context.TotalNodeCount / GlobalNodeCount) * 100).ToString("F2"))% diff --git a/DragonFruit.Sakura/OnionFruit/Countries.razor.cs b/DragonFruit.Sakura/OnionFruit/Countries.razor.cs index 66d4aa8..993b9de 100644 --- a/DragonFruit.Sakura/OnionFruit/Countries.razor.cs +++ b/DragonFruit.Sakura/OnionFruit/Countries.razor.cs @@ -9,10 +9,22 @@ namespace DragonFruit.Sakura.OnionFruit { public partial class Countries { + private OnionDb _database; + [Inject] private SakuraClient Client { get; set; } - private IReadOnlyCollection NodeCountries { get; set; } + private OnionDb Database + { + get => _database; + set + { + _database = value; + GlobalNodeCount = _database.Countries.Sum(x => x.TotalNodeCount); + } + } + + private float GlobalNodeCount { get; set; } protected override async Task OnInitializedAsync() { @@ -21,7 +33,8 @@ protected override async Task OnInitializedAsync() return; } - NodeCountries = await Client.PerformAsync>(new OnionCountryInfoRequest()).ConfigureAwait(false); + Database = await Client.PerformAsync(new OnionFruitDatabaseRequest()) + .ContinueWith(t => OnionDb.Parser.ParseFrom(t.Result), TaskContinuationOptions.OnlyOnRanToCompletion); } } } diff --git a/DragonFruit.Sakura/OnionFruit/Status.razor b/DragonFruit.Sakura/OnionFruit/Status.razor index 53f5159..ec2fbbd 100644 --- a/DragonFruit.Sakura/OnionFruit/Status.razor +++ b/DragonFruit.Sakura/OnionFruit/Status.razor @@ -48,7 +48,12 @@ OnionFruit™ Connection Status - + + + @if (!string.IsNullOrEmpty(ConnectionInfo?.ASName)) + { + + } diff --git a/DragonFruit.Sakura/OnionFruit/Status.razor.cs b/DragonFruit.Sakura/OnionFruit/Status.razor.cs index 3f6fb67..6cf1747 100644 --- a/DragonFruit.Sakura/OnionFruit/Status.razor.cs +++ b/DragonFruit.Sakura/OnionFruit/Status.razor.cs @@ -13,7 +13,7 @@ public partial class Status [Inject] private SakuraClient Client { get; set; } - public ApiGeolocationInfo ConnectionInfo { get; set; } + public OnionFruitGeolocationInfo ConnectionInfo { get; set; } protected override async Task OnInitializedAsync() { @@ -23,7 +23,7 @@ protected override async Task OnInitializedAsync() return; } - ConnectionInfo = await Client.PerformAsync(new ApiGeolocationInfoRequest()).ConfigureAwait(false); + ConnectionInfo = await Client.PerformAsync(new OnionFruitStatusRequest()).ConfigureAwait(false); } private (string icon, string title, string colour) GetConnectionDisplay() => ConnectionInfo?.IsConnectedToTor switch diff --git a/DragonFruit.Sakura/OnionFruit/onionlite.proto b/DragonFruit.Sakura/OnionFruit/onionlite.proto new file mode 100644 index 0000000..9a9b195 --- /dev/null +++ b/DragonFruit.Sakura/OnionFruit/onionlite.proto @@ -0,0 +1,38 @@ +// This is the protocol buffer definition for the OnionDb file format. +// Original can be found at: https://github.com/dragonfruitnetwork/onionfruit-web/blob/master/oniondb.proto + +syntax = "proto3"; + +message OnionDb { + // location.db info (not present in lite files) + reserved 4, 6; + + // Magic Bytes. Should always be 0xDB followed by the version number + bytes magic_bytes = 1; + + // Database version number. Higher value means newer database (usually a UNIX Epoch) + int64 db_version = 2; + + // Version of the Tor Onionoo dataset used to build the database. Takes the form of a UNIX Epoch. + int64 tor_dir_version = 3; + + // Onionoo Dataset license expression. If null no license data was provided/could be found. + optional string tor_license = 5; + + repeated OnionDbCountry countries = 7; +} + +message OnionDbCountry { + // address ranges (not present in lite files) + reserved 9, 10; + + string country_code = 1; + string country_name = 2; + string country_name_local = 3; + + uint32 total_node_count = 4; + uint32 entry_node_count = 5; + uint32 exit_node_count = 6; + uint32 fast_node_count = 7; + uint32 online_node_count = 8; +} \ No newline at end of file diff --git a/DragonFruit.Sakura/Wiki/Wiki.razor.cs b/DragonFruit.Sakura/Wiki/Wiki.razor.cs index 1e0311b..f0b12e9 100644 --- a/DragonFruit.Sakura/Wiki/Wiki.razor.cs +++ b/DragonFruit.Sakura/Wiki/Wiki.razor.cs @@ -43,7 +43,7 @@ protected override async Task OnParametersSetAsync() try { - var request = new ApiWikiPageRequest(Path); + var request = new WikiPageRequest(Path); PageMetadata = await Client.PerformAsync(request).ConfigureAwait(false); PageContent = Renderer.ProcessPage(PageMetadata);