[backend/core] Populate & render emoji media type if available
This commit is contained in:
parent
ca786026c2
commit
7c93c5591a
6 changed files with 74 additions and 30 deletions
|
@ -334,7 +334,7 @@ public class ActivityPubController(
|
|||
{
|
||||
Id = emoji.GetPublicUri(config.Value),
|
||||
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);
|
||||
|
|
|
@ -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) { }
|
||||
}
|
||||
}
|
|
@ -92,7 +92,7 @@ public class ActivityRenderer(
|
|||
{
|
||||
Id = emoji.GetPublicUriOrNull(config.Value),
|
||||
Name = name,
|
||||
Image = new ASImage { Url = new ASLink(emoji.RawPublicUrl) }
|
||||
Image = new ASImage { Url = new ASLink(emoji.RawPublicUrl), MediaType = emoji.Type }
|
||||
};
|
||||
|
||||
res.Tags = [e];
|
||||
|
|
|
@ -105,7 +105,7 @@ public class NoteRenderer(
|
|||
{
|
||||
Id = e.GetPublicUri(config.Value),
|
||||
Name = e.Name,
|
||||
Image = new ASImage { Url = new ASLink(e.RawPublicUrl) }
|
||||
Image = new ASImage { Url = new ASLink(e.RawPublicUrl), MediaType = e.Type }
|
||||
}))
|
||||
.ToList();
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class UserRenderer(
|
|||
{
|
||||
Id = e.GetPublicUri(config.Value),
|
||||
Name = e.Name,
|
||||
Image = new ASImage { Url = new ASLink(e.RawPublicUrl) }
|
||||
Image = new ASImage { Url = new ASLink(e.RawPublicUrl), MediaType = e.Type }
|
||||
}))
|
||||
.ToList();
|
||||
|
||||
|
|
|
@ -49,16 +49,17 @@ public partial class EmojiService(
|
|||
var id = IdHelpers.GenerateSnowflakeId();
|
||||
var emoji = new Emoji
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Aliases = aliases ?? [],
|
||||
Category = category,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
OriginalUrl = driveFile.Url,
|
||||
RawPublicUrl = driveFile.RawAccessUrl,
|
||||
Width = driveFile.Properties.Width,
|
||||
Height = driveFile.Properties.Height,
|
||||
Sensitive = false
|
||||
Id = id,
|
||||
Name = name,
|
||||
Aliases = aliases ?? [],
|
||||
Category = category,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
OriginalUrl = driveFile.Url,
|
||||
RawPublicUrl = driveFile.RawAccessUrl,
|
||||
Type = driveFile.PublicMimeType ?? driveFile.Type,
|
||||
Width = driveFile.Properties.Width,
|
||||
Height = driveFile.Properties.Height,
|
||||
Sensitive = false
|
||||
};
|
||||
emoji.Uri = emoji.GetPublicUri(config.Value);
|
||||
|
||||
|
@ -77,14 +78,15 @@ public partial class EmojiService(
|
|||
|
||||
var emoji = new Emoji
|
||||
{
|
||||
Id = IdHelpers.GenerateSnowflakeId(),
|
||||
Name = existing.Name,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
OriginalUrl = driveFile.Url,
|
||||
RawPublicUrl = driveFile.RawAccessUrl,
|
||||
Width = driveFile.Properties.Width,
|
||||
Height = driveFile.Properties.Height,
|
||||
Sensitive = existing.Sensitive
|
||||
Id = IdHelpers.GenerateSnowflakeId(),
|
||||
Name = existing.Name,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
OriginalUrl = driveFile.Url,
|
||||
RawPublicUrl = driveFile.RawAccessUrl,
|
||||
Type = driveFile.PublicMimeType ?? driveFile.Type,
|
||||
Width = driveFile.Properties.Width,
|
||||
Height = driveFile.Properties.Height,
|
||||
Sensitive = existing.Sensitive
|
||||
};
|
||||
emoji.Uri = emoji.GetPublicUri(config.Value);
|
||||
|
||||
|
@ -127,14 +129,15 @@ public partial class EmojiService(
|
|||
{
|
||||
dbEmojo = new Emoji
|
||||
{
|
||||
Id = IdHelpers.GenerateSnowflakeId(),
|
||||
Host = host,
|
||||
Name = emojo.Name ?? throw new Exception("emojo.Name must not be null at this stage"),
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
OriginalUrl = emojo.Image?.Url?.Link ?? throw new Exception("Emoji.Image has no url"),
|
||||
RawPublicUrl = emojo.Image.Url.Link,
|
||||
Uri = emojo.Id,
|
||||
Sensitive = false
|
||||
Id = IdHelpers.GenerateSnowflakeId(),
|
||||
Host = host,
|
||||
Name = emojo.Name ?? throw new Exception("emojo.Name must not be null at this stage"),
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
OriginalUrl = emojo.Image?.Url?.Link ?? throw new Exception("Emoji.Image has no url"),
|
||||
RawPublicUrl = emojo.Image.Url.Link,
|
||||
Type = emojo.Image.MediaType,
|
||||
Uri = emojo.Id,
|
||||
Sensitive = false
|
||||
};
|
||||
await db.AddAsync(dbEmojo);
|
||||
await db.SaveChangesAsync();
|
||||
|
|
Loading…
Add table
Reference in a new issue