[backend/core] Populate & render emoji media type if available

This commit is contained in:
Laura Hausmann 2025-02-17 20:31:41 +01:00
parent ca786026c2
commit 7c93c5591a
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
6 changed files with 74 additions and 30 deletions

View file

@ -334,7 +334,7 @@ public class ActivityPubController(
{ {
Id = emoji.GetPublicUri(config.Value), Id = emoji.GetPublicUri(config.Value),
Name = emoji.Name, Name = emoji.Name,
Image = new ASImage { Url = new ASLink(emoji.RawPublicUrl) } Image = new ASImage { Url = new ASLink(emoji.RawPublicUrl), MediaType = emoji.Type }
}; };
return LdHelpers.Compact(rendered); return LdHelpers.Compact(rendered);

View file

@ -0,0 +1,41 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
[DbContext(typeof(DatabaseContext))]
[Migration("20250217192617_FixupEmojiType")]
public partial class FixupEmojiType : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
UPDATE "emoji"
SET "type" =
(SELECT COALESCE("drive_file"."webpublicType", "drive_file"."type")
FROM "drive_file"
WHERE "drive_file"."userHost" IS NULL
AND ("drive_file"."webpublicUrl" = "emoji"."publicUrl"
OR "drive_file"."url" = "emoji"."publicUrl"
)
)
WHERE "host" IS NULL
AND EXISTS
(SELECT 1
FROM "drive_file"
WHERE "drive_file"."userHost" IS NULL
AND ("drive_file"."webpublicUrl" = "emoji"."publicUrl"
OR "drive_file"."url" = "emoji"."publicUrl"
)
);
""");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) { }
}
}

View file

@ -92,7 +92,7 @@ public class ActivityRenderer(
{ {
Id = emoji.GetPublicUriOrNull(config.Value), Id = emoji.GetPublicUriOrNull(config.Value),
Name = name, Name = name,
Image = new ASImage { Url = new ASLink(emoji.RawPublicUrl) } Image = new ASImage { Url = new ASLink(emoji.RawPublicUrl), MediaType = emoji.Type }
}; };
res.Tags = [e]; res.Tags = [e];

View file

@ -105,7 +105,7 @@ public class NoteRenderer(
{ {
Id = e.GetPublicUri(config.Value), Id = e.GetPublicUri(config.Value),
Name = e.Name, Name = e.Name,
Image = new ASImage { Url = new ASLink(e.RawPublicUrl) } Image = new ASImage { Url = new ASLink(e.RawPublicUrl), MediaType = e.Type }
})) }))
.ToList(); .ToList();

View file

@ -74,7 +74,7 @@ public class UserRenderer(
{ {
Id = e.GetPublicUri(config.Value), Id = e.GetPublicUri(config.Value),
Name = e.Name, Name = e.Name,
Image = new ASImage { Url = new ASLink(e.RawPublicUrl) } Image = new ASImage { Url = new ASLink(e.RawPublicUrl), MediaType = e.Type }
})) }))
.ToList(); .ToList();

View file

@ -56,6 +56,7 @@ public partial class EmojiService(
UpdatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow,
OriginalUrl = driveFile.Url, OriginalUrl = driveFile.Url,
RawPublicUrl = driveFile.RawAccessUrl, RawPublicUrl = driveFile.RawAccessUrl,
Type = driveFile.PublicMimeType ?? driveFile.Type,
Width = driveFile.Properties.Width, Width = driveFile.Properties.Width,
Height = driveFile.Properties.Height, Height = driveFile.Properties.Height,
Sensitive = false Sensitive = false
@ -82,6 +83,7 @@ public partial class EmojiService(
UpdatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow,
OriginalUrl = driveFile.Url, OriginalUrl = driveFile.Url,
RawPublicUrl = driveFile.RawAccessUrl, RawPublicUrl = driveFile.RawAccessUrl,
Type = driveFile.PublicMimeType ?? driveFile.Type,
Width = driveFile.Properties.Width, Width = driveFile.Properties.Width,
Height = driveFile.Properties.Height, Height = driveFile.Properties.Height,
Sensitive = existing.Sensitive Sensitive = existing.Sensitive
@ -133,6 +135,7 @@ public partial class EmojiService(
UpdatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow,
OriginalUrl = emojo.Image?.Url?.Link ?? throw new Exception("Emoji.Image has no url"), OriginalUrl = emojo.Image?.Url?.Link ?? throw new Exception("Emoji.Image has no url"),
RawPublicUrl = emojo.Image.Url.Link, RawPublicUrl = emojo.Image.Url.Link,
Type = emojo.Image.MediaType,
Uri = emojo.Id, Uri = emojo.Id,
Sensitive = false Sensitive = false
}; };