mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-27 22:34:11 +00:00
Some unfinished templates work
This commit is contained in:
Binary file not shown.
Binary file not shown.
+1
-1
@@ -34,7 +34,7 @@ public class UnixSocketSpacebarReplication(UnixSocketConfiguration conf) : ISpac
|
||||
|
||||
public class UnixSocketConfiguration {
|
||||
public UnixSocketConfiguration(IConfiguration config) {
|
||||
config.GetRequiredSection("UnixSocketReplication").Bind(this);
|
||||
config.GetRequiredSection("Spacebar").GetRequiredSection("UnixSocketReplication").Bind(this);
|
||||
}
|
||||
|
||||
public string SocketDir { get; set; } = null!;
|
||||
|
||||
@@ -36,6 +36,7 @@ builder.Services.AddScoped<SpacebarAspNetAuthenticationService>();
|
||||
// builder.Services.AddSingleton<RabbitMQConfiguration>();
|
||||
// builder.Services.AddSingleton<RabbitMQService>();
|
||||
// builder.Services.AddSingleton<ISpacebarReplication, RabbitMqSpacebarReplication>();
|
||||
builder.Services.AddSingleton<UnixSocketConfiguration>();
|
||||
builder.Services.AddSingleton<ISpacebarReplication, UnixSocketSpacebarReplication>();
|
||||
|
||||
builder.Services.AddRequestTimeouts(x => {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Spacebar.Interop.Authentication.AspNetCore;
|
||||
using Spacebar.Models.Db.Contexts;
|
||||
using Spacebar.UApi.Models;
|
||||
using Spacebar.UApi.Services;
|
||||
|
||||
namespace Spacebar.UApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class GuildTemplatesController(ILogger<GuildMembersController> logger, SpacebarDbContext db, SpacebarAspNetAuthenticationService authService, TemplateImportService importService) : ControllerBase {
|
||||
[HttpPost("/api/v10/guilds/templates/{templateId}")]
|
||||
public async Task UseTemplate(string templateId, UseGuildTemplateRequest request) {
|
||||
var user = await authService.GetCurrentUserAsync(Request);
|
||||
await importService.CreateGuildFromTemplateById(templateId, request, user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Spacebar.UApi.Models;
|
||||
|
||||
// TODO: real schemas
|
||||
public class GuildTemplate {
|
||||
[JsonPropertyName("code")]
|
||||
public string Code { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
[JsonPropertyName("usage_count")]
|
||||
public int UsageCount { get; set; }
|
||||
|
||||
[JsonPropertyName("creator_id")]
|
||||
public string CreatorId { get; set; }
|
||||
|
||||
[JsonPropertyName("creator")]
|
||||
public JsonObject Creator { get; set; }
|
||||
|
||||
[JsonPropertyName("created_at")]
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
[JsonPropertyName("updated_at")]
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
[JsonPropertyName("source_guild_id")]
|
||||
public string SourceGuildId { get; set; }
|
||||
|
||||
[JsonPropertyName("serialized_source_guild")]
|
||||
public SerializedSourceGuild SerializedSourceGuild { get; set; }
|
||||
}
|
||||
|
||||
public class SerializedSourceGuild { }
|
||||
|
||||
public class GuildTemplateRole {
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("permissions")]
|
||||
public string Permissions { get; set; }
|
||||
|
||||
// "color" ignored for now - is deprecated anyhow
|
||||
[JsonPropertyName("colors")]
|
||||
public RoleColors Colors { get; set; }
|
||||
|
||||
[JsonPropertyName("hoist")]
|
||||
public bool Hoist { get; set; }
|
||||
|
||||
[JsonPropertyName("mentionable")]
|
||||
public bool Mentionable { get; set; }
|
||||
|
||||
// [JsonPropertyName("icon")]
|
||||
}
|
||||
|
||||
public class RoleColors {
|
||||
[JsonPropertyName("primary_color")]
|
||||
public int PrimaryColor { get; set; }
|
||||
|
||||
[JsonPropertyName("secondary_color")]
|
||||
public int? SecondaryColor { get; set; }
|
||||
|
||||
[JsonPropertyName("tertiary_color")]
|
||||
public int TertiaryColor { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Spacebar.UApi.Models;
|
||||
|
||||
public class UseGuildTemplateRequest {
|
||||
/// <summary>
|
||||
/// Data URI encoded image
|
||||
/// </summary>
|
||||
[JsonPropertyName("icon")]
|
||||
public string? Icon { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Spacebar.Interop.Authentication;
|
||||
using Spacebar.Interop.Authentication.AspNetCore;
|
||||
using Spacebar.Models.Db.Contexts;
|
||||
using Spacebar.UApi.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("APPSETTINGS_PATH")))
|
||||
@@ -32,6 +33,7 @@ builder.Services.AddDbContextPool<SpacebarDbContext>(options => {
|
||||
builder.Services.AddSingleton<SpacebarAuthenticationConfiguration>();
|
||||
builder.Services.AddScoped<SpacebarAuthenticationService>();
|
||||
builder.Services.AddScoped<SpacebarAspNetAuthenticationService>();
|
||||
builder.Services.AddScoped<TemplateImportService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using Spacebar.Models.Db.Contexts;
|
||||
using Spacebar.Models.Db.Models;
|
||||
using Spacebar.UApi.Models;
|
||||
|
||||
namespace Spacebar.UApi.Services;
|
||||
|
||||
public class TemplateImportService(SpacebarDbContext db) {
|
||||
public async Task<string> CreateGuildFromTemplateById(string templateId, UseGuildTemplateRequest request, User user) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public async Task<>
|
||||
}
|
||||
@@ -18,5 +18,5 @@
|
||||
|
||||
export interface GuildTemplateCreateSchema {
|
||||
name: string;
|
||||
avatar?: string | null;
|
||||
icon?: string | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user