mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-29 19:52:24 -05:00 
			
		
		
		
	[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:
		
					parent
					
						
							
								eb25739c34
							
						
					
				
			
			
				commit
				
					
						b4f7316a4c
					
				
			
		
					 11 changed files with 183 additions and 57 deletions
				
			
		|  | @ -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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue