Fixed Indexer SwaggerUI, Added worker & call management endpoints to Indexer, restructuring to improve project separation

This commit is contained in:
2025-07-12 22:55:56 +02:00
parent a884a2734d
commit e8e5b742d1
30 changed files with 558 additions and 189 deletions

View File

@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
namespace Shared;
public class ApiKeyMiddleware
{
private readonly RequestDelegate _next;
private readonly IConfiguration _configuration;
public ApiKeyMiddleware(RequestDelegate next, IConfiguration configuration)
{
_next = next;
_configuration = configuration;
}
public async Task InvokeAsync(HttpContext context)
{
if (!context.Request.Headers.TryGetValue("X-API-KEY", out StringValues extractedApiKey))
{
context.Response.StatusCode = 401;
await context.Response.WriteAsync("API Key is missing.");
return;
}
var validApiKeys = _configuration.GetSection("Embeddingsearch").GetSection("ApiKeys").Get<List<string>>();
#pragma warning disable CS8604
if (validApiKeys == null || !validApiKeys.Contains(extractedApiKey)) // CS8604 extractedApiKey is not null here, but the compiler still thinks that it might be.
{
context.Response.StatusCode = 403;
await context.Response.WriteAsync("Invalid API Key.");
return;
}
#pragma warning restore CS8604
await _next(context);
}
}

View File

@@ -0,0 +1,75 @@
using System.Text.Json.Serialization;
namespace Shared.Models;
public class EntityQueryResults
{
[JsonPropertyName("Results")]
public required List<EntityQueryResult> Results { get; set; }
}
public class EntityQueryResult
{
[JsonPropertyName("Name")]
public required string Name { get; set; }
[JsonPropertyName("Value")]
public float Value { get; set; }
}
public class EntityIndexResult
{
[JsonPropertyName("Success")]
public required bool Success { get; set; }
}
public class EntityListResults
{
[JsonPropertyName("Results")]
public required List<EntityListResult> Results { get; set; }
[JsonPropertyName("Success")]
public required bool Success { get; set; }
}
public class EntityListResult
{
[JsonPropertyName("Name")]
public required string Name { get; set; }
[JsonPropertyName("Attributes")]
public required List<AttributeResult> Attributes { get; set; }
[JsonPropertyName("Datapoints")]
public required List<DatapointResult> Datapoints { get; set; }
}
public class AttributeResult
{
[JsonPropertyName("Name")]
public required string Name { get; set; }
[JsonPropertyName("Value")]
public required string Value { get; set; }
}
public class DatapointResult
{
[JsonPropertyName("Name")]
public required string Name { get; set; }
[JsonPropertyName("ProbMethod")]
public required string ProbMethod { get; set; }
[JsonPropertyName("Embeddings")]
public required List<EmbeddingResult>? Embeddings { get; set; }
}
public class EmbeddingResult
{
[JsonPropertyName("Model")]
public required string Model { get; set; }
[JsonPropertyName("Embeddings")]
public required float[] Embeddings { get; set; }
}
public class EntityDeleteResults
{
[JsonPropertyName("Success")]
public required bool Success { get; set; }
}

View File

@@ -0,0 +1,18 @@
namespace Shared.Models;
public class JSONEntity
{
public required string Name { get; set; }
public required string Probmethod { get; set; }
public required string Searchdomain { get; set; }
public required Dictionary<string, string> Attributes { get; set; }
public required JSONDatapoint[] Datapoints { get; set; }
}
public class JSONDatapoint
{
public required string Name { get; set; }
public required string Text { get; set; }
public required string Probmethod_embedding { get; set; }
public required string[] Model { get; set; }
}

View File

@@ -0,0 +1,32 @@
using System.Text.Json.Serialization;
namespace Shared.Models;
public class SearchdomainListResults
{
[JsonPropertyName("Searchdomains")] // Otherwise the api returns {"searchdomains": [...]} and the client requires {"Searchdomains": [...]}
public required List<string> Searchdomains { get; set; }
}
public class SearchdomainCreateResults
{
[JsonPropertyName("Success")]
public required bool Success { get; set; }
[JsonPropertyName("Id")]
public int? Id { get; set; }
}
public class SearchdomainUpdateResults
{
[JsonPropertyName("Success")]
public required bool Success { get; set; }
}
public class SearchdomainDeleteResults
{
[JsonPropertyName("Success")]
public required bool Success { get; set; }
[JsonPropertyName("DeletedEntities")]
public required int DeletedEntities { get; set; }
}

11
src/Shared/Shared.csproj Normal file
View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ElmahCore" Version="2.1.2" />
</ItemGroup>
</Project>