Skip to content

Commit

Permalink
actual routes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold committed Apr 12, 2024
1 parent 06fe6a6 commit 2861ec7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
27 changes: 14 additions & 13 deletions bskyweb/cmd/embedr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -231,31 +233,30 @@ 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{}{}

// sanity check arguments. don't 4xx, just let app handle if not expected format
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()
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions bskyweb/embed-static/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* embed javascript widget will go here */
2 changes: 1 addition & 1 deletion bskyweb/embed-templates/home.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
embed homepage
embed homepage: could redirect to bsky.app, or show a "create embed" widget
1 change: 1 addition & 0 deletions bskyweb/embed-templates/oembed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oembed JSON response will go here
1 change: 1 addition & 0 deletions bskyweb/embed-templates/postEmbed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
embed post HTML will go here

0 comments on commit 2861ec7

Please sign in to comment.