[feature] Add token review / delete to backend + settings panel (#3845)

This commit is contained in:
tobi
2025-03-04 11:01:25 +01:00
committed by GitHub
parent ee60732cf7
commit 829143d263
25 changed files with 1637 additions and 1 deletions

View File

@ -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
}