fix embedr go:embed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
— US Department of the Interior (@Interior) <a href="https://twitter.com/Interior/status/463440424141459456?ref_src=twsrc%5Etfw">May 5, 2014</a>
|
||||
</blockquote>
|
||||
```
|
||||
@@ -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 |
@@ -4,3 +4,6 @@ import "embed"
|
||||
|
||||
//go:embed templates/*
|
||||
var TemplateFS embed.FS
|
||||
|
||||
//go:embed embedr-templates/*
|
||||
var EmbedrTemplateFS embed.FS
|
||||
|
||||
Reference in New Issue
Block a user