fix embedr go:embed

This commit is contained in:
bryan newbold
2024-04-12 11:51:46 -07:00
parent 2861ec7ed5
commit cfaf5ccca4
17 changed files with 69 additions and 11 deletions
+1
View File
@@ -3,6 +3,7 @@ test-coverage.out
# Don't check in the binary.
/bskyweb
/embedr
# Don't accidentally commit JS-generated code
static/js/*.js
+5
View File
@@ -14,6 +14,7 @@ help: ## Print info about all commands
.PHONY: build
build: ## Build all executables
go build ./cmd/bskyweb
go build ./cmd/embedr
.PHONY: test
test: ## Run all tests
@@ -43,3 +44,7 @@ check: ## Compile everything, checking syntax (does not output binaries)
.PHONY: run-dev-bskyweb
run-dev-bskyweb: .env ## Runs 'bskyweb' for local dev
GOLOG_LOG_LEVEL=info go run ./cmd/bskyweb serve
.PHONY: run-dev-embedr
run-dev-embedr: .env ## Runs 'embedr' for local dev
GOLOG_LOG_LEVEL=info go run ./cmd/embedr serve
+52
View File
@@ -0,0 +1,52 @@
## oEmbed
<https://oembed.com/>
* URL scheme: `https://bsky.app/profile/*/post/*`
* API endpoint: `https://embed.bsky.app/oembed`
Request params:
- `url` (required): support both AT-URI and bsky.app URL
- `maxwidth` (optional): [220..550], 325 is default
- `maxheight` (not supported!)
- `format` (optional): only `json` supported
Response format:
- `type` (required): "rich"
- `version` (required): "1.0"
- `author_name` (optional): display name
- `author_url` (optional): profile URL
- `provider_name` (optional): "Bluesky Social"
- `provider_url` (optional): "https://bsky.app"
- `cache_age` (optional, integer seconds): 86400 (24 hours) (?)
- `width` (required): ?
- `height` (required): ?
Not used:
- title (optional): A text title, describing the resource.
- thumbnail_url (optional): A URL to a thumbnail image representing the resource. The thumbnail must respect any maxwidth and maxheight parameters. If this parameter is present, thumbnail_width and thumbnail_height must also be present.
- thumbnail_width (optional): The width of the optional thumbnail. If this parameter is present, thumbnail_url and thumbnail_height must also be present.
- thumbnail_height (optional): The height of the optional thumbnail. If this parameter is present, thumbnail_url and thumbnail_width must also be present.
Only `json` is supported; `xml` is a 501.
```
<link rel="alternate" type="application/json+oembed" href="https://embed.bsky.app/oembed?format=json&url=https://bsky.app/profile/bnewbold.net/post/abc123" />
```
## iframe URL
`https://embed.bsky.app/embed/<did>/app.bsky.feed.post/<rkey>`
`https://embed.bsky.app/static/embed.js`
```
<blockquote class="bluesky-post" data-lang="en" data-align="center">
<p lang="en" dir="ltr">{{ post-text }}</p>
&mdash; US Department of the Interior (@Interior) <a href="https://twitter.com/Interior/status/463440424141459456?ref_src=twsrc%5Etfw">May 5, 2014</a>
</blockquote>
```
+8 -11
View File
@@ -85,7 +85,7 @@ func serve(cctx *cli.Context) error {
e.HideBanner = true
tmpl := &Template{
templates: template.Must(template.ParseGlob("embed-templates/*.html")),
templates: template.Must(template.ParseFS(bskyweb.EmbedrTemplateFS, "embedr-templates/*.html")),
}
e.Renderer = tmpl
e.HTTPErrorHandler = server.errorHandler
@@ -104,7 +104,7 @@ func serve(cctx *cli.Context) error {
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
// Don't log requests for static content.
Skipper: func(c echo.Context) bool {
return strings.HasPrefix(c.Request().URL.Path, "/embed-static")
return strings.HasPrefix(c.Request().URL.Path, "/embedr-static")
},
}))
e.Use(middleware.RateLimiterWithConfig(middleware.RateLimiterConfig{
@@ -174,7 +174,7 @@ func serve(cctx *cli.Context) error {
e.GET("/", server.WebHome)
e.GET("/embed.js", echo.WrapHandler(staticHandler))
e.GET("/oembed", server.WebOEmbed)
e.GET("/embed/did/app.bsky.feed.post/rkey", server.WebPostEmbed)
e.GET("/embed/:did/app.bsky.feed.post/:rkey", server.WebPostEmbed)
// Start the server.
log.Infof("starting server address=%s", httpAddress)
@@ -253,18 +253,16 @@ func (srv *Server) WebPostEmbed(c echo.Context) error {
if err != nil {
return c.Render(http.StatusOK, "postEmbed.html", data)
}
handleOrDIDParam := c.Param("handleOrDID")
handleOrDID, err := syntax.ParseAtIdentifier(handleOrDIDParam)
didParam := c.Param("did")
did, err := syntax.ParseDID(didParam)
if err != nil {
return c.Render(http.StatusOK, "postEmbed.html", data)
}
identifier := handleOrDID.Normalize().String()
// requires two fetches: first fetch profile (!)
pv, err := appbsky.ActorGetProfile(ctx, srv.xrpcc, identifier)
pv, err := appbsky.ActorGetProfile(ctx, srv.xrpcc, did.String())
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", did, err)
return c.Render(http.StatusOK, "postEmbed.html", data)
}
unauthedViewingOkay := true
@@ -277,8 +275,7 @@ func (srv *Server) WebPostEmbed(c echo.Context) error {
if !unauthedViewingOkay {
return c.Render(http.StatusOK, "postEmbed.html", data)
}
did := pv.Did
data["did"] = did
data["did"] = did.String()
// then fetch the post thread (with extra context)
uri := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", did, rkey)

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

+3
View File
@@ -4,3 +4,6 @@ import "embed"
//go:embed templates/*
var TemplateFS embed.FS
//go:embed embedr-templates/*
var EmbedrTemplateFS embed.FS