Live video on the AT Protocol
at issue-705-2 48 lines 1.4 kB view raw
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 host := a.CLI.BroadcasterHost 17 _, pub, err := a.StatefulDB.EnsurePublisherKey(ctx) 18 if err != nil { 19 log.Error(ctx, "could not get publisher key", "error", err) 20 http.Error(w, "could not get publisher key", http.StatusInternalServerError) 21 return 22 } 23 didJSON := atproto.DIDDoc(host, pub) 24 w.WriteHeader(200) 25 w.Header().Set("Content-Type", "application/json") 26 bs, err := json.Marshal(didJSON) 27 if err != nil { 28 log.Error(ctx, "could not marshal did json", "error", err) 29 return 30 } 31 if _, err := w.Write(bs); err != nil { 32 log.Error(ctx, "error writing response", "error", err) 33 } 34 } 35} 36 37func (a *StreamplaceAPI) HandleAtprotoDID(ctx context.Context) httprouter.Handle { 38 return func(w http.ResponseWriter, req *http.Request, params httprouter.Params) { 39 did := a.CLI.AtprotoDID 40 if did == "" { 41 did = fmt.Sprintf("did:web:%s", a.CLI.BroadcasterHost) 42 } 43 _, err := fmt.Fprintf(w, "%s", did) 44 if err != nil { 45 log.Error(ctx, "error writing response", "error", err) 46 } 47 } 48}