Added a check for characters which an API key cannot contain (#1227)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-24 17:20:13 +01:00
1 parent c72a1948b3
commit e5a7f5423f
40 files changed
+1179 -71

No files matched your search

@@ -1,5 +1,6 @@
using AIStudio.Tools.Services;
using AIStudio.Tools.UserAPIKeys;
using AIStudio.Tools.Validation;
using Microsoft.AspNetCore.Components;
@@ -42,12 +43,20 @@ public partial class UserAPIKeyPrompt : MSGComponentBase
private string Title => string.IsNullOrWhiteSpace(this.Group.Prompt?.Title) ? TA("Your API key is missing") : this.Group.Prompt.Title;
/// <summary>
/// Whether the entered key can be checked and stored: it is there, and it can be sent.
/// </summary>
private bool CanStoreAPIKey => !this.isBusy && !string.IsNullOrWhiteSpace(this.apiKey) && !APIKeyValidation.Check(this.apiKey).IsProblem;
private static string? ValidateAPIKey(string apiKey) => APIKeyValidation.Validate(apiKey);
private async Task StoreAPIKeyAsync()
{
var enteredAPIKey = this.apiKey.Trim();
if (this.isBusy || string.IsNullOrWhiteSpace(enteredAPIKey))
if (!this.CanStoreAPIKey)
return;
var enteredAPIKey = APIKeyValidation.Normalize(this.apiKey);
this.isBusy = true;
this.issue = string.Empty;
try