Don't pass processContentType the entire edit form, it doesn't need it

This commit is contained in:
ewin 2025-03-06 09:49:37 -05:00
commit 3050c2930a
No known key found for this signature in database

View file

@ -86,7 +86,7 @@ func (p *Processor) Edit(
} }
// Process incoming content type // Process incoming content type
contentType := processContentType(form, status, requester.Settings.StatusContentType) contentType := processContentType(form.ContentType, status, requester.Settings.StatusContentType)
// Process incoming status edit content fields. // Process incoming status edit content fields.
content, errWithCode := p.processContent(ctx, content, errWithCode := p.processContent(ctx,
@ -348,21 +348,21 @@ func (p *Processor) Edit(
return p.c.GetAPIStatus(ctx, requester, status) return p.c.GetAPIStatus(ctx, requester, status)
} }
// Returns the new content type of the status when applying an edit. // Returns the final content type to use when creating or editing a status.
func processContentType( func processContentType(
form *apimodel.StatusEditRequest, requestContentType apimodel.StatusContentType,
status *gtsmodel.Status, existingStatus *gtsmodel.Status,
accountDefaultContentType string, accountDefaultContentType string,
) gtsmodel.StatusContentType { ) gtsmodel.StatusContentType {
switch { switch {
// Content type set on form, return the new value. // Content type set in the request, return the new value.
case form.ContentType != "": case requestContentType != "":
return typeutils.APIContentTypeToContentType(form.ContentType) return typeutils.APIContentTypeToContentType(requestContentType)
// No content type on the form, return the existing // No content type in the request, return the existing
// status's current content type if there is one. // status's current content type if we know of one.
case status != nil && status.ContentType != 0: case existingStatus != nil && existingStatus.ContentType != 0:
return status.ContentType return existingStatus.ContentType
// We aren't editing an existing status, or if we are // We aren't editing an existing status, or if we are
// it's an old one that doesn't have a saved content // it's an old one that doesn't have a saved content