Live video on the AT Protocol
1package api
2
3import (
4 "context"
5 "encoding/json"
6 "fmt"
7 "net/http"
8
9 "github.com/julienschmidt/httprouter"
10 "stream.place/streamplace/pkg/atproto"
11 "stream.place/streamplace/pkg/log"
12)
13
14func (a *StreamplaceAPI) HandleDidJSON(ctx context.Context) httprouter.Handle {
15 return func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
16 didJSON := atproto.DIDDoc(a.CLI)
17 w.WriteHeader(200)
18 w.Header().Set("Content-Type", "application/json")
19 bs, err := json.Marshal(didJSON)
20 if err != nil {
21 log.Error(ctx, "could not marshal did json", "error", err)
22 return
23 }
24 if _, err := w.Write(bs); err != nil {
25 log.Error(ctx, "error writing response", "error", err)
26 }
27 }
28}
29
30func (a *StreamplaceAPI) HandleAtprotoDID(ctx context.Context) httprouter.Handle {
31 return func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
32 _, err := fmt.Fprintf(w, "%s", a.CLI.MyDID())
33 if err != nil {
34 log.Error(ctx, "error writing response", "error", err)
35 }
36 }
37}