about summary refs log tree commit diff
path: root/bskyweb/cmd
diff options
context:
space:
mode:
authordevin ivy <devinivy@gmail.com>2024-06-24 21:06:53 -0400
committerGitHub <noreply@github.com>2024-06-24 21:06:53 -0400
commit682f31ec9df290a63ec5b91c5943399da675b96f (patch)
tree10f7c90ac0595c347ce746cb1f98faca02580126 /bskyweb/cmd
parent6cda6412502c9af9ca07194d598ed37e880df23d (diff)
downloadvoidsky-682f31ec9df290a63ec5b91c5943399da675b96f.tar.zst
Add og meta tags to starter pack detail (#4585)
* add og meta tags to starter pack detail

* tidy

* bskyweb: add starter pack title to og meta

* bskyweb build

* go version to 1.22

* tidy
Diffstat (limited to 'bskyweb/cmd')
-rw-r--r--bskyweb/cmd/bskyweb/main.go6
-rw-r--r--bskyweb/cmd/bskyweb/server.go62
2 files changed, 65 insertions, 3 deletions
diff --git a/bskyweb/cmd/bskyweb/main.go b/bskyweb/cmd/bskyweb/main.go
index 49629e3f2..908486aa7 100644
--- a/bskyweb/cmd/bskyweb/main.go
+++ b/bskyweb/cmd/bskyweb/main.go
@@ -41,6 +41,12 @@ func run(args []string) {
 					EnvVars: []string{"ATP_APPVIEW_HOST", "ATP_PDS_HOST"},
 				},
 				&cli.StringFlag{
+					Name:  "ogcard-host",
+					Usage: "scheme, hostname, and port of ogcard service",
+					Required: false,
+					EnvVars: []string{"OGCARD_HOST"},
+				},
+				&cli.StringFlag{
 					Name:     "http-address",
 					Usage:    "Specify the local IP/port to bind to",
 					Required: false,
diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go
index 96fb07ddf..d7e41a4ca 100644
--- a/bskyweb/cmd/bskyweb/server.go
+++ b/bskyweb/cmd/bskyweb/server.go
@@ -31,12 +31,22 @@ type Server struct {
 	echo  *echo.Echo
 	httpd *http.Server
 	xrpcc *xrpc.Client
+	cfg   *Config
+}
+
+type Config struct {
+	debug       bool
+	httpAddress string
+	appviewHost string
+	ogcardHost  string
+	linkHost    string
 }
 
 func serve(cctx *cli.Context) error {
 	debug := cctx.Bool("debug")
 	httpAddress := cctx.String("http-address")
 	appviewHost := cctx.String("appview-host")
+	ogcardHost := cctx.String("ogcard-host")
 	linkHost := cctx.String("link-host")
 
 	// Echo
@@ -73,6 +83,13 @@ func serve(cctx *cli.Context) error {
 	server := &Server{
 		echo:  e,
 		xrpcc: xrpcc,
+		cfg: &Config{
+			debug:       debug,
+			httpAddress: httpAddress,
+			appviewHost: appviewHost,
+			ogcardHost:  ogcardHost,
+			linkHost:    linkHost,
+		},
 	}
 
 	// Create the HTTP server.
@@ -223,9 +240,9 @@ func serve(cctx *cli.Context) error {
 	e.GET("/profile/:handleOrDID/post/:rkey/liked-by", server.WebGeneric)
 	e.GET("/profile/:handleOrDID/post/:rkey/reposted-by", server.WebGeneric)
 
-    // starter packs
-	e.GET("/starter-pack/:handleOrDID/:rkey", server.WebGeneric)
-	e.GET("/start/:handleOrDID/:rkey", server.WebGeneric)
+	// starter packs
+	e.GET("/starter-pack/:handleOrDID/:rkey", server.WebStarterPack)
+	e.GET("/start/:handleOrDID/:rkey", server.WebStarterPack)
 
 	if linkHost != "" {
 		linkUrl, err := url.Parse(linkHost)
@@ -415,6 +432,45 @@ func (srv *Server) WebPost(c echo.Context) error {
 	return c.Render(http.StatusOK, "post.html", data)
 }
 
+func (srv *Server) WebStarterPack(c echo.Context) error {
+	req := c.Request()
+	ctx := req.Context()
+	data := pongo2.Context{}
+	data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path)
+	// 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 {
+		log.Errorf("bad rkey: %v", err)
+		return c.Render(http.StatusOK, "starterpack.html", data)
+	}
+	handleOrDIDParam := c.Param("handleOrDID")
+	handleOrDID, err := syntax.ParseAtIdentifier(handleOrDIDParam)
+	if err != nil {
+		log.Errorf("bad identifier: %v", err)
+		return c.Render(http.StatusOK, "starterpack.html", data)
+	}
+	identifier := handleOrDID.Normalize().String()
+	starterPackURI := fmt.Sprintf("at://%s/app.bsky.graph.starterpack/%s", identifier, rkey)
+	spv, err := appbsky.GraphGetStarterPack(ctx, srv.xrpcc, starterPackURI)
+	if err != nil {
+		log.Errorf("failed to fetch starter pack view for: %s\t%v", starterPackURI, err)
+		return c.Render(http.StatusOK, "starterpack.html", data)
+	}
+	if spv.StarterPack == nil || spv.StarterPack.Record == nil {
+		return c.Render(http.StatusOK, "starterpack.html", data)
+	}
+	rec, ok := spv.StarterPack.Record.Val.(*appbsky.GraphStarterpack)
+	if !ok {
+		return c.Render(http.StatusOK, "starterpack.html", data)
+	}
+	data["title"] = rec.Name
+	if srv.cfg.ogcardHost != "" {
+		data["imgThumbUrl"] = fmt.Sprintf("%s/start/%s/%s", srv.cfg.ogcardHost, identifier, rkey)
+	}
+	return c.Render(http.StatusOK, "starterpack.html", data)
+}
+
 func (srv *Server) WebProfile(c echo.Context) error {
 	ctx := c.Request().Context()
 	data := pongo2.Context{}