Skip to content

Commit 8ed8ae5

Browse files
committed
refactor some api options usages
1 parent c6ce57e commit 8ed8ae5

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

StabilityMatrix.Avalonia/App.axaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte
640640
(sp, c) =>
641641
{
642642
var options = sp.GetRequiredService<IOptions<ApiOptions>>().Value;
643-
c.BaseAddress = options.AuthApiBaseUrl;
643+
c.BaseAddress = options.LykosAuthApiBaseUrl;
644644
c.Timeout = TimeSpan.FromHours(1);
645645
}
646646
)
@@ -656,7 +656,7 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte
656656
(sp, c) =>
657657
{
658658
var options = sp.GetRequiredService<IOptions<ApiOptions>>().Value;
659-
c.BaseAddress = options.AuthApiBaseUrl;
659+
c.BaseAddress = options.LykosAuthApiBaseUrl;
660660
c.Timeout = TimeSpan.FromHours(1);
661661
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "");
662662
}
@@ -673,7 +673,7 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte
673673
(sp, c) =>
674674
{
675675
var options = sp.GetRequiredService<IOptions<ApiOptions>>().Value;
676-
c.BaseAddress = options.AuthApiBaseUrl;
676+
c.BaseAddress = options.LykosAuthApiBaseUrl;
677677
c.Timeout = TimeSpan.FromHours(1);
678678
}
679679
)
@@ -686,7 +686,7 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte
686686
(sp, c) =>
687687
{
688688
var options = sp.GetRequiredService<IOptions<ApiOptions>>().Value;
689-
c.BaseAddress = options.PromptGenApiBaseUrl;
689+
c.BaseAddress = options.LykosPromptGenApiBaseUrl;
690690
c.Timeout = TimeSpan.FromHours(1);
691691
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "");
692692
}
@@ -703,7 +703,7 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte
703703
(sp, c) =>
704704
{
705705
var options = sp.GetRequiredService<IOptions<ApiOptions>>().Value;
706-
c.BaseAddress = options.AnalyticsApiBaseUrl;
706+
c.BaseAddress = options.LykosAnalyticsApiBaseUrl;
707707
c.Timeout = TimeSpan.FromMinutes(5);
708708
}
709709
)
@@ -768,7 +768,7 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte
768768
new OpenIddictClientRegistration
769769
{
770770
ProviderName = OpenIdClientConstants.LykosAccount.ProviderName,
771-
Issuer = apiOptions.AccountApiBaseUrl,
771+
Issuer = apiOptions.LykosAccountApiBaseUrl,
772772
ClientId = "ai.lykos.stabilitymatrix",
773773
Scopes =
774774
{

StabilityMatrix.Avalonia/ViewModels/Dialogs/OAuthGoogleLoginViewModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Injectio.Attributes;
1010
using MessagePipe;
1111
using Microsoft.Extensions.Logging;
12+
using Microsoft.Extensions.Options;
1213
using NSec.Cryptography;
1314
using Refit;
1415
using StabilityMatrix.Avalonia.Services;
@@ -17,6 +18,7 @@
1718
using StabilityMatrix.Core.Attributes;
1819
using StabilityMatrix.Core.Extensions;
1920
using StabilityMatrix.Core.Models.Api.Lykos;
21+
using StabilityMatrix.Core.Models.Configs;
2022
using StabilityMatrix.Core.Processes;
2123

2224
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
@@ -29,7 +31,8 @@ public class OAuthGoogleLoginViewModel(
2931
IDistributedSubscriber<string, Uri> uriHandlerSubscriber,
3032
ILogger<OAuthGoogleLoginViewModel> logger,
3133
ILykosAuthApiV1 lykosAuthApi,
32-
IAccountsService accountsService
34+
IAccountsService accountsService,
35+
IOptions<ApiOptions> apiOptions
3336
) : OAuthLoginViewModel(baseLogger, uriHandlerSubscriber)
3437
{
3538
private string? challenge;
@@ -137,7 +140,7 @@ private async Task GenerateUrlAsync()
137140
{
138141
(challenge, verifier) = GeneratePkceSha256ChallengePair();
139142

140-
var redirectUri = new Uri(App.LykosAuthApiBaseUrl).Append("/api/open/sm/oauth/google/callback");
143+
var redirectUri = apiOptions.Value.LykosAuthApiBaseUrl.Append("/api/open/sm/oauth/google/callback");
141144

142145
logger.LogDebug("Requesting Google OAuth URL...");
143146

StabilityMatrix.Avalonia/ViewModels/Settings/AccountSettingsViewModel.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using FluentAvalonia.UI.Controls;
1212
using FluentIcons.Common;
1313
using Injectio.Attributes;
14+
using Microsoft.Extensions.Options;
1415
using OpenIddict.Client;
1516
using StabilityMatrix.Avalonia.Controls;
1617
using StabilityMatrix.Avalonia.Languages;
@@ -24,6 +25,7 @@
2425
using StabilityMatrix.Core.Extensions;
2526
using StabilityMatrix.Core.Models.Api;
2627
using StabilityMatrix.Core.Models.Api.Lykos;
28+
using StabilityMatrix.Core.Models.Configs;
2729
using StabilityMatrix.Core.Processes;
2830
using StabilityMatrix.Core.Services;
2931
using Symbol = FluentIcons.Common.Symbol;
@@ -42,6 +44,7 @@ public partial class AccountSettingsViewModel : PageViewModelBase
4244
private readonly IServiceManager<ViewModelBase> vmFactory;
4345
private readonly INotificationService notificationService;
4446
private readonly ILykosAuthApiV2 lykosAuthApi;
47+
private readonly IOptions<ApiOptions> apiOptions;
4548

4649
/// <inheritdoc />
4750
public override string Title => "Accounts";
@@ -69,21 +72,24 @@ public partial class AccountSettingsViewModel : PageViewModelBase
6972
[ObservableProperty]
7073
private CivitAccountStatusUpdateEventArgs civitStatus = CivitAccountStatusUpdateEventArgs.Disconnected;
7174

72-
public string LykosAccountManageUrl => new Uri(App.LykosAccountApiBaseUrl).Append("/manage").ToString();
75+
public string LykosAccountManageUrl =>
76+
apiOptions.Value.LykosAccountApiBaseUrl.Append("/manage").ToString();
7377

7478
public AccountSettingsViewModel(
7579
IAccountsService accountsService,
7680
ISettingsManager settingsManager,
7781
IServiceManager<ViewModelBase> vmFactory,
7882
INotificationService notificationService,
79-
ILykosAuthApiV2 lykosAuthApi
83+
ILykosAuthApiV2 lykosAuthApi,
84+
IOptions<ApiOptions> apiOptions
8085
)
8186
{
8287
this.accountsService = accountsService;
8388
this.settingsManager = settingsManager;
8489
this.vmFactory = vmFactory;
8590
this.notificationService = notificationService;
8691
this.lykosAuthApi = lykosAuthApi;
92+
this.apiOptions = apiOptions;
8793

8894
accountsService.LykosAccountStatusUpdate += (_, args) =>
8995
{
@@ -128,24 +134,24 @@ private async Task<bool> BeforeConnectCheck()
128134
Title = "About Account Credentials",
129135
Content = """
130136
Account credentials and tokens are stored locally on your computer, with at-rest AES encryption.
131-
137+
132138
If you make changes to your computer hardware, you may need to re-login to your accounts.
133-
139+
134140
Account tokens will not be viewable after saving, please make a note of them if you need to use them elsewhere.
135141
""",
136142
PrimaryButtonText = Resources.Action_Continue,
137143
CloseButtonText = Resources.Action_Cancel,
138144
DefaultButton = ContentDialogButton.Primary,
139-
MaxDialogWidth = 400
145+
MaxDialogWidth = 400,
140146
};
141147

142148
if (await dialog.ShowAsync() != ContentDialogResult.Primary)
143149
{
144150
return false;
145151
}
146152

147-
settingsManager.Transaction(
148-
s => s.SeenTeachingTips.Add(TeachingTip.AccountsCredentialsStorageNotice)
153+
settingsManager.Transaction(s =>
154+
s.SeenTeachingTips.Add(TeachingTip.AccountsCredentialsStorageNotice)
149155
);
150156
}
151157

@@ -161,7 +167,7 @@ private async Task ConnectLykos()
161167
var vm = vmFactory.Get<OAuthDeviceAuthViewModel>();
162168
vm.ChallengeRequest = new OpenIddictClientModels.DeviceChallengeRequest
163169
{
164-
ProviderName = OpenIdClientConstants.LykosAccount.ProviderName
170+
ProviderName = OpenIdClientConstants.LykosAccount.ProviderName,
165171
};
166172
await vm.ShowDialogAsync();
167173

@@ -236,15 +242,15 @@ private async Task ConnectCivit()
236242
{
237243
throw new ValidationException("API key is required");
238244
}
239-
}
240-
}
245+
},
246+
},
241247
};
242248

243249
var dialog = DialogHelper.CreateTextEntryDialog(
244250
"Connect CivitAI Account",
245251
"""
246252
Login to [CivitAI](https://civitai.com/) and head to your [Account](https://civitai.com/user/account) page
247-
253+
248254
Add a new API key and paste it below
249255
""",
250256
"avares://StabilityMatrix.Avalonia/Assets/guide-civitai-api.webp",

StabilityMatrix.Core/Models/Configs/ApiOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ public record ApiOptions
88
/// <summary>
99
/// Base URL for Lykos Authentication API
1010
/// </summary>
11-
public Uri AuthApiBaseUrl { get; init; } = new("https://auth.lykos.ai");
11+
public Uri LykosAuthApiBaseUrl { get; init; } = new("https://auth.lykos.ai");
1212

1313
/// <summary>
1414
/// Base URL for Lykos Analytics API
1515
/// </summary>
16-
public Uri AnalyticsApiBaseUrl { get; init; } = new("https://analytics.lykos.ai");
16+
public Uri LykosAnalyticsApiBaseUrl { get; init; } = new("https://analytics.lykos.ai");
1717

1818
/// <summary>
1919
/// Base URL for Lykos Account API
2020
/// </summary>
21-
public Uri AccountApiBaseUrl { get; init; } = new("https://account.lykos.ai/");
21+
public Uri LykosAccountApiBaseUrl { get; init; } = new("https://account.lykos.ai/");
2222

2323
/// <summary>
2424
/// Base URL for PromptGen API
2525
/// </summary>
26-
public Uri PromptGenApiBaseUrl { get; init; } = new("https://promptgen.lykos.ai/api");
26+
public Uri LykosPromptGenApiBaseUrl { get; init; } = new("https://promptgen.lykos.ai/api");
2727
}

0 commit comments

Comments
 (0)