summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-01-05 13:20:33 +0100
committerLibravatar GitHub <noreply@github.com>2025-01-05 13:20:33 +0100
commite9bb7ddd3aa11da5c48a75c4a600f8fe5cc1c990 (patch)
treea2897775112a821aa093b6e2686044814912001f /internal/typeutils/internaltofrontend.go
parent[chore] Update robots.txt with more AI bots (#3634) (diff)
downloadgotosocial-e9bb7ddd3aa11da5c48a75c4a600f8fe5cc1c990.tar.xz
[feature] Create/update/remove domain permission subscriptions (#3623)
* [feature] Create/update/remove domain permission subscriptions * lint * envparsing * remove errant fmt.Println * create drafts, subs, exclude, from snapshot models * name etag column correctly * remove count column * lint
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r--internal/typeutils/internaltofrontend.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 0d5e15078..9fb69b438 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -36,6 +36,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/filter/usermute"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/language"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/media"
@@ -2130,6 +2131,60 @@ func (c *Converter) DomainPermToAPIDomainPerm(
return domainPerm, nil
}
+func (c *Converter) DomainPermSubToAPIDomainPermSub(
+ ctx context.Context,
+ d *gtsmodel.DomainPermissionSubscription,
+) (*apimodel.DomainPermissionSubscription, error) {
+ createdAt, err := id.TimeFromULID(d.ID)
+ if err != nil {
+ return nil, gtserror.Newf("error converting id to time: %w", err)
+ }
+
+ // URI may be in Punycode,
+ // de-punify it just in case.
+ uri, err := util.DePunify(d.URI)
+ if err != nil {
+ return nil, gtserror.Newf("error de-punifying URI %s: %w", d.URI, err)
+ }
+
+ var (
+ fetchedAt string
+ successfullyFetchedAt string
+ )
+
+ if !d.FetchedAt.IsZero() {
+ fetchedAt = util.FormatISO8601(d.FetchedAt)
+ }
+
+ if !d.SuccessfullyFetchedAt.IsZero() {
+ successfullyFetchedAt = util.FormatISO8601(d.SuccessfullyFetchedAt)
+ }
+
+ count, err := c.state.DB.CountDomainPermissionSubscriptionPerms(ctx, d.ID)
+ if err != nil {
+ return nil, gtserror.Newf("error counting perm sub perms: %w", err)
+ }
+
+ return &apimodel.DomainPermissionSubscription{
+ ID: d.ID,
+ Priority: d.Priority,
+ Title: d.Title,
+ PermissionType: d.PermissionType.String(),
+ AsDraft: *d.AsDraft,
+ AdoptOrphans: *d.AdoptOrphans,
+ CreatedBy: d.CreatedByAccountID,
+ CreatedAt: util.FormatISO8601(createdAt),
+ URI: uri,
+ ContentType: d.ContentType.String(),
+ FetchUsername: d.FetchUsername,
+ FetchPassword: d.FetchPassword,
+ FetchedAt: fetchedAt,
+ SuccessfullyFetchedAt: successfullyFetchedAt,
+ Error: d.Error,
+ Count: uint64(count), // #nosec G115 -- Don't care about overflow here.
+ }, nil
+}
+
// ReportToAPIReport converts a gts model report into an api model report, for serving at /api/v1/reports
func (c *Converter) ReportToAPIReport(ctx context.Context, r *gtsmodel.Report) (*apimodel.Report, error) {
report := &apimodel.Report{