actual routes
This commit is contained in:
committed by
Dan Abramov
parent
7b1985d0a6
commit
516e602841
@@ -172,7 +172,9 @@ func serve(cctx *cli.Context) error {
|
|||||||
|
|
||||||
// actual routes
|
// actual routes
|
||||||
e.GET("/", server.WebHome)
|
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.
|
// Start the server.
|
||||||
log.Infof("starting server address=%s", httpAddress)
|
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)
|
c.Render(code, "error.html", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler for endpoint that have no specific server-side handling
|
|
||||||
func (srv *Server) WebGeneric(c echo.Context) error {
|
|
||||||
data := map[string]interface{}{}
|
|
||||||
return c.Render(http.StatusOK, "base.html", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (srv *Server) WebHome(c echo.Context) error {
|
func (srv *Server) WebHome(c echo.Context) error {
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
return c.Render(http.StatusOK, "home.html", data)
|
return c.Render(http.StatusOK, "home.html", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) WebPost(c echo.Context) error {
|
func (srv *Server) WebOEmbed(c echo.Context) error {
|
||||||
|
data := map[string]interface{}{}
|
||||||
|
return c.Render(http.StatusOK, "oembed.html", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (srv *Server) WebPostEmbed(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
|
|
||||||
@@ -250,12 +251,12 @@ func (srv *Server) WebPost(c echo.Context) error {
|
|||||||
rkeyParam := c.Param("rkey")
|
rkeyParam := c.Param("rkey")
|
||||||
rkey, err := syntax.ParseRecordKey(rkeyParam)
|
rkey, err := syntax.ParseRecordKey(rkeyParam)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Render(http.StatusOK, "post.html", data)
|
return c.Render(http.StatusOK, "postEmbed.html", data)
|
||||||
}
|
}
|
||||||
handleOrDIDParam := c.Param("handleOrDID")
|
handleOrDIDParam := c.Param("handleOrDID")
|
||||||
handleOrDID, err := syntax.ParseAtIdentifier(handleOrDIDParam)
|
handleOrDID, err := syntax.ParseAtIdentifier(handleOrDIDParam)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Render(http.StatusOK, "post.html", data)
|
return c.Render(http.StatusOK, "postEmbed.html", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
identifier := handleOrDID.Normalize().String()
|
identifier := handleOrDID.Normalize().String()
|
||||||
@@ -264,7 +265,7 @@ func (srv *Server) WebPost(c echo.Context) error {
|
|||||||
pv, err := appbsky.ActorGetProfile(ctx, srv.xrpcc, identifier)
|
pv, err := appbsky.ActorGetProfile(ctx, srv.xrpcc, identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to fetch profile for: %s\t%v", identifier, err)
|
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
|
unauthedViewingOkay := true
|
||||||
for _, label := range pv.Labels {
|
for _, label := range pv.Labels {
|
||||||
@@ -274,7 +275,7 @@ func (srv *Server) WebPost(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !unauthedViewingOkay {
|
if !unauthedViewingOkay {
|
||||||
return c.Render(http.StatusOK, "post.html", data)
|
return c.Render(http.StatusOK, "postEmbed.html", data)
|
||||||
}
|
}
|
||||||
did := pv.Did
|
did := pv.Did
|
||||||
data["did"] = 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)
|
tpv, err := appbsky.FeedGetPostThread(ctx, srv.xrpcc, 1, 0, uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to fetch post: %s\t%v", uri, err)
|
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()
|
req := c.Request()
|
||||||
postView := tpv.Thread.FeedDefs_ThreadViewPost.Post
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
/* embed javascript widget will go here */
|
||||||
@@ -1 +1 @@
|
|||||||
embed homepage
|
embed homepage: could redirect to bsky.app, or show a "create embed" widget
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
oembed JSON response will go here
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
embed post HTML will go here
|
||||||
Reference in New Issue
Block a user