feat(sync): paginate Android sync with change tokens
Lint / Lint (push) Successful in 1m8s
Tests / Go backend (push) Failing after 1m23s
Tests / Dashboard checks (push) Failing after 38s
Docker / Docker Build & Push (push) Failing after 6m29s

This commit is contained in:
Gabriel20xx committed 2026-10-20 15:27:53 +00:00
1 parent 0ff94f9b10
commit 97c237be80
76 files changed
+3401 -851

No files matched your search

+20
View File
@@ -71,6 +71,7 @@ type Client struct {
projectKey string
validationMu sync.Mutex
validationCache map[[32]byte]validationCacheEntry
profileCache map[[32]byte]profileCacheEntry
}
// ProjectKeyHeader is the header Client attaches to every request identifying
@@ -118,6 +119,7 @@ func New(baseURL string, opts ...Option) *Client {
httpClient: &http.Client{Timeout: 5 * time.Second},
cookieName: DefaultCookieName,
validationCache: make(map[[32]byte]validationCacheEntry),
profileCache: make(map[[32]byte]profileCacheEntry),
}
for _, opt := range opts {
opt(c)
@@ -583,12 +585,24 @@ func (c *Client) Logout(ctx context.Context, token string) ([]*http.Cookie, erro
// Me calls GET /api/me, resolving token to its account.
func (c *Client) Me(ctx context.Context, token string) (*PublicUser, error) {
token = strings.TrimSpace(token)
if token == "" {
return nil, ErrInvalidSession
}
if profile, ok := c.cachedProfile(token); ok {
return profile, nil
}
var out struct {
User PublicUser `json:"user"`
}
if _, err := c.call(ctx, http.MethodGet, "/api/me", token, nil, &out); err != nil {
var apiErr *APIError
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusUnauthorized {
c.invalidateValidation(token)
}
return nil, err
}
c.cacheProfile(token, &out.User)
return &out.User, nil
}
@@ -607,6 +621,9 @@ func (c *Client) TOTPEnable(ctx context.Context, token string) (*TOTPEnableResul
// pending secret TOTPEnable provisioned and activating two-factor auth.
func (c *Client) TOTPVerify(ctx context.Context, token, code string) error {
_, err := c.call(ctx, http.MethodPost, "/api/totp/verify", token, map[string]string{"token": code}, nil)
if err == nil {
c.invalidateValidation(token)
}
return err
}
@@ -615,6 +632,9 @@ func (c *Client) TOTPVerify(ctx context.Context, token, code string) error {
// as proof of possession.
func (c *Client) TOTPDisable(ctx context.Context, token, code string) error {
_, err := c.call(ctx, http.MethodPost, "/api/totp/disable", token, map[string]string{"token": code}, nil)
if err == nil {
c.invalidateValidation(token)
}
return err
}