From 054fb66a00ff1698e0a1d6dd1063e5c1a2c48131 Mon Sep 17 00:00:00 2001 From: pancakes Date: Sat, 29 Mar 2025 12:49:58 +1000 Subject: [PATCH] [backend/masto-client] Add icon to InstanceInfoV2Response --- .../Controllers/Mastodon/InstanceController.cs | 12 +++++++++--- .../Mastodon/Schemas/InstanceInfoV2Response.cs | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Iceshrimp.Backend/Controllers/Mastodon/InstanceController.cs b/Iceshrimp.Backend/Controllers/Mastodon/InstanceController.cs index 05e8105f..2e993d20 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/InstanceController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/InstanceController.cs @@ -61,14 +61,20 @@ public class InstanceController( && !Constants.SystemUsers.Contains(p.UsernameLower) && p.LastActiveDate > cutoff); - var (instanceName, instanceDescription, adminContact) = + var (instanceName, instanceDescription, adminContact, iconId) = await meta.GetManyAsync(MetaEntity.InstanceName, MetaEntity.InstanceDescription, - MetaEntity.AdminContactEmail); + MetaEntity.AdminContactEmail, MetaEntity.IconFileId); + + var favicon = await db.DriveFiles.Where(p => p.Id == iconId) + .Select(p => new InstanceIcon(p.PublicUrl ?? p.RawAccessUrl, p.Properties.Width ?? 128, + p.Properties.Height ?? 128)) + .FirstOrDefaultAsync(); return new InstanceInfoV2Response(config.Value, instanceName, instanceDescription, adminContact) { Usage = new InstanceUsage { Users = new InstanceUsersUsage { ActiveMonth = activeMonth } }, - Rules = await GetRules() + Rules = await GetRules(), + Icons = favicon != null ? [favicon] : [] }; } diff --git a/Iceshrimp.Backend/Controllers/Mastodon/Schemas/InstanceInfoV2Response.cs b/Iceshrimp.Backend/Controllers/Mastodon/Schemas/InstanceInfoV2Response.cs index 0b05e1fb..38095a45 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/Schemas/InstanceInfoV2Response.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/Schemas/InstanceInfoV2Response.cs @@ -29,6 +29,8 @@ public class InstanceInfoV2Response( [J("rules")] public required List Rules { get; set; } + [J("icon")] public required List Icons { get; set; } + //TODO: add the rest } @@ -76,4 +78,10 @@ public class InstanceExtendedDescription(string? description) [J("content")] public string Content => description ?? "This Iceshrimp.NET instance does not appear to have a description"; +} + +public class InstanceIcon(string src, int width, int height) +{ + [J("src")] public string Url => src; + [J("size")] public string Size => $"{width}x{height}"; } \ No newline at end of file