From 829143d2636d4c0d274bf2ab4559912f472a2bc4 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 4 Mar 2025 11:01:25 +0100 Subject: [feature] Add token review / delete to backend + settings panel (#3845) --- internal/typeutils/internaltofrontend.go | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'internal/typeutils') 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 +} -- cgit v1.2.3