From 73b8839c5d1b481d1aa1330cd8c206a9f2213333 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 22 Jul 2022 12:48:19 +0200 Subject: [bugfix] Make `/api/v2/media` more compatible with masto API (#724) * update docs * make api version into a path param * update tests * workaround to unset URL if using v2 of api * make some fields into pointers --- internal/typeutils/internaltofrontend.go | 41 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'internal/typeutils/internaltofrontend.go') diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 1ac49688a..81dfaf9dd 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -233,14 +233,11 @@ func (c *converter) AppToAPIAppPublic(ctx context.Context, a *gtsmodel.Applicati } func (c *converter) AttachmentToAPIAttachment(ctx context.Context, a *gtsmodel.MediaAttachment) (model.Attachment, error) { - return model.Attachment{ - ID: a.ID, - Type: strings.ToLower(string(a.Type)), - URL: a.URL, - TextURL: a.URL, - PreviewURL: a.Thumbnail.URL, - RemoteURL: a.RemoteURL, - PreviewRemoteURL: a.Thumbnail.RemoteURL, + apiAttachment := model.Attachment{ + ID: a.ID, + Type: strings.ToLower(string(a.Type)), + TextURL: a.URL, + PreviewURL: a.Thumbnail.URL, Meta: model.MediaMeta{ Original: model.MediaDimensions{ Width: a.FileMeta.Original.Width, @@ -259,9 +256,31 @@ func (c *converter) AttachmentToAPIAttachment(ctx context.Context, a *gtsmodel.M Y: a.FileMeta.Focus.Y, }, }, - Description: a.Description, - Blurhash: a.Blurhash, - }, nil + Blurhash: a.Blurhash, + } + + // nullable fields + if a.URL != "" { + i := a.URL + apiAttachment.URL = &i + } + + if a.RemoteURL != "" { + i := a.RemoteURL + apiAttachment.RemoteURL = &i + } + + if a.Thumbnail.RemoteURL != "" { + i := a.Thumbnail.RemoteURL + apiAttachment.PreviewRemoteURL = &i + } + + if a.Description != "" { + i := a.Description + apiAttachment.Description = &i + } + + return apiAttachment, nil } func (c *converter) MentionToAPIMention(ctx context.Context, m *gtsmodel.Mention) (model.Mention, error) { -- cgit v1.2.3