summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-11-08 18:11:06 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-08 17:11:06 +0000
commitb4f7316a4cdf5ee2b43118aa6133a84a7ae4a5df (patch)
tree1ffa65108351843bbb92c8a245c5345cff88c61a /internal/typeutils
parent[frontend] Custom Emoji Deletion (#994) (diff)
downloadgotosocial-b4f7316a4cdf5ee2b43118aa6133a84a7ae4a5df.tar.xz
[feature] Make instance thumbnail configurable via admin panel (#973)
* [feature] Make instance thumbnail configurable via admin panel * log db errors in InstanceToAPIInstance * only update instance in db if necessary * start adding tests * finish test
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/internaltofrontend.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 7b4c3e8cc..e22813549 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -20,6 +20,7 @@ package typeutils
import (
"context"
+ "errors"
"fmt"
"strings"
@@ -665,12 +666,25 @@ func (c *converter) InstanceToAPIInstance(ctx context.Context, i *gtsmodel.Insta
mi.AccountDomain = config.GetAccountDomain()
if ia, err := c.db.GetInstanceAccount(ctx, ""); err == nil {
- if ia.HeaderMediaAttachment != nil {
- // take instance account header as instance thumbnail
- mi.Thumbnail = ia.HeaderMediaAttachment.URL
- } else {
- // or just use a default
- mi.Thumbnail = config.GetProtocol() + "://" + host + "/assets/logo.png"
+ // assume default logo
+ mi.Thumbnail = config.GetProtocol() + "://" + host + "/assets/logo.png"
+
+ // take instance account avatar as instance thumbnail if we can
+ if ia.AvatarMediaAttachmentID != "" {
+ if ia.AvatarMediaAttachment == nil {
+ avi, err := c.db.GetAttachmentByID(ctx, ia.AvatarMediaAttachmentID)
+ if err == nil {
+ ia.AvatarMediaAttachment = avi
+ } else if !errors.Is(err, db.ErrNoEntries) {
+ log.Errorf("InstanceToAPIInstance: error getting instance avatar attachment with id %s: %s", ia.AvatarMediaAttachmentID, err)
+ }
+ }
+
+ if ia.AvatarMediaAttachment != nil {
+ mi.Thumbnail = ia.AvatarMediaAttachment.URL
+ mi.ThumbnailType = ia.AvatarMediaAttachment.File.ContentType
+ mi.ThumbnailDescription = ia.AvatarMediaAttachment.Description
+ }
}
}