summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-07-22 12:48:19 +0200
committerLibravatar GitHub <noreply@github.com>2022-07-22 12:48:19 +0200
commit73b8839c5d1b481d1aa1330cd8c206a9f2213333 (patch)
tree877525e40448effbc37d31fdc4f6cbef23263ee8 /internal/typeutils/internaltofrontend.go
parent[bugfix] update go-cache library to fix critical bug during cache sweep sched... (diff)
downloadgotosocial-73b8839c5d1b481d1aa1330cd8c206a9f2213333.tar.xz
[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
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r--internal/typeutils/internaltofrontend.go41
1 files changed, 30 insertions, 11 deletions
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) {