[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
This commit is contained in:
tobi
2022-11-08 18:11:06 +01:00
committed by GitHub
parent eb25739c34
commit b4f7316a4c
11 changed files with 183 additions and 57 deletions

View File

@ -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
}
}
}