mirror of
https://github.com/spacebarchat/server.git
synced 2026-03-29 14:09:52 +00:00
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
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:
@@ -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()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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...?
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
83
extra/admin-api/Spacebar.UApi/Program.cs
Normal file
83
extra/admin-api/Spacebar.UApi/Program.cs
Normal 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();
|
||||
14
extra/admin-api/Spacebar.UApi/Properties/launchSettings.json
Normal file
14
extra/admin-api/Spacebar.UApi/Properties/launchSettings.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
extra/admin-api/Spacebar.UApi/Spacebar.UApi.csproj
Normal file
32
extra/admin-api/Spacebar.UApi/Spacebar.UApi.csproj
Normal 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>
|
||||
6
extra/admin-api/Spacebar.UApi/Spacebar.UApi.http
Normal file
6
extra/admin-api/Spacebar.UApi/Spacebar.UApi.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@Spacebar.UApi_HostAddress = http://localhost:5085
|
||||
|
||||
GET {{Spacebar.UApi_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
extra/admin-api/Spacebar.UApi/appsettings.json
Normal file
9
extra/admin-api/Spacebar.UApi/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user