The attodo.app, uhh... app.

service worker fix 4, i think, again

+27 -2
+27 -2
internal/handlers/settings.go
··· 10 10 "strings" 11 11 "time" 12 12 13 + "github.com/bluesky-social/indigo/atproto/identity" 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 + // Resolve the actual PDS endpoint for this user (same as tasks does) 265 + pdsHost, err := h.resolvePDSEndpoint(ctx, sess.DID) 266 + if err != nil { 267 + return fmt.Errorf("failed to resolve PDS endpoint: %w", err) 268 + } 269 + log.Printf("createRecord: Resolved PDS=%s", pdsHost) 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 - // Create the request to the PDS endpoint 281 - url := fmt.Sprintf("%s/xrpc/com.atproto.repo.putRecord", sess.PDS) 289 + // Create the request to the resolved PDS endpoint 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 + 370 + // resolvePDSEndpoint resolves the PDS endpoint for a given DID 371 + func (h *SettingsHandler) resolvePDSEndpoint(ctx context.Context, did string) (string, error) { 372 + dir := identity.DefaultDirectory() 373 + atid, err := syntax.ParseAtIdentifier(did) 374 + if err != nil { 375 + return "", err 376 + } 377 + 378 + ident, err := dir.Lookup(ctx, *atid) 379 + if err != nil { 380 + return "", err 381 + } 382 + 383 + return ident.PDSEndpoint(), nil 384 + }