From 2861ec7ed592a1b72ff98ee5dc041ae7d74a9359 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Fri, 12 Apr 2024 11:18:36 -0700 Subject: [PATCH] actual routes --- bskyweb/cmd/embedr/server.go | 27 +++++++++++++------------- bskyweb/embed-static/embed.js | 1 + bskyweb/embed-templates/home.html | 2 +- bskyweb/embed-templates/oembed.html | 1 + bskyweb/embed-templates/postEmbed.html | 1 + 5 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 bskyweb/embed-static/embed.js create mode 100644 bskyweb/embed-templates/oembed.html create mode 100644 bskyweb/embed-templates/postEmbed.html diff --git a/bskyweb/cmd/embedr/server.go b/bskyweb/cmd/embedr/server.go index 2c519106dc..c47aed9675 100644 --- a/bskyweb/cmd/embedr/server.go +++ b/bskyweb/cmd/embedr/server.go @@ -172,7 +172,9 @@ func serve(cctx *cli.Context) error { // actual routes e.GET("/", server.WebHome) - e.GET("/about", server.WebGeneric) + e.GET("/embed.js", echo.WrapHandler(staticHandler)) + e.GET("/oembed", server.WebOEmbed) + e.GET("/embed/did/app.bsky.feed.post/rkey", server.WebPostEmbed) // Start the server. log.Infof("starting server address=%s", httpAddress) @@ -231,18 +233,17 @@ func (srv *Server) errorHandler(err error, c echo.Context) { c.Render(code, "error.html", data) } -// handler for endpoint that have no specific server-side handling -func (srv *Server) WebGeneric(c echo.Context) error { +func (srv *Server) WebHome(c echo.Context) error { data := map[string]interface{}{} - return c.Render(http.StatusOK, "base.html", data) + return c.Render(http.StatusOK, "home.html", data) } -func (srv *Server) WebHome(c echo.Context) error { +func (srv *Server) WebOEmbed(c echo.Context) error { data := map[string]interface{}{} - return c.Render(http.StatusOK, "home.html", data) + return c.Render(http.StatusOK, "oembed.html", data) } -func (srv *Server) WebPost(c echo.Context) error { +func (srv *Server) WebPostEmbed(c echo.Context) error { ctx := c.Request().Context() data := map[string]interface{}{} @@ -250,12 +251,12 @@ func (srv *Server) WebPost(c echo.Context) error { rkeyParam := c.Param("rkey") rkey, err := syntax.ParseRecordKey(rkeyParam) if err != nil { - return c.Render(http.StatusOK, "post.html", data) + return c.Render(http.StatusOK, "postEmbed.html", data) } handleOrDIDParam := c.Param("handleOrDID") handleOrDID, err := syntax.ParseAtIdentifier(handleOrDIDParam) if err != nil { - return c.Render(http.StatusOK, "post.html", data) + return c.Render(http.StatusOK, "postEmbed.html", data) } identifier := handleOrDID.Normalize().String() @@ -264,7 +265,7 @@ func (srv *Server) WebPost(c echo.Context) error { pv, err := appbsky.ActorGetProfile(ctx, srv.xrpcc, identifier) if err != nil { log.Warnf("failed to fetch profile for: %s\t%v", identifier, err) - return c.Render(http.StatusOK, "post.html", data) + return c.Render(http.StatusOK, "postEmbed.html", data) } unauthedViewingOkay := true for _, label := range pv.Labels { @@ -274,7 +275,7 @@ func (srv *Server) WebPost(c echo.Context) error { } if !unauthedViewingOkay { - return c.Render(http.StatusOK, "post.html", data) + return c.Render(http.StatusOK, "postEmbed.html", data) } did := pv.Did data["did"] = did @@ -284,7 +285,7 @@ func (srv *Server) WebPost(c echo.Context) error { tpv, err := appbsky.FeedGetPostThread(ctx, srv.xrpcc, 1, 0, uri) if err != nil { log.Warnf("failed to fetch post: %s\t%v", uri, err) - return c.Render(http.StatusOK, "post.html", data) + return c.Render(http.StatusOK, "postEmbed.html", data) } req := c.Request() postView := tpv.Thread.FeedDefs_ThreadViewPost.Post @@ -314,5 +315,5 @@ func (srv *Server) WebPost(c echo.Context) error { } } - return c.Render(http.StatusOK, "post.html", data) + return c.Render(http.StatusOK, "postEmbed.html", data) } diff --git a/bskyweb/embed-static/embed.js b/bskyweb/embed-static/embed.js new file mode 100644 index 0000000000..15964a76c3 --- /dev/null +++ b/bskyweb/embed-static/embed.js @@ -0,0 +1 @@ +/* embed javascript widget will go here */ diff --git a/bskyweb/embed-templates/home.html b/bskyweb/embed-templates/home.html index 0ff746b56a..6da3381246 100644 --- a/bskyweb/embed-templates/home.html +++ b/bskyweb/embed-templates/home.html @@ -1 +1 @@ -embed homepage +embed homepage: could redirect to bsky.app, or show a "create embed" widget diff --git a/bskyweb/embed-templates/oembed.html b/bskyweb/embed-templates/oembed.html new file mode 100644 index 0000000000..646f0a482c --- /dev/null +++ b/bskyweb/embed-templates/oembed.html @@ -0,0 +1 @@ +oembed JSON response will go here diff --git a/bskyweb/embed-templates/postEmbed.html b/bskyweb/embed-templates/postEmbed.html new file mode 100644 index 0000000000..6329b3a199 --- /dev/null +++ b/bskyweb/embed-templates/postEmbed.html @@ -0,0 +1 @@ +embed post HTML will go here