From 49e649068c146db77ada66a37d91891fc216c661 Mon Sep 17 00:00:00 2001 From: ewin Date: Mon, 3 Mar 2025 13:46:05 -0500 Subject: [PATCH] Add helpers to convert between API/internal StatusContentType --- internal/typeutils/frontendtointernal.go | 10 ++++++++++ internal/typeutils/internaltofrontend.go | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/internal/typeutils/frontendtointernal.go b/internal/typeutils/frontendtointernal.go index b341aa6ae..eb60c548e 100644 --- a/internal/typeutils/frontendtointernal.go +++ b/internal/typeutils/frontendtointernal.go @@ -44,6 +44,16 @@ func APIVisToVis(m apimodel.Visibility) gtsmodel.Visibility { return 0 } +func APIContentTypeToContentType(m apimodel.StatusContentType) gtsmodel.StatusContentType { + switch m { + case apimodel.StatusContentTypePlain: + return gtsmodel.StatusContentTypePlain + case apimodel.StatusContentTypeMarkdown: + return gtsmodel.StatusContentTypeMarkdown + } + return 0 +} + func APIMarkerNameToMarkerName(m apimodel.MarkerName) gtsmodel.MarkerName { switch m { case apimodel.MarkerNameHome: diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 510b165d1..465f4acf5 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -1626,6 +1626,17 @@ func (c *Converter) VisToAPIVis(ctx context.Context, m gtsmodel.Visibility) apim return "" } +// Converts a gts status content type into its api equivalent +func (c *Converter) ContentTypeToAPIContentType(ctx context.Context, m gtsmodel.StatusContentType) apimodel.StatusContentType { + switch m { + case gtsmodel.StatusContentTypePlain: + return apimodel.StatusContentTypePlain + case gtsmodel.StatusContentTypeMarkdown: + return apimodel.StatusContentTypeMarkdown + } + return "" +} + // InstanceRuleToAdminAPIRule converts a local instance rule into its api equivalent for serving at /api/v1/admin/instance/rules/:id func InstanceRuleToAPIRule(r gtsmodel.Rule) apimodel.InstanceRule { return apimodel.InstanceRule{