[backend/api] Add url & uri properties to NoteBase

This commit is contained in:
Laura Hausmann 2024-06-23 01:13:43 +02:00
parent 259a21b273
commit 8606df89c0
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 12 additions and 1 deletions

View file

@ -1,3 +1,4 @@
using Iceshrimp.Backend.Core.Configuration;
using Iceshrimp.Shared.Schemas; using Iceshrimp.Shared.Schemas;
using Iceshrimp.Backend.Core.Database; using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Database.Tables; using Iceshrimp.Backend.Core.Database.Tables;
@ -5,10 +6,16 @@ using Iceshrimp.Backend.Core.Extensions;
using Iceshrimp.Backend.Core.Helpers; using Iceshrimp.Backend.Core.Helpers;
using Iceshrimp.Backend.Core.Services; using Iceshrimp.Backend.Core.Services;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Iceshrimp.Backend.Controllers.Renderers; namespace Iceshrimp.Backend.Controllers.Renderers;
public class NoteRenderer(UserRenderer userRenderer, DatabaseContext db, EmojiService emojiSvc) public class NoteRenderer(
UserRenderer userRenderer,
DatabaseContext db,
EmojiService emojiSvc,
IOptions<Config.InstanceSection> config
)
{ {
public async Task<NoteResponse> RenderOne( public async Task<NoteResponse> RenderOne(
Note note, User? user, Filter.FilterContext? filterContext = null, NoteRendererDto? data = null Note note, User? user, Filter.FilterContext? filterContext = null, NoteRendererDto? data = null
@ -74,6 +81,8 @@ public class NoteRenderer(UserRenderer userRenderer, DatabaseContext db, EmojiSe
{ {
Id = note.Id, Id = note.Id,
CreatedAt = note.CreatedAt.ToStringIso8601Like(), CreatedAt = note.CreatedAt.ToStringIso8601Like(),
Uri = note.Uri ?? note.GetPublicUri(config.Value),
Url = note.Url ?? note.Uri ?? note.GetPublicUri(config.Value),
Text = note.Text, Text = note.Text,
Cw = note.Cw, Cw = note.Cw,
Visibility = (NoteVisibility)note.Visibility, Visibility = (NoteVisibility)note.Visibility,

View file

@ -32,6 +32,8 @@ public class NoteBase
{ {
public required string Id { get; set; } public required string Id { get; set; }
public required string CreatedAt { get; set; } public required string CreatedAt { get; set; }
public required string Uri { get; set; }
public required string Url { get; set; }
public required string? Text { get; set; } public required string? Text { get; set; }
public required string? Cw { get; set; } public required string? Cw { get; set; }
public required NoteVisibility Visibility { get; set; } public required NoteVisibility Visibility { get; set; }