[backend/federation] Federate alt text (ISH-55)

This commit is contained in:
Laura Hausmann 2024-02-13 03:01:58 +01:00
parent 8c015815bc
commit b67dd173f4
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
5 changed files with 12 additions and 5 deletions

View file

@ -72,7 +72,6 @@ public class DriveFile : IEntity {
/// The comment of the DriveFile.
/// </summary>
[Column("comment")]
[StringLength(8192)]
public string? Comment { get; set; }
/// <summary>

View file

@ -56,7 +56,8 @@ public class NoteRenderer(IOptions<Config.InstanceSection> config, MfmConverter
Type = $"{Constants.ActivityStreamsNs}#Document",
Sensitive = p.IsSensitive,
Url = new ASObjectBase(p.Url),
MediaType = p.Type
MediaType = p.Type,
Description = p.Comment
})
.Cast<ASAttachment>()
.ToListAsync()

View file

@ -24,6 +24,10 @@ public class ASDocument : ASAttachment {
[J("https://www.w3.org/ns/activitystreams#sensitive")]
[JC(typeof(ValueObjectConverter))]
public bool? Sensitive { get; set; }
[J("https://www.w3.org/ns/activitystreams#name")]
[JC(typeof(ValueObjectConverter))]
public string? Description { get; set; }
}
public sealed class ASAttachmentConverter : JsonConverter {

View file

@ -23,7 +23,9 @@ public class DriveService(
QueueService queueSvc,
ILogger<DriveService> logger
) {
public async Task<DriveFile?> StoreFile(string? uri, User user, bool sensitive) {
public async Task<DriveFile?> StoreFile(
string? uri, User user, bool sensitive, string? description = null, string? mimeType = null
) {
if (uri == null) return null;
logger.LogDebug("Storing file {uri} for user {userId}", uri, user.Id);
@ -63,7 +65,8 @@ public class DriveService(
Uri = uri,
Filename = new Uri(uri).AbsolutePath.Split('/').LastOrDefault() ?? "",
IsSensitive = sensitive,
MimeType = CleanMimeType(res.Content.Headers.ContentType?.MediaType)
Comment = description,
MimeType = CleanMimeType(mimeType ?? res.Content.Headers.ContentType?.MediaType)
};
return await StoreFile(await res.Content.ReadAsStreamAsync(), user, request);

View file

@ -283,7 +283,7 @@ public class NoteService(
if (attachments is not { Count: > 0 }) return [];
var result = await attachments
.OfType<ASDocument>()
.Select(p => driveSvc.StoreFile(p.Url?.Id, user, p.Sensitive ?? sensitive))
.Select(p => driveSvc.StoreFile(p.Url?.Id, user, p.Sensitive ?? sensitive, p.Description, p.MediaType))
.AwaitAllNoConcurrencyAsync();
return result.Where(p => p != null).Cast<DriveFile>().ToList();