cs: create uapi project
Some checks failed
Build docker images / build (api) (push) Failing after 26s
Build docker images / build (cdn) (push) Failing after 26s
Build docker images / build (cdn-cs) (push) Failing after 26s
Build docker images / build (default) (push) Failing after 25s
Build docker images / build (gateway) (push) Failing after 38s
Build docker images / build (gateway-offload) (push) Failing after 26s
Build docker images / build (admin-api) (push) Failing after 4m11s
Style / build (24.x) (push) Failing after 45s
Build / build (24.x) (push) Failing after 42s
Nix build / build-nix (push) Failing after 20s

This commit is contained in:
Rory&
2026-02-13 06:12:01 +01:00
parent ee6b7b6ccf
commit e5b7977f2a
10 changed files with 196 additions and 3 deletions

View File

@@ -2,9 +2,9 @@ using Spacebar.Models.Generic;
namespace Spacebar.DataMappings.Generic;
public static class Member
public static class MemberExtensions
{
public static Models.Generic.Member ToPublicMember(this Models.Db.Models.Member member, PartialUser? partialUser = null)
public static Member ToPublicMember(this Models.Db.Models.Member member, PartialUser? partialUser = null)
{
return new()
{
@@ -15,7 +15,8 @@ public static class Member
Collectibles = member.Collectibles,
DisplayNameStyles = member.DisplayNameStyles,
Bio = string.IsNullOrWhiteSpace(member.Bio) ? null : member.Bio,
Nick = string.IsNullOrWhiteSpace(member.Nick) ? null : member.Nick
Nick = string.IsNullOrWhiteSpace(member.Nick) ? null : member.Nick,
Roles = member.Roles.Select(x=>x.Id).ToList()
};
}
}

View File

@@ -28,6 +28,9 @@ public class Member {
[JsonPropertyName("bio")]
public string? Bio { get; set; }
[JsonPropertyName("roles")]
public List<string>? Roles { get; set; }
}
// Unsure if this is used anywhere outside of op14...?

View File

@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Spacebar.Interop.Authentication.AspNetCore;
using Spacebar.Models.Db.Contexts;
using Spacebar.DataMappings.Generic;
using Spacebar.Models.Generic;
namespace Spacebar.UApi.Controllers;
[Route("/api/v{_}/guilds/{guildId}/members/")]
public class GuildMembersController(ILogger<GuildMembersController> logger, SpacebarDbContext db, SpacebarAspNetAuthenticationService authService) : ControllerBase {
/// <summary>
/// Get a guild member by ID
/// </summary>
/// <param name="guildId">Guild ID</param>
/// <param name="memberId">Member ID</param>
/// <returns>The public member projection</returns>
/// <exception cref="InvalidOperationException">An error has occured</exception>
[HttpGet("{memberId}")]
public async Task<Member> GetMemberAsync(string guildId, string memberId) {
var user = await authService.GetCurrentUserAsync(Request);
var cmember = db.Members.SingleOrDefault(x => x.Id == user.Id && x.GuildId == guildId);
if (cmember is null)
throw new InvalidOperationException("You are not a member of this guild.");
var member = db.Members
.Include(x => x.IdNavigation) // User object
.Include(x => x.Roles)
.SingleOrDefault(x => x.Id == user.Id && x.GuildId == guildId);
if (member is null)
throw new InvalidOperationException("Member not found");
return member.ToPublicMember();
}
}

View File

