mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 14:49:06 +00:00
Moved
This commit is contained in:
parent
d1cb5204c1
commit
6cbbcbc1e1
@ -1,5 +1,5 @@
|
||||
using AIStudio;
|
||||
using AIStudio.Components;
|
||||
using AIStudio.Settings;
|
||||
using MudBlazor;
|
||||
using MudBlazor.Services;
|
||||
|
||||
|
47
app/MindWork AI Studio/Settings/SettingsManager.cs
Normal file
47
app/MindWork AI Studio/Settings/SettingsManager.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System.Text.Json;
|
||||
using AIStudio.Provider;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public sealed class SettingsManager
|
||||
{
|
||||
private const string SETTINGS_FILENAME = "settings.json";
|
||||
|
||||
public static string? ConfigDirectory { get; set; }
|
||||
|
||||
public static string? DataDirectory { get; set; }
|
||||
|
||||
public bool IsSetUp => !string.IsNullOrWhiteSpace(ConfigDirectory) && !string.IsNullOrWhiteSpace(DataDirectory);
|
||||
|
||||
private readonly record struct GetSecretRequest(string Destination, string UserName);
|
||||
|
||||
public async Task<string> GetAPIKey(IJSRuntime jsRuntime, IProvider provider) => await jsRuntime.InvokeAsync<string>("window.__TAURI__.invoke", "get_secret", new GetSecretRequest($"provider::{provider.Id}::{provider.InstanceName}::api_key", Environment.UserName));
|
||||
|
||||
private readonly record struct StoreSecretRequest(string Destination, string UserName, string Secret);
|
||||
|
||||
public async Task SetAPIKey(IJSRuntime jsRuntime, IProvider provider, string key) => await jsRuntime.InvokeVoidAsync("window.__TAURI__.invoke", "store_secret", new StoreSecretRequest($"provider::{provider.Id}::{provider.InstanceName}::api_key", Environment.UserName, key));
|
||||
|
||||
public async Task<Data> LoadSettings()
|
||||
{
|
||||
if(!this.IsSetUp)
|
||||
return new Data();
|
||||
|
||||
var settingsPath = Path.Combine(ConfigDirectory!, SETTINGS_FILENAME);
|
||||
if(!File.Exists(settingsPath))
|
||||
return new Data();
|
||||
|
||||
var settingsJson = await File.ReadAllTextAsync(settingsPath);
|
||||
return JsonSerializer.Deserialize<Data>(settingsJson) ?? new Data();
|
||||
}
|
||||
|
||||
public async Task StoreSettings(Data data)
|
||||
{
|
||||
if(!this.IsSetUp)
|
||||
return;
|
||||
|
||||
var settingsPath = Path.Combine(ConfigDirectory!, SETTINGS_FILENAME);
|
||||
var settingsJson = JsonSerializer.Serialize(data);
|
||||
await File.WriteAllTextAsync(settingsPath, settingsJson);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace AIStudio;
|
||||
|
||||
public sealed class SettingsManager
|
||||
{
|
||||
public static string? ConfigDirectory { get; set; }
|
||||
|
||||
public static string? DataDirectory { get; set; }
|
||||
|
||||
public bool IsSetUp => !string.IsNullOrWhiteSpace(ConfigDirectory) && !string.IsNullOrWhiteSpace(DataDirectory);
|
||||
|
||||
private readonly record struct GetSecretRequest(string Destination, string UserName);
|
||||
|
||||
public async Task<string> GetAPIKey(IJSRuntime jsRuntime) => await jsRuntime.InvokeAsync<string>("window.__TAURI__.invoke", "get_secret", new GetSecretRequest("api_key", Environment.UserName));
|
||||
|
||||
private readonly record struct StoreSecretRequest(string Destination, string UserName, string Secret);
|
||||
|
||||
public async Task SetAPIKey(IJSRuntime jsRuntime, string key) => await jsRuntime.InvokeVoidAsync("window.__TAURI__.invoke", "store_secret", new StoreSecretRequest("api_key", Environment.UserName, key));
|
||||
}
|
Loading…
Reference in New Issue
Block a user