[backend/masto-client] Add icon to InstanceInfoV2Response

This commit is contained in:
pancakes 2025-03-29 12:49:58 +10:00
parent 48a8b9f14a
commit 054fb66a00
No known key found for this signature in database
2 changed files with 17 additions and 3 deletions

View file

@ -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] : []
};
}

View file

@ -29,6 +29,8 @@ public class InstanceInfoV2Response(
[J("rules")] public required List<RuleEntity> Rules { get; set; }
[J("icon")] public required List<InstanceIcon> Icons { get; set; }
//TODO: add the rest
}
@ -77,3 +79,9 @@ 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}";
}