From 4c3a140e9f445689546d8c118611d3c0aa5c2913 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 1 Mar 2024 18:41:49 +0100 Subject: [PATCH] [backend/masto-client] Fix public media url handling --- .../Mastodon/Renderers/NoteRenderer.cs | 23 ++++--------------- .../Core/Database/Tables/DriveFile.cs | 3 +++ .../Core/Services/DriveService.cs | 7 ------ 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs b/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs index 5dbb81c1..4fee085b 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/Renderers/NoteRenderer.cs @@ -43,26 +43,11 @@ public class NoteRenderer( var noteEmoji = data?.Emoji?.Where(p => note.Emojis.Contains(p.Id)).ToList() ?? await GetEmoji([note]); var mentions = data?.Mentions == null - ? await db.Users.IncludeCommonProperties() - .Where(p => note.Mentions.Contains(p.Id)) - .Select(u => new MentionEntity(u, config.Value.WebDomain)) - .ToListAsync() + ? await GetMentions([note]) : [..data.Mentions.Where(p => note.Mentions.Contains(p.Id))]; var attachments = data?.Attachments == null - ? await db.DriveFiles.Where(p => note.FileIds.Contains(p.Id)) - .Select(f => new AttachmentEntity - { - Id = f.Id, - Url = f.WebpublicUrl ?? f.Url, - Blurhash = f.Blurhash, - PreviewUrl = f.ThumbnailUrl, - Description = f.Comment, - Metadata = null, - RemoteUrl = f.Uri, - Type = AttachmentEntity.GetType(f.Type) - }) - .ToListAsync() + ? await GetAttachments([note]) : [..data.Attachments.Where(p => note.FileIds.Contains(p.Id))]; @@ -132,9 +117,9 @@ public class NoteRenderer( .Select(f => new AttachmentEntity { Id = f.Id, - Url = f.Url, + Url = f.PublicUrl, Blurhash = f.Blurhash, - PreviewUrl = f.ThumbnailUrl, + PreviewUrl = f.PublicThumbnailUrl, Description = f.Comment, Metadata = null, RemoteUrl = f.Uri, diff --git a/Iceshrimp.Backend/Core/Database/Tables/DriveFile.cs b/Iceshrimp.Backend/Core/Database/Tables/DriveFile.cs index b488df74..76837def 100644 --- a/Iceshrimp.Backend/Core/Database/Tables/DriveFile.cs +++ b/Iceshrimp.Backend/Core/Database/Tables/DriveFile.cs @@ -189,6 +189,9 @@ public class DriveFile : IEntity [StringLength(32)] public string Id { get; set; } = null!; + [NotMapped] public string PublicUrl => WebpublicUrl ?? Url; + [NotMapped] public string PublicThumbnailUrl => ThumbnailUrl ?? WebpublicUrl ?? Url; + public class FileProperties { [J("width")] public int? Width { get; set; } diff --git a/Iceshrimp.Backend/Core/Services/DriveService.cs b/Iceshrimp.Backend/Core/Services/DriveService.cs index 397bc451..d79febc9 100644 --- a/Iceshrimp.Backend/Core/Services/DriveService.cs +++ b/Iceshrimp.Backend/Core/Services/DriveService.cs @@ -296,13 +296,6 @@ public class DriveService( await queueSvc.BackgroundTaskQueue.EnqueueAsync(job); } - public string GetPublicUrl(DriveFile file, bool thumbnail) - { - return thumbnail - ? file.ThumbnailUrl ?? file.WebpublicUrl ?? file.Url - : file.WebpublicUrl ?? file.Url; - } - private static string GenerateFilenameKeepingExtension(string filename) { var guid = Guid.NewGuid().ToString().ToLowerInvariant();