a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend/masto-client] Return instance name, instance description & admin contact

+54 -20
+13 -7
Iceshrimp.Backend/Controllers/Mastodon/InstanceController.cs
··· 4 4 using Iceshrimp.Backend.Controllers.Mastodon.Schemas.Entities; 5 5 using Iceshrimp.Backend.Core.Configuration; 6 6 using Iceshrimp.Backend.Core.Database; 7 + using Iceshrimp.Backend.Core.Services; 7 8 using Microsoft.AspNetCore.Cors; 8 9 using Microsoft.AspNetCore.Mvc; 9 10 using Microsoft.AspNetCore.RateLimiting; ··· 16 17 [EnableCors("mastodon")] 17 18 [EnableRateLimiting("sliding")] 18 19 [Produces(MediaTypeNames.Application.Json)] 19 - public class InstanceController(DatabaseContext db) : ControllerBase 20 + public class InstanceController(DatabaseContext db, MetaService meta) : ControllerBase 20 21 { 21 22 [HttpGet("/api/v1/instance")] 22 23 [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(InstanceInfoV1Response))] ··· 24 25 { 25 26 var userCount = 26 27 await db.Users.LongCountAsync(p => p.Host == null && !Constants.SystemUsers.Contains(p.UsernameLower)); 27 - var noteCount = await db.Notes.LongCountAsync(p => p.UserHost == null); 28 - var instanceCount = await db.Instances.LongCountAsync(); 29 - //TODO: admin contact 28 + var noteCount = await db.Notes.LongCountAsync(p => p.UserHost == null); 29 + var instanceCount = await db.Instances.LongCountAsync(); 30 + var instanceName = await meta.Get(MetaEntity.InstanceName); 31 + var instanceDescription = await meta.Get(MetaEntity.InstanceDescription); 32 + var adminContact = await meta.Get(MetaEntity.AdminContactEmail); 30 33 31 - var res = new InstanceInfoV1Response(config.Value) 34 + var res = new InstanceInfoV1Response(config.Value, instanceName, instanceDescription, adminContact) 32 35 { 33 36 Stats = new InstanceStats(userCount, noteCount, instanceCount) 34 37 }; ··· 44 47 var activeMonth = await db.Users.LongCountAsync(p => p.Host == null && 45 48 !Constants.SystemUsers.Contains(p.UsernameLower) && 46 49 p.LastActiveDate > cutoff); 47 - //TODO: admin contact 50 + 51 + var instanceName = await meta.Get(MetaEntity.InstanceName); 52 + var instanceDescription = await meta.Get(MetaEntity.InstanceDescription); 53 + var adminContact = await meta.Get(MetaEntity.AdminContactEmail); 48 54 49 - var res = new InstanceInfoV2Response(config.Value) 55 + var res = new InstanceInfoV2Response(config.Value, instanceName, instanceDescription, adminContact) 50 56 { 51 57 Usage = new InstanceUsage { Users = new InstanceUsersUsage { ActiveMonth = activeMonth } } 52 58 };
+19 -6
Iceshrimp.Backend/Controllers/Mastodon/Schemas/InstanceInfoV1Response.cs
··· 1 1 using Iceshrimp.Backend.Core.Configuration; 2 + using Iceshrimp.Backend.Core.Extensions; 2 3 using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 3 4 4 5 namespace Iceshrimp.Backend.Controllers.Mastodon.Schemas; 5 6 6 - public class InstanceInfoV1Response(Config config) 7 + public class InstanceInfoV1Response( 8 + Config config, 9 + string? instanceName, 10 + string? instanceDescription, 11 + string? adminContact 12 + ) 7 13 { 8 14 [J("stats")] public required InstanceStats Stats; 9 15 [J("version")] public string Version => $"4.2.1 (compatible; Iceshrimp.NET/{config.Instance.Version})"; 10 16 11 - [J("max_toot_chars")] public int MaxNoteChars => config.Instance.CharacterLimit; 12 - [J("uri")] public string AccountDomain => config.Instance.AccountDomain; 13 - [J("title")] public string InstanceName => config.Instance.AccountDomain; 14 - [J("short_description")] public string ShortDescription => $"{config.Instance.AccountDomain} on Iceshrimp.NET"; 15 - [J("description")] public string Description => $"{config.Instance.AccountDomain} on Iceshrimp.NET"; 17 + [J("max_toot_chars")] public int MaxNoteChars => config.Instance.CharacterLimit; 18 + [J("uri")] public string AccountDomain => config.Instance.AccountDomain; 19 + [J("title")] public string InstanceName => instanceName ?? config.Instance.AccountDomain; 20 + [J("email")] public string Email => adminContact ?? "unset@example.org"; 21 + 22 + [J("short_description")] 23 + public string ShortDescription => instanceDescription?.Truncate(140) ?? 24 + "This Iceshrimp.NET instance does not appear to have a description"; 25 + 26 + [J("description")] 27 + public string Description => instanceDescription ?? 28 + "This Iceshrimp.NET instance does not appear to have a description"; 16 29 17 30 [J("registrations")] public bool RegsOpen => config.Security.Registrations == Enums.Registrations.Open; 18 31 [J("invites_enabled")] public bool RegsInvite => config.Security.Registrations == Enums.Registrations.Invite;
+22 -7
Iceshrimp.Backend/Controllers/Mastodon/Schemas/InstanceInfoV2Response.cs
··· 1 1 using Iceshrimp.Backend.Core.Configuration; 2 + using Iceshrimp.Backend.Core.Extensions; 2 3 using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 3 4 4 5 namespace Iceshrimp.Backend.Controllers.Mastodon.Schemas; 5 6 6 - public class InstanceInfoV2Response(Config config) 7 + public class InstanceInfoV2Response( 8 + Config config, 9 + string? instanceName, 10 + string? instanceDescription, 11 + string? adminContact 12 + ) 7 13 { 8 - [J("version")] public string Version => $"4.2.1 (compatible; Iceshrimp.NET/{config.Instance.Version})"; 9 - [J("source_url")] public string SourceUrl => "https://iceshrimp.dev/iceshrimp/iceshrimp.net"; 10 - [J("domain")] public string AccountDomain => config.Instance.AccountDomain; 11 - [J("title")] public string InstanceName => config.Instance.AccountDomain; 12 - [J("description")] public string Description => $"{config.Instance.AccountDomain} on Iceshrimp.NET"; 14 + [J("version")] public string Version => $"4.2.1 (compatible; Iceshrimp.NET/{config.Instance.Version})"; 15 + [J("source_url")] public string SourceUrl => "https://iceshrimp.dev/iceshrimp/iceshrimp.net"; 16 + [J("domain")] public string AccountDomain => config.Instance.AccountDomain; 17 + [J("title")] public string InstanceName => instanceName ?? config.Instance.AccountDomain; 18 + 19 + [J("description")] 20 + public string Description => instanceDescription?.Truncate(140) ?? 21 + "This Iceshrimp.NET instance does not appear to have a description"; 13 22 23 + [J("contact")] public InstanceContact Contact => new(adminContact); 14 24 [J("registrations")] public InstanceRegistrations Registrations => new(config.Security); 15 25 [J("configuration")] public InstanceConfigurationV2 Configuration => new(config.Instance); 16 26 17 - [J("usage")] public required InstanceUsage Usage { get; set; } 27 + [J("usage")] public required InstanceUsage Usage { get; set; } 18 28 19 29 //TODO: add the rest 20 30 } ··· 45 55 public class InstanceUsersUsage 46 56 { 47 57 [J("active_month")] public required long ActiveMonth { get; set; } 58 + } 59 + 60 + public class InstanceContact(string? adminContact) 61 + { 62 + [J("email")] public string Email => adminContact ?? "unset@example.org"; 48 63 }