[backend/database] Move emoji url generation to the Emoji entity
This commit is contained in:
parent
333611f65e
commit
c38ff71791
3 changed files with 11 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Database.Tables;
|
namespace Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
@ -55,4 +56,12 @@ public class Emoji
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Column("height")]
|
[Column("height")]
|
||||||
public int? Height { get; set; }
|
public int? Height { get; set; }
|
||||||
|
|
||||||
|
public string GetPublicUri(Config.InstanceSection config) => Host == null
|
||||||
|
? $"https://{config.WebDomain}/emoji/{Name}"
|
||||||
|
: throw new Exception("Cannot access PublicUri for remote emoji");
|
||||||
|
|
||||||
|
public string? GetPublicUriOrNull(Config.InstanceSection config) => Host == null
|
||||||
|
? $"https://{config.WebDomain}/emoji/{Name}"
|
||||||
|
: null;
|
||||||
}
|
}
|
|
@ -97,7 +97,7 @@ public class ActivityRenderer(
|
||||||
|
|
||||||
var e = new ASEmoji
|
var e = new ASEmoji
|
||||||
{
|
{
|
||||||
Id = emoji.Host == null ? $"https://{config.Value.WebDomain}/emoji/{emoji.Name}" : null,
|
Id = emoji.GetPublicUriOrNull(config.Value),
|
||||||
Name = name,
|
Name = name,
|
||||||
Image = new ASImage { Url = new ASLink(emoji.PublicUrl) }
|
Image = new ASImage { Url = new ASLink(emoji.PublicUrl) }
|
||||||
};
|
};
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
||||||
}))
|
}))
|
||||||
.Concat(emoji.Select(e => new ASEmoji
|
.Concat(emoji.Select(e => new ASEmoji
|
||||||
{
|
{
|
||||||
Id = $"https://{config.Value.WebDomain}/emoji/{e.Name}",
|
Id = e.GetPublicUri(config.Value),
|
||||||
Name = e.Name,
|
Name = e.Name,
|
||||||
Image = new ASImage { Url = new ASLink(e.PublicUrl) }
|
Image = new ASImage { Url = new ASLink(e.PublicUrl) }
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Add table
Reference in a new issue