From b4f7316a4cdf5ee2b43118aa6133a84a7ae4a5df Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 8 Nov 2022 18:11:06 +0100 Subject: [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 --- internal/processing/instance.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'internal/processing/instance.go') 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) -- cgit v1.2.3