summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r--internal/typeutils/internaltofrontend.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 510b165d1..8bd92512a 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -3068,3 +3068,39 @@ func (c *Converter) WebPushSubscriptionToAPIWebPushSubscription(
Standard: true,
}, nil
}
+
+func (c *Converter) TokenToAPITokenInfo(
+ ctx context.Context,
+ token *gtsmodel.Token,
+) (*apimodel.TokenInfo, error) {
+ createdAt, err := id.TimeFromULID(token.ID)
+ if err != nil {
+ err := gtserror.Newf("error parsing time from token id: %w", err)
+ return nil, err
+ }
+
+ var lastUsed string
+ if !token.LastUsed.IsZero() {
+ lastUsed = util.FormatISO8601(token.LastUsed)
+ }
+
+ application, err := c.state.DB.GetApplicationByClientID(ctx, token.ClientID)
+ if err != nil {
+ err := gtserror.Newf("db error getting application with client id %s: %w", token.ClientID, err)
+ return nil, err
+ }
+
+ apiApplication, err := c.AppToAPIAppPublic(ctx, application)
+ if err != nil {
+ err := gtserror.Newf("error converting application to api application: %w", err)
+ return nil, err
+ }
+
+ return &apimodel.TokenInfo{
+ ID: token.ID,
+ CreatedAt: util.FormatISO8601(createdAt),
+ LastUsed: lastUsed,
+ Scope: token.Scope,
+ Application: apiApplication,
+ }, nil
+}