Write on the margins of the internet. Powered by the AT Protocol.
margin.at
extension
web
atproto
comments
1package api
2
3import (
4 "context"
5 "encoding/json"
6 "net/http"
7
8 "margin.at/internal/xrpc"
9)
10
11func (h *Handler) SyncAll(w http.ResponseWriter, r *http.Request) {
12 session, err := h.refresher.GetSessionWithAutoRefresh(r)
13 if err != nil {
14 http.Error(w, err.Error(), http.StatusUnauthorized)
15 return
16 }
17
18 results, err := h.syncService.PerformSync(r.Context(), session.DID, func(ctx context.Context, did string) (*xrpc.Client, error) {
19 var client *xrpc.Client
20 err := h.refresher.ExecuteWithAutoRefresh(r, session, func(c *xrpc.Client, d string) error {
21 client = c
22 return nil
23 })
24 return client, err
25 })
26
27 if err != nil {
28 http.Error(w, "Sync failed: "+err.Error(), http.StatusInternalServerError)
29 return
30 }
31
32 w.WriteHeader(http.StatusOK)
33 json.NewEncoder(w).Encode(results)
34}