BYOK Personal Data Server (PDS) written in Go
ipfs vow atproto pds go
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: update getRecord to proxy directly to app view.

Inspired from https://bsky.app/profile/threddyrex.org/post/3mi55ce3ojk26

+35 -2
+35 -2
server/handle_repo_get_record.go
··· 1 1 package server 2 2 3 3 import ( 4 + "fmt" 5 + "io" 4 6 "net/http" 7 + "strings" 5 8 6 9 "github.com/bluesky-social/indigo/atproto/atdata" 7 10 "github.com/bluesky-social/indigo/atproto/syntax" 11 + "pkg.rbrt.fr/vow/internal/helpers" 8 12 "pkg.rbrt.fr/vow/models" 9 13 ) 10 14 ··· 43 47 44 48 val, err := atdata.UnmarshalCBOR(record.Value) 45 49 if err != nil { 46 - // Fall back to proxy if we can't find/decode the record locally 47 - s.handleProxy(w, r) 50 + s.proxyToAppView(w, r) 48 51 return 49 52 } 50 53 ··· 54 57 Value: val, 55 58 }) 56 59 } 60 + 61 + func (s *Server) proxyToAppView(w http.ResponseWriter, r *http.Request) { 62 + endpoint, _, err := s.getAtprotoProxyEndpointFromRequest(r) 63 + if err != nil { 64 + s.logger.Error("could not get appview endpoint", "error", err) 65 + helpers.ServerError(w, nil) 66 + return 67 + } 68 + 69 + targetURL := fmt.Sprintf("%s%s?%s", strings.TrimSuffix(endpoint, "/"), r.URL.Path, r.URL.RawQuery) 70 + 71 + req, err := http.NewRequest(http.MethodGet, targetURL, nil) 72 + if err != nil { 73 + helpers.ServerError(w, nil) 74 + return 75 + } 76 + 77 + resp, err := http.DefaultClient.Do(req) 78 + if err != nil { 79 + helpers.ServerError(w, nil) 80 + return 81 + } 82 + defer func() { _ = resp.Body.Close() }() 83 + 84 + for k, v := range resp.Header { 85 + w.Header()[k] = v 86 + } 87 + w.WriteHeader(resp.StatusCode) 88 + _, _ = io.Copy(w, resp.Body) 89 + }