summaryrefslogtreecommitdiff
path: root/internal/processing
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/processing
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/processing')
-rw-r--r--internal/processing/account/account.go11
-rw-r--r--internal/processing/account/update.go11
-rw-r--r--internal/processing/instance.go30
3 files changed, 35 insertions, 17 deletions
diff --git a/internal/processing/account/account.go b/internal/processing/account/account.go
index d2c3cddbe..3eccbc27d 100644
--- a/internal/processing/account/account.go
+++ b/internal/processing/account/account.go
@@ -78,15 +78,14 @@ type Processor interface {
BlockCreate(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode)
// BlockRemove handles the removal of a block from requestingAccount to targetAccountID, either remote or local.
BlockRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode)
-
- // UpdateHeader does the dirty work of checking the header part of an account update form,
- // parsing and checking the image, and doing the necessary updates in the database for this to become
- // the account's new header image.
- UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error)
// UpdateAvatar does the dirty work of checking the avatar part of an account update form,
// parsing and checking the image, and doing the necessary updates in the database for this to become
// the account's new avatar image.
- UpdateHeader(ctx context.Context, header *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error)
+ UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error)
+ // UpdateHeader does the dirty work of checking the header part of an account update form,
+ // parsing and checking the image, and doing the necessary updates in the database for this to become
+ // the account's new header image.
+ UpdateHeader(ctx context.Context, header *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error)
}
type processor struct {
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 2ef3bfe25..bce82d6ca 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -100,7 +100,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
}
if form.Avatar != nil && form.Avatar.Size != 0 {
- avatarInfo, err := p.UpdateAvatar(ctx, form.Avatar, account.ID)
+ avatarInfo, err := p.UpdateAvatar(ctx, form.Avatar, nil, account.ID)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err)
}
@@ -110,7 +110,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
}
if form.Header != nil && form.Header.Size != 0 {
- headerInfo, err := p.UpdateHeader(ctx, form.Header, account.ID)
+ headerInfo, err := p.UpdateHeader(ctx, form.Header, nil, account.ID)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err)
}
@@ -186,7 +186,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
// UpdateAvatar does the dirty work of checking the avatar part of an account update form,
// parsing and checking the image, and doing the necessary updates in the database for this to become
// the account's new avatar image.
-func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error) {
+func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error) {
maxImageSize := config.GetMediaImageMaxSize()
if avatar.Size > int64(maxImageSize) {
return nil, fmt.Errorf("UpdateAvatar: avatar with size %d exceeded max image size of %d bytes", avatar.Size, maxImageSize)
@@ -199,7 +199,8 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
isAvatar := true
ai := &media.AdditionalMediaInfo{
- Avatar: &isAvatar,
+ Avatar: &isAvatar,
+ Description: description,
}
processingMedia, err := p.mediaManager.ProcessMedia(ctx, dataFunc, nil, accountID, ai)
@@ -213,7 +214,7 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
// UpdateHeader does the dirty work of checking the header part of an account update form,
// parsing and checking the image, and doing the necessary updates in the database for this to become
// the account's new header image.
-func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHeader, accountID string) (*gtsmodel.MediaAttachment, error) {
+func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error) {
maxImageSize := config.GetMediaImageMaxSize()
if header.Size > int64(maxImageSize) {
return nil, fmt.Errorf("UpdateHeader: header with size %d exceeded max image size of %d bytes", header.Size, maxImageSize)
diff --git a/internal/processing/instance.go b/internal/processing/instance.go
index 2d74fe181..1d7bdb377 100644
--- a/internal/processing/instance.go
+++ b/internal/processing/instance.go
@@ -208,24 +208,42 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
i.Terms = text.SanitizeHTML(*form.Terms) // html is OK in site terms, but we should sanitize it
}
- // process avatar if provided
+ var updateInstanceAccount bool
+
+ // process instance avatar if provided
if form.Avatar != nil && form.Avatar.Size != 0 {
- _, err := p.accountProcessor.UpdateAvatar(ctx, form.Avatar, ia.ID)
+ avatarInfo, err := p.accountProcessor.UpdateAvatar(ctx, form.Avatar, form.AvatarDescription, ia.ID)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err, "error processing avatar")
}
+ ia.AvatarMediaAttachmentID = avatarInfo.ID
+ ia.AvatarMediaAttachment = avatarInfo
+ updateInstanceAccount = true
}
- // process header if provided
+ // process instance header if provided
if form.Header != nil && form.Header.Size != 0 {
- _, err := p.accountProcessor.UpdateHeader(ctx, form.Header, ia.ID)
+ headerInfo, err := p.accountProcessor.UpdateHeader(ctx, form.Header, nil, ia.ID)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err, "error processing header")
}
+ ia.HeaderMediaAttachmentID = headerInfo.ID
+ ia.HeaderMediaAttachment = headerInfo
+ updateInstanceAccount = true
}
- if err := p.db.UpdateByID(ctx, i, i.ID, updatingColumns...); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error updating instance %s: %s", host, err))
+ if updateInstanceAccount {
+ // if either avatar or header is updated, we need
+ // to update the instance account that stores them
+ if _, err := p.db.UpdateAccount(ctx, ia); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error updating instance account: %s", err))
+ }
+ }
+
+ if len(updatingColumns) != 0 {
+ if err := p.db.UpdateByID(ctx, i, i.ID, updatingColumns...); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error updating instance %s: %s", host, err))
+ }
}
ai, err := p.tc.InstanceToAPIInstance(ctx, i)