tangled
alpha
login
or
join now
shindakun.net
/
attodo.app
3
fork
atom
The attodo.app, uhh... app.
3
fork
atom
overview
issues
pulls
pipelines
service worker fix 4, i think, again
Steve Layton
3 months ago
a5e6eeaf
3ea561c0
+27
-2
1 changed file
expand all
collapse all
unified
split
internal
handlers
settings.go
+27
-2
internal/handlers/settings.go
···
10
10
"strings"
11
11
"time"
12
12
13
13
+
"github.com/bluesky-social/indigo/atproto/identity"
14
14
+
"github.com/bluesky-social/indigo/atproto/syntax"
13
15
"github.com/shindakun/attodo/internal/models"
14
16
"github.com/shindakun/attodo/internal/session"
15
17
"github.com/shindakun/bskyoauth"
···
259
261
func (h *SettingsHandler) createRecord(ctx context.Context, sess *bskyoauth.Session, rkey string, record map[string]interface{}) error {
260
262
log.Printf("createRecord: DID=%s, Collection=%s, RKey=%s", sess.DID, SettingsCollection, rkey)
261
263
264
264
+
// Resolve the actual PDS endpoint for this user (same as tasks does)
265
265
+
pdsHost, err := h.resolvePDSEndpoint(ctx, sess.DID)
266
266
+
if err != nil {
267
267
+
return fmt.Errorf("failed to resolve PDS endpoint: %w", err)
268
268
+
}
269
269
+
log.Printf("createRecord: Resolved PDS=%s", pdsHost)
270
270
+
262
271
// Add $type field to the record if not present
263
272
if _, exists := record["$type"]; !exists {
264
273
record["$type"] = SettingsCollection
···
277
286
return fmt.Errorf("failed to marshal request: %w", err)
278
287
}
279
288
280
280
-
// Create the request to the PDS endpoint
281
281
-
url := fmt.Sprintf("%s/xrpc/com.atproto.repo.putRecord", sess.PDS)
289
289
+
// Create the request to the resolved PDS endpoint
290
290
+
url := fmt.Sprintf("%s/xrpc/com.atproto.repo.putRecord", pdsHost)
282
291
req, err := http.NewRequestWithContext(ctx, "POST", url, strings.NewReader(string(bodyJSON)))
283
292
if err != nil {
284
293
return fmt.Errorf("failed to create request: %w", err)
···
357
366
358
367
return sess, fmt.Errorf("max retries exceeded, last error: %w", lastErr)
359
368
}
369
369
+
370
370
+
// resolvePDSEndpoint resolves the PDS endpoint for a given DID
371
371
+
func (h *SettingsHandler) resolvePDSEndpoint(ctx context.Context, did string) (string, error) {
372
372
+
dir := identity.DefaultDirectory()
373
373
+
atid, err := syntax.ParseAtIdentifier(did)
374
374
+
if err != nil {
375
375
+
return "", err
376
376
+
}
377
377
+
378
378
+
ident, err := dir.Lookup(ctx, *atid)
379
379
+
if err != nil {
380
380
+
return "", err
381
381
+
}
382
382
+
383
383
+
return ident.PDSEndpoint(), nil
384
384
+
}