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 3, i think, again
Steve Layton
3 months ago
3ea561c0
f83ec8b0
+16
-10
1 changed file
expand all
collapse all
unified
split
internal
handlers
settings.go
+16
-10
internal/handlers/settings.go
···
259
259
func (h *SettingsHandler) createRecord(ctx context.Context, sess *bskyoauth.Session, rkey string, record map[string]interface{}) error {
260
260
log.Printf("createRecord: DID=%s, Collection=%s, RKey=%s", sess.DID, SettingsCollection, rkey)
261
261
262
262
+
// Add $type field to the record if not present
262
263
if _, exists := record["$type"]; !exists {
263
264
record["$type"] = SettingsCollection
264
265
}
265
266
267
267
+
// Build the request body
266
268
body := map[string]interface{}{
267
269
"repo": sess.DID,
268
270
"collection": SettingsCollection,
···
275
277
return fmt.Errorf("failed to marshal request: %w", err)
276
278
}
277
279
280
280
+
// Create the request to the PDS endpoint
278
281
url := fmt.Sprintf("%s/xrpc/com.atproto.repo.putRecord", sess.PDS)
279
279
-
req, err := http.NewRequestWithContext(ctx, "POST", url, io.NopCloser(strings.NewReader(string(bodyJSON))))
282
282
+
req, err := http.NewRequestWithContext(ctx, "POST", url, strings.NewReader(string(bodyJSON)))
280
283
if err != nil {
281
284
return fmt.Errorf("failed to create request: %w", err)
282
285
}
283
286
284
287
req.Header.Set("Content-Type", "application/json")
285
285
-
// DPoP transport handles authorization automatically - do not set Authorization header manually
286
288
287
287
-
transport := bskyoauth.NewDPoPTransport(http.DefaultTransport, sess.DPoPKey, sess.AccessToken, sess.DPoPNonce)
288
288
-
client := &http.Client{
289
289
-
Transport: transport,
289
289
+
// Create DPoP transport for authentication - do NOT set Authorization header manually
290
290
+
dpopTransport := bskyoauth.NewDPoPTransport(
291
291
+
http.DefaultTransport,
292
292
+
sess.DPoPKey,
293
293
+
sess.AccessToken,
294
294
+
sess.DPoPNonce,
295
295
+
)
296
296
+
297
297
+
httpClient := &http.Client{
298
298
+
Transport: dpopTransport,
290
299
Timeout: 10 * time.Second,
291
300
}
292
301
293
293
-
resp, err := client.Do(req)
302
302
+
resp, err := httpClient.Do(req)
294
303
if err != nil {
295
304
return fmt.Errorf("failed to execute request: %w", err)
296
305
}
297
306
defer resp.Body.Close()
298
307
299
299
-
if dpopTransport, ok := transport.(bskyoauth.DPoPTransport); ok {
300
300
-
sess.DPoPNonce = dpopTransport.GetNonce()
301
301
-
}
302
302
-
303
308
if resp.StatusCode != http.StatusOK {
304
309
bodyBytes, _ := io.ReadAll(resp.Body)
310
310
+
log.Printf("createRecord: HTTP %d: %s", resp.StatusCode, string(bodyBytes))
305
311
return fmt.Errorf("XRPC ERROR %d: %s", resp.StatusCode, string(bodyBytes))
306
312
}
307
313