@@ -0,0 +1,83 @@
using System.Text.Json.Serialization;
using ArcaneLibs;
using Microsoft.EntityFrameworkCore;
using Spacebar.Interop.Authentication;
using Spacebar.Interop.Authentication.AspNetCore;
using Spacebar.Models.Db.Contexts;
var builder = WebApplication.CreateBuilder(args);
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("APPSETTINGS_PATH")))
builder.Configuration.AddJsonFile(Environment.GetEnvironmentVariable("APPSETTINGS_PATH")!);
// Add services to the container.
builder.Services.AddControllers(options => {
options.MaxValidationDepth = null;
// options.MaxIAsyncEnumerableBufferLimit = 1;
}).AddJsonOptions(options => {
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.WriteIndented = true;
options.JsonSerializerOptions.MaxDepth = 100;
// options.JsonSerializerOptions.DefaultBufferSize = ;
}).AddMvcOptions(o => { o.SuppressOutputFormatterBuffering = true; });
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddDbContextPool<SpacebarDbContext>(options => {
options
.UseNpgsql(builder.Configuration.GetConnectionString("Spacebar"))
.EnableDetailedErrors();
});
builder.Services.AddSingleton<SpacebarAuthenticationConfiguration>();
builder.Services.AddScoped<SpacebarAuthenticationService>();
builder.Services.AddScoped<SpacebarAspNetAuthenticationService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) {
app.MapOpenApi();
}
app.UseAuthorization();
app.MapControllers();
app.Use((context, next) => {
context.Response.Headers["Access-Control-Allow-Origin"] = "*";
context.Response.Headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS";
context.Response.Headers["Access-Control-Allow-Headers"] = "*, Authorization";
if (context.Request.Method == "OPTIONS") {
context.Response.StatusCode = 200;
return Task.CompletedTask;
}
return next();
});
// fallback to proxy in case we dont have a specific endpoint...
// TODO config
app.MapFallback("{*_}", async context => {
var client = new StreamingHttpClient();
var requestMessage = new HttpRequestMessage(
new HttpMethod(context.Request.Method),
"http://api.old.server.spacebar.chat" + context.Request.Path + context.Request.QueryString
) {
Content = new StreamContent(context.Request.Body)
};
Console.WriteLine(requestMessage.RequestUri);
foreach (var header in context.Request.Headers)
if (header.Key is not ("Accept-Encoding" or "Host"))
requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray());
var responseMessage = await client.SendUnhandledAsync(requestMessage, CancellationToken.None);
context.Response.StatusCode = (int)responseMessage.StatusCode;
foreach (var header in responseMessage.Headers) context.Response.Headers[header.Key] = header.Value.ToArray();
foreach (var header in responseMessage.Content.Headers) context.Response.Headers[header.Key] = header.Value.ToArray();
await responseMessage.Content.CopyToAsync(context.Response.Body);
});
app.Run();

View File

@@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5085",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ArcaneLibs" Version="1.0.1-preview.20260126-091403"/>
<PackageReference Include="ArcaneLibs.StringNormalisation" Version="1.0.1-preview.20260126-091403"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataMappings\Spacebar.DataMappings.Generic\Spacebar.DataMappings.Generic.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
<PackageReference Include="Spacebar.DataMappings.Generic" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
<ProjectReference Include="..\Interop\Spacebar.Interop.Authentication.AspNetCore\Spacebar.Interop.Authentication.AspNetCore.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
<PackageReference Include="Spacebar.Interop.Authentication.AspNetCore" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
<ProjectReference Include="..\Interop\Spacebar.Interop.Replication.UnixSocket\Spacebar.Interop.Replication.UnixSocket.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
<PackageReference Include="Spacebar.Interop.Replication.UnixSocket" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
<ProjectReference Include="..\Models\Spacebar.Models.AdminApi\Spacebar.Models.AdminApi.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
<PackageReference Include="Spacebar.Models.AdminApi" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
<ProjectReference Include="..\Models\Spacebar.Models.Config\Spacebar.Models.Config.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
<PackageReference Include="Spacebar.Models.Config" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
<ProjectReference Include="..\Models\Spacebar.Models.Db\Spacebar.Models.Db.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
<PackageReference Include="Spacebar.Models.Db" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
<ProjectReference Include="..\Models\Spacebar.Models.Generic\Spacebar.Models.Generic.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
<PackageReference Include="Spacebar.Models.Generic" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@Spacebar.UApi_HostAddress = http://localhost:5085
GET {{Spacebar.UApi_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@@ -36,4 +36,5 @@
<Project Path="Spacebar.AdminApi/Spacebar.AdminApi.csproj" />
<Project Path="Spacebar.Cdn/Spacebar.Cdn.csproj" />
<Project Path="Spacebar.GatewayOffload/Spacebar.GatewayOffload.csproj" />
<Project Path="Spacebar.UApi/Spacebar.UApi.csproj" />
</Solution>