Live video on the AT Protocol
1package spxrpc
2
3import (
4 "io"
5 "strconv"
6
7 comatprototypes "github.com/bluesky-social/indigo/api/atproto"
8 appbskytypes "github.com/bluesky-social/indigo/api/bsky"
9 "github.com/labstack/echo/v4"
10 "go.opentelemetry.io/otel"
11 placestreamtypes "stream.place/streamplace/pkg/streamplace"
12)
13
14func (s *Server) RegisterHandlersAppBsky(e *echo.Echo) error {
15 e.GET("/xrpc/app.bsky.actor.getProfile", s.HandleAppBskyActorGetProfile)
16 e.GET("/xrpc/app.bsky.feed.getFeedSkeleton", s.HandleAppBskyFeedGetFeedSkeleton)
17 return nil
18}
19
20func (s *Server) HandleAppBskyActorGetProfile(c echo.Context) error {
21 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyActorGetProfile")
22 defer span.End()
23 actor := c.QueryParam("actor")
24 var out *appbskytypes.ActorDefs_ProfileViewDetailed
25 var handleErr error
26 // func (s *Server) handleAppBskyActorGetProfile(ctx context.Context,actor string) (*appbskytypes.ActorDefs_ProfileViewDetailed, error)
27 out, handleErr = s.handleAppBskyActorGetProfile(ctx, actor)
28 if handleErr != nil {
29 return handleErr
30 }
31 return c.JSON(200, out)
32}
33
34func (s *Server) HandleAppBskyFeedGetFeedSkeleton(c echo.Context) error {
35 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedGetFeedSkeleton")
36 defer span.End()
37 cursor := c.QueryParam("cursor")
38 feed := c.QueryParam("feed")
39
40 var limit int
41 if p := c.QueryParam("limit"); p != "" {
42 var err error
43 limit, err = strconv.Atoi(p)
44 if err != nil {
45 return err
46 }
47 } else {
48 limit = 50
49 }
50 var out *appbskytypes.FeedGetFeedSkeleton_Output
51 var handleErr error
52 // func (s *Server) handleAppBskyFeedGetFeedSkeleton(ctx context.Context,cursor string,feed string,limit int) (*appbskytypes.FeedGetFeedSkeleton_Output, error)
53 out, handleErr = s.handleAppBskyFeedGetFeedSkeleton(ctx, cursor, feed, limit)
54 if handleErr != nil {
55 return handleErr
56 }
57 return c.JSON(200, out)
58}
59
60func (s *Server) RegisterHandlersChatBsky(e *echo.Echo) error {
61 return nil
62}
63
64func (s *Server) RegisterHandlersComAtproto(e *echo.Echo) error {
65 e.GET("/xrpc/com.atproto.identity.resolveHandle", s.HandleComAtprotoIdentityResolveHandle)
66 e.POST("/xrpc/com.atproto.moderation.createReport", s.HandleComAtprotoModerationCreateReport)
67 e.GET("/xrpc/com.atproto.repo.describeRepo", s.HandleComAtprotoRepoDescribeRepo)
68 e.GET("/xrpc/com.atproto.repo.getRecord", s.HandleComAtprotoRepoGetRecord)
69 e.GET("/xrpc/com.atproto.repo.listRecords", s.HandleComAtprotoRepoListRecords)
70 e.POST("/xrpc/com.atproto.repo.uploadBlob", s.HandleComAtprotoRepoUploadBlob)
71 e.GET("/xrpc/com.atproto.server.describeServer", s.HandleComAtprotoServerDescribeServer)
72 e.GET("/xrpc/com.atproto.sync.getRecord", s.HandleComAtprotoSyncGetRecord)
73 e.GET("/xrpc/com.atproto.sync.listRepos", s.HandleComAtprotoSyncListRepos)
74 return nil
75}
76
77func (s *Server) HandleComAtprotoIdentityResolveHandle(c echo.Context) error {
78 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoIdentityResolveHandle")
79 defer span.End()
80 handle := c.QueryParam("handle")
81 var out *comatprototypes.IdentityResolveHandle_Output
82 var handleErr error
83 // func (s *Server) handleComAtprotoIdentityResolveHandle(ctx context.Context,handle string) (*comatprototypes.IdentityResolveHandle_Output, error)
84 out, handleErr = s.handleComAtprotoIdentityResolveHandle(ctx, handle)
85 if handleErr != nil {
86 return handleErr
87 }
88 return c.JSON(200, out)
89}
90
91func (s *Server) HandleComAtprotoModerationCreateReport(c echo.Context) error {
92 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoModerationCreateReport")
93 defer span.End()
94
95 var body comatprototypes.ModerationCreateReport_Input
96 if err := c.Bind(&body); err != nil {
97 return err
98 }
99 var out *comatprototypes.ModerationCreateReport_Output
100 var handleErr error
101 // func (s *Server) handleComAtprotoModerationCreateReport(ctx context.Context,body *comatprototypes.ModerationCreateReport_Input) (*comatprototypes.ModerationCreateReport_Output, error)
102 out, handleErr = s.handleComAtprotoModerationCreateReport(ctx, &body)
103 if handleErr != nil {
104 return handleErr
105 }
106 return c.JSON(200, out)
107}
108
109func (s *Server) HandleComAtprotoRepoDescribeRepo(c echo.Context) error {
110 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoDescribeRepo")
111 defer span.End()
112 repo := c.QueryParam("repo")
113 var out *comatprototypes.RepoDescribeRepo_Output
114 var handleErr error
115 // func (s *Server) handleComAtprotoRepoDescribeRepo(ctx context.Context,repo string) (*comatprototypes.RepoDescribeRepo_Output, error)
116 out, handleErr = s.handleComAtprotoRepoDescribeRepo(ctx, repo)
117 if handleErr != nil {
118 return handleErr
119 }
120 return c.JSON(200, out)
121}
122
123func (s *Server) HandleComAtprotoRepoGetRecord(c echo.Context) error {
124 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoGetRecord")
125 defer span.End()
126 cid := c.QueryParam("cid")
127 collection := c.QueryParam("collection")
128 repo := c.QueryParam("repo")
129 rkey := c.QueryParam("rkey")
130 var out *comatprototypes.RepoGetRecord_Output
131 var handleErr error
132 // func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context,cid string,collection string,repo string,rkey string) (*comatprototypes.RepoGetRecord_Output, error)
133 out, handleErr = s.handleComAtprotoRepoGetRecord(ctx, cid, collection, repo, rkey)
134 if handleErr != nil {
135 return handleErr
136 }
137 return c.JSON(200, out)
138}
139
140func (s *Server) HandleComAtprotoRepoListRecords(c echo.Context) error {
141 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoListRecords")
142 defer span.End()
143 collection := c.QueryParam("collection")
144 cursor := c.QueryParam("cursor")
145
146 var limit int
147 if p := c.QueryParam("limit"); p != "" {
148 var err error
149 limit, err = strconv.Atoi(p)
150 if err != nil {
151 return err
152 }
153 } else {
154 limit = 50
155 }
156 repo := c.QueryParam("repo")
157
158 var reverse *bool
159 if p := c.QueryParam("reverse"); p != "" {
160 reverse_val, err := strconv.ParseBool(p)
161 if err != nil {
162 return err
163 }
164 reverse = &reverse_val
165 }
166 var out *comatprototypes.RepoListRecords_Output
167 var handleErr error
168 // func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context,collection string,cursor string,limit int,repo string,reverse *bool) (*comatprototypes.RepoListRecords_Output, error)
169 out, handleErr = s.handleComAtprotoRepoListRecords(ctx, collection, cursor, limit, repo, reverse)
170 if handleErr != nil {
171 return handleErr
172 }
173 return c.JSON(200, out)
174}
175
176func (s *Server) HandleComAtprotoRepoUploadBlob(c echo.Context) error {
177 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoUploadBlob")
178 defer span.End()
179 body := c.Request().Body
180 contentType := c.Request().Header.Get("Content-Type")
181 var out *comatprototypes.RepoUploadBlob_Output
182 var handleErr error
183 // func (s *Server) handleComAtprotoRepoUploadBlob(ctx context.Context,r io.Reader,contentType string) (*comatprototypes.RepoUploadBlob_Output, error)
184 out, handleErr = s.handleComAtprotoRepoUploadBlob(ctx, body, contentType)
185 if handleErr != nil {
186 return handleErr
187 }
188 return c.JSON(200, out)
189}
190
191func (s *Server) HandleComAtprotoServerDescribeServer(c echo.Context) error {
192 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerDescribeServer")
193 defer span.End()
194 var out *comatprototypes.ServerDescribeServer_Output
195 var handleErr error
196 // func (s *Server) handleComAtprotoServerDescribeServer(ctx context.Context) (*comatprototypes.ServerDescribeServer_Output, error)
197 out, handleErr = s.handleComAtprotoServerDescribeServer(ctx)
198 if handleErr != nil {
199 return handleErr
200 }
201 return c.JSON(200, out)
202}
203
204func (s *Server) HandleComAtprotoSyncGetRecord(c echo.Context) error {
205 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSyncGetRecord")
206 defer span.End()
207 collection := c.QueryParam("collection")
208 did := c.QueryParam("did")
209 rkey := c.QueryParam("rkey")
210 var out io.Reader
211 var handleErr error
212 // func (s *Server) handleComAtprotoSyncGetRecord(ctx context.Context,collection string,did string,rkey string) (io.Reader, error)
213 out, handleErr = s.handleComAtprotoSyncGetRecord(ctx, collection, did, rkey)
214 if handleErr != nil {
215 return handleErr
216 }
217 return c.Stream(200, "application/vnd.ipld.car", out)
218}
219
220func (s *Server) HandleComAtprotoSyncListRepos(c echo.Context) error {
221 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSyncListRepos")
222 defer span.End()
223 cursor := c.QueryParam("cursor")
224
225 var limit int
226 if p := c.QueryParam("limit"); p != "" {
227 var err error
228 limit, err = strconv.Atoi(p)
229 if err != nil {
230 return err
231 }
232 } else {
233 limit = 500
234 }
235 var out *comatprototypes.SyncListRepos_Output
236 var handleErr error
237 // func (s *Server) handleComAtprotoSyncListRepos(ctx context.Context,cursor string,limit int) (*comatprototypes.SyncListRepos_Output, error)
238 out, handleErr = s.handleComAtprotoSyncListRepos(ctx, cursor, limit)
239 if handleErr != nil {
240 return handleErr
241 }
242 return c.JSON(200, out)
243}
244
245func (s *Server) RegisterHandlersPlaceStream(e *echo.Echo) error {
246 e.GET("/xrpc/place.stream.graph.getFollowingUser", s.HandlePlaceStreamGraphGetFollowingUser)
247 e.GET("/xrpc/place.stream.live.getLiveUsers", s.HandlePlaceStreamLiveGetLiveUsers)
248 e.GET("/xrpc/place.stream.live.getProfileCard", s.HandlePlaceStreamLiveGetProfileCard)
249 e.GET("/xrpc/place.stream.live.getSegments", s.HandlePlaceStreamLiveGetSegments)
250 return nil
251}
252
253func (s *Server) HandlePlaceStreamGraphGetFollowingUser(c echo.Context) error {
254 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandlePlaceStreamGraphGetFollowingUser")
255 defer span.End()
256 subjectDID := c.QueryParam("subjectDID")
257 userDID := c.QueryParam("userDID")
258 var out *placestreamtypes.GraphGetFollowingUser_Output
259 var handleErr error
260 // func (s *Server) handlePlaceStreamGraphGetFollowingUser(ctx context.Context,subjectDID string,userDID string) (*placestreamtypes.GraphGetFollowingUser_Output, error)
261 out, handleErr = s.handlePlaceStreamGraphGetFollowingUser(ctx, subjectDID, userDID)
262 if handleErr != nil {
263 return handleErr
264 }
265 return c.JSON(200, out)
266}
267
268func (s *Server) HandlePlaceStreamLiveGetLiveUsers(c echo.Context) error {
269 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandlePlaceStreamLiveGetLiveUsers")
270 defer span.End()
271 before := c.QueryParam("before")
272
273 var limit int
274 if p := c.QueryParam("limit"); p != "" {
275 var err error
276 limit, err = strconv.Atoi(p)
277 if err != nil {
278 return err
279 }
280 } else {
281 limit = 50
282 }
283 var out *placestreamtypes.LiveGetLiveUsers_Output
284 var handleErr error
285 // func (s *Server) handlePlaceStreamLiveGetLiveUsers(ctx context.Context,before string,limit int) (*placestreamtypes.LiveGetLiveUsers_Output, error)
286 out, handleErr = s.handlePlaceStreamLiveGetLiveUsers(ctx, before, limit)
287 if handleErr != nil {
288 return handleErr
289 }
290 return c.JSON(200, out)
291}
292
293func (s *Server) HandlePlaceStreamLiveGetProfileCard(c echo.Context) error {
294 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandlePlaceStreamLiveGetProfileCard")
295 defer span.End()
296 id := c.QueryParam("id")
297 var out io.Reader
298 var handleErr error
299 // func (s *Server) handlePlaceStreamLiveGetProfileCard(ctx context.Context,id string) (io.Reader, error)
300 out, handleErr = s.handlePlaceStreamLiveGetProfileCard(ctx, id)
301 if handleErr != nil {
302 return handleErr
303 }
304 return c.Stream(200, "application/octet-stream", out)
305}
306
307func (s *Server) HandlePlaceStreamLiveGetSegments(c echo.Context) error {
308 ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandlePlaceStreamLiveGetSegments")
309 defer span.End()
310 before := c.QueryParam("before")
311
312 var limit int
313 if p := c.QueryParam("limit"); p != "" {
314 var err error
315 limit, err = strconv.Atoi(p)
316 if err != nil {
317 return err
318 }
319 } else {
320 limit = 50
321 }
322 userDID := c.QueryParam("userDID")
323 var out *placestreamtypes.LiveGetSegments_Output
324 var handleErr error
325 // func (s *Server) handlePlaceStreamLiveGetSegments(ctx context.Context,before string,limit int,userDID string) (*placestreamtypes.LiveGetSegments_Output, error)
326 out, handleErr = s.handlePlaceStreamLiveGetSegments(ctx, before, limit, userDID)
327 if handleErr != nil {
328 return handleErr
329 }
330 return c.JSON(200, out)
331}
332
333func (s *Server) RegisterHandlersToolsOzone(e *echo.Echo) error {
334 return nil
335}