Live video on the AT Protocol
79
fork

Configure Feed

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

at eli/fix-context-recursion 57 lines 1.5 kB view raw
1package spxrpc 2 3import ( 4 "fmt" 5 "net/http" 6 "strings" 7 8 "github.com/bluesky-social/indigo/xrpc" 9 "github.com/labstack/echo/v4" 10 "github.com/streamplace/oatproxy/pkg/oatproxy" 11 "go.opentelemetry.io/otel" 12 "stream.place/streamplace/pkg/log" 13) 14 15func (s *Server) HandleWildcard(c echo.Context) error { 16 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleWildcard") 17 defer span.End() 18 19 session, client := oatproxy.GetOAuthSession(ctx) 20 if session == nil { 21 return echo.NewHTTPError(http.StatusUnauthorized, "oauth session not found") 22 } 23 24 var out map[string]any 25 26 // Get the last path segment in the URL 27 path := c.Request().URL.Path 28 segments := strings.Split(path, "/") 29 lastSegment := segments[len(segments)-1] 30 31 var xrpcType string 32 var err error 33 if c.Request().Method == "GET" { 34 xrpcType = xrpc.Query 35 queryParams := make(map[string]any) 36 for k, v := range c.QueryParams() { 37 for _, vv := range v { 38 queryParams[k] = vv 39 } 40 } 41 err = client.Do(ctx, xrpcType, "application/json", lastSegment, queryParams, nil, &out) 42 } else { 43 xrpcType = xrpc.Procedure 44 var body map[string]any 45 if err := c.Bind(&body); err != nil { 46 return c.JSON(http.StatusBadRequest, xrpc.XRPCError{ErrStr: "BadRequest", Message: fmt.Sprintf("invalid body: %s", err)}) 47 } 48 err = client.Do(ctx, xrpcType, "application/json", lastSegment, nil, body, &out) 49 } 50 51 if err != nil { 52 log.Error(ctx, "upstream xrpc error", "error", err) 53 return err 54 } 55 56 return c.JSON(200, out) 57}