diff options
| author | 2025-03-03 16:03:36 +0100 | |
|---|---|---|
| committer | 2025-03-03 15:03:36 +0000 | |
| commit | 1b37944f8b8eccc2afcfb0f603786209a3b7402d (patch) | |
| tree | 2bc0be27cf0405e16ac3e14efc3b6973eb096b8b /internal/db/bundb/application.go | |
| parent | bumps go-ffmpreg to v0.6.6 (#3866) (diff) | |
| download | gotosocial-1b37944f8b8eccc2afcfb0f603786209a3b7402d.tar.xz | |
[feature] Refactor tokens, allow multiple app redirect_uris (#3849)
* [feature] Refactor tokens, allow multiple app redirect_uris
* move + tweak handlers a bit
* return error for unset oauth2.ClientStore funcs
* wrap UpdateToken with cache
* panic handling
* cheeky little time optimization
* unlock on error
Diffstat (limited to 'internal/db/bundb/application.go')
| -rw-r--r-- | internal/db/bundb/application.go | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/internal/db/bundb/application.go b/internal/db/bundb/application.go index 92fc5ea2b..d94c984d0 100644 --- a/internal/db/bundb/application.go +++ b/internal/db/bundb/application.go @@ -97,41 +97,6 @@ func (a *applicationDB) DeleteApplicationByClientID(ctx context.Context, clientI return nil } -func (a *applicationDB) GetClientByID(ctx context.Context, id string) (*gtsmodel.Client, error) { - return a.state.Caches.DB.Client.LoadOne("ID", func() (*gtsmodel.Client, error) { - var client gtsmodel.Client - - if err := a.db.NewSelect(). - Model(&client). - Where("? = ?", bun.Ident("id"), id). - Scan(ctx); err != nil { - return nil, err - } - - return &client, nil - }, id) -} - -func (a *applicationDB) PutClient(ctx context.Context, client *gtsmodel.Client) error { - return a.state.Caches.DB.Client.Store(client, func() error { - _, err := a.db.NewInsert().Model(client).Exec(ctx) - return err - }) -} - -func (a *applicationDB) DeleteClientByID(ctx context.Context, id string) error { - _, err := a.db.NewDelete(). - Table("clients"). - Where("? = ?", bun.Ident("id"), id). - Exec(ctx) - if err != nil { - return err - } - - a.state.Caches.DB.Client.Invalidate("ID", id) - return nil -} - func (a *applicationDB) GetAllTokens(ctx context.Context) ([]*gtsmodel.Token, error) { var tokenIDs []string @@ -233,6 +198,18 @@ func (a *applicationDB) PutToken(ctx context.Context, token *gtsmodel.Token) err }) } +func (a *applicationDB) UpdateToken(ctx context.Context, token *gtsmodel.Token, columns ...string) error { + return a.state.Caches.DB.Token.Store(token, func() error { + _, err := a.db. + NewUpdate(). + Model(token). + Column(columns...). + Where("? = ?", bun.Ident("id"), token.ID). + Exec(ctx) + return err + }) +} + func (a *applicationDB) DeleteTokenByID(ctx context.Context, id string) error { _, err := a.db.NewDelete(). Table("tokens"). |
