From cde0691cec9489c930626122152ae8edbb488dbb Mon Sep 17 00:00:00 2001 From: pancakes Date: Sat, 29 Mar 2025 02:01:31 +1000 Subject: [PATCH] [backend/razor] Add UI for setting instance icon --- .../Core/Services/MetaService.cs | 1 + Iceshrimp.Backend/Pages/Admin/Metadata.razor | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Iceshrimp.Backend/Core/Services/MetaService.cs b/Iceshrimp.Backend/Core/Services/MetaService.cs index c943777a..7579fa4a 100644 --- a/Iceshrimp.Backend/Core/Services/MetaService.cs +++ b/Iceshrimp.Backend/Core/Services/MetaService.cs @@ -80,6 +80,7 @@ public static class MetaEntity public static readonly NullableStringMeta InstanceDescription = new("instance_description"); public static readonly NullableStringMeta AdminContactEmail = new("admin_contact_email"); public static readonly NullableStringMeta ThemeColor = new("theme_color"); + public static readonly NullableStringMeta IconFileId = new("icon_file_id"); } public class Meta( diff --git a/Iceshrimp.Backend/Pages/Admin/Metadata.razor b/Iceshrimp.Backend/Pages/Admin/Metadata.razor index bc268a52..adce1be8 100644 --- a/Iceshrimp.Backend/Pages/Admin/Metadata.razor +++ b/Iceshrimp.Backend/Pages/Admin/Metadata.razor @@ -10,7 +10,9 @@

Here you can adjust basic instance metadata. It gets displayed to all users, including guests.

- + + + @@ -23,16 +25,19 @@ @code { - [Inject] public required MetaService Meta { get; set; } + [Inject] public required DriveService Drive { get; set; } + [Inject] public required MetaService Meta { get; set; } + [Inject] public required SystemUserService SystemUser { get; set; } [SupplyParameterFromForm] private MetadataModel Model { get; set; } = null!; private class MetadataModel { - public string? Name { get; set; } - public string? Description { get; set; } - public string? AdminContact { get; set; } - public string? ThemeColor { get; set; } + public string? Name { get; set; } + public string? Description { get; set; } + public string? AdminContact { get; set; } + public string? ThemeColor { get; set; } + public IFormFile? IconFile { get; set; } public void Canonicalize() { @@ -51,6 +56,8 @@ AdminContact = null; if (!colorRegex.IsMatch(ThemeColor ?? "")) ThemeColor = null; + if (!IconFile?.ContentType.StartsWith("image/") ?? false) + IconFile = null; } } @@ -74,6 +81,15 @@ await Meta.SetAsync(MetaEntity.AdminContactEmail, Model.AdminContact); await Meta.SetAsync(MetaEntity.ThemeColor, Model.ThemeColor); + if (Model.IconFile != null) + { + var ia = await SystemUser.GetInstanceActorAsync(); + var req = new DriveFileCreationRequest { Filename = Model.IconFile.Name, IsSensitive = false, MimeType = Model.IconFile.ContentType }; + + var file = await Drive.StoreFileAsync(Model.IconFile.OpenReadStream(), ia, req); + await Meta.SetAsync(MetaEntity.IconFileId, file.Id); + } + ReloadPage(); } } \ No newline at end of file