[backend/akko-client] Try to implement GET v1/pleroma/emoji
Akkoma-FE is doing something horrible here, I do not think this is fixable without changing the FE itself.
This commit is contained in:
parent
fefe599d32
commit
44864a2274
2 changed files with 43 additions and 0 deletions
34
Iceshrimp.Backend/Controllers/Pleroma/EmojiController.cs
Normal file
34
Iceshrimp.Backend/Controllers/Pleroma/EmojiController.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Net;
|
||||
using System.Net.Mime;
|
||||
using Iceshrimp.Backend.Controllers.Mastodon.Attributes;
|
||||
using Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
|
||||
using Iceshrimp.Backend.Controllers.Shared.Attributes;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Iceshrimp.Backend.Controllers.Pleroma;
|
||||
|
||||
[MastodonApiController]
|
||||
[EnableCors("mastodon")]
|
||||
[EnableRateLimiting("sliding")]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
public class EmojiController(DatabaseContext db) : ControllerBase
|
||||
{
|
||||
[HttpGet("/api/v1/pleroma/emoji")]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
public async Task<Dictionary<string, PleromaEmojiEntity>> GetCustomEmojis()
|
||||
{
|
||||
var emoji = await db.Emojis.Where(p => p.Host == null)
|
||||
.Select(p => KeyValuePair.Create(p.Name, new PleromaEmojiEntity
|
||||
{
|
||||
ImageUrl = new Uri(p.PublicUrl).AbsolutePath, // TODO: akkoma-fe expects *relative paths* instead of absolute URLs... i genuinely think this is unfixable without forking the fe
|
||||
Tags = p.Category == null ? new string[0] : new string[] { p.Category }
|
||||
}))
|
||||
.ToArrayAsync();
|
||||
|
||||
return new Dictionary<string, PleromaEmojiEntity>(emoji);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
|
||||
|
||||
namespace Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
|
||||
|
||||
public class PleromaEmojiEntity
|
||||
{
|
||||
[J("image_url")] public required string ImageUrl { get; set; }
|
||||
[J("tags")] public string[] Tags { get; set; } = [];
|
||||
}
|
Loading…
Add table
Reference in a new issue