yet more RSS tweaks (#2289)
* rss: full URL in RSS link; use request Host in URLs Full URL syntax on request from third parties. Using the actual request host should fix issues with non-bsky-production deployments. It is HTTPS-only, so doesn't work perfectly for local dev. * rss: make /profile/{handle}/rss an HTTP redirect Motivation is easier discoverability of RSS feed.zio/stable
parent
ee20092735
commit
b922b83820
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
appbsky "github.com/bluesky-social/indigo/api/bsky"
|
appbsky "github.com/bluesky-social/indigo/api/bsky"
|
||||||
|
@ -39,11 +40,33 @@ type rss struct {
|
||||||
|
|
||||||
func (srv *Server) WebProfileRSS(c echo.Context) error {
|
func (srv *Server) WebProfileRSS(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
|
req := c.Request()
|
||||||
|
|
||||||
didParam := c.Param("did")
|
identParam := c.Param("ident")
|
||||||
did, err := syntax.ParseDID(didParam)
|
|
||||||
|
// if not a DID, try parsing as a handle and doing a redirect
|
||||||
|
if !strings.HasPrefix(identParam, "did:") {
|
||||||
|
handle, err := syntax.ParseHandle(identParam)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(400, fmt.Sprintf("not a valid DID: %s", didParam))
|
return echo.NewHTTPError(400, fmt.Sprintf("not a valid handle: %s", identParam))
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that public view is Ok, and resolve DID
|
||||||
|
pv, err := appbsky.ActorGetProfile(ctx, srv.xrpcc, handle.String())
|
||||||
|
if err != nil {
|
||||||
|
return echo.NewHTTPError(404, fmt.Sprintf("account not found: %s", handle))
|
||||||
|
}
|
||||||
|
for _, label := range pv.Labels {
|
||||||
|
if label.Src == pv.Did && label.Val == "!no-unauthenticated" {
|
||||||
|
return echo.NewHTTPError(403, fmt.Sprintf("account does not allow public views: %s", handle))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c.Redirect(http.StatusFound, fmt.Sprintf("/profile/%s/rss", pv.Did))
|
||||||
|
}
|
||||||
|
|
||||||
|
did, err := syntax.ParseDID(identParam)
|
||||||
|
if err != nil {
|
||||||
|
return echo.NewHTTPError(400, fmt.Sprintf("not a valid DID: %s", identParam))
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that public view is Ok
|
// check that public view is Ok
|
||||||
|
@ -84,7 +107,7 @@ func (srv *Server) WebProfileRSS(c echo.Context) error {
|
||||||
pubDate = createdAt.Time().Format(time.RFC822Z)
|
pubDate = createdAt.Time().Format(time.RFC822Z)
|
||||||
}
|
}
|
||||||
posts = append(posts, Item{
|
posts = append(posts, Item{
|
||||||
Link: fmt.Sprintf("https://bsky.app/profile/%s/post/%s", pv.Handle, aturi.RecordKey().String()),
|
Link: fmt.Sprintf("https://%s/profile/%s/post/%s", req.Host, pv.Handle, aturi.RecordKey().String()),
|
||||||
Description: rec.Text,
|
Description: rec.Text,
|
||||||
PubDate: pubDate,
|
PubDate: pubDate,
|
||||||
GUID: ItemGUID{
|
GUID: ItemGUID{
|
||||||
|
@ -105,7 +128,7 @@ func (srv *Server) WebProfileRSS(c echo.Context) error {
|
||||||
feed := &rss{
|
feed := &rss{
|
||||||
Version: "2.0",
|
Version: "2.0",
|
||||||
Description: desc,
|
Description: desc,
|
||||||
Link: fmt.Sprintf("https://bsky.app/profile/%s", pv.Handle),
|
Link: fmt.Sprintf("https://%s/profile/%s", req.Host, pv.Handle),
|
||||||
Title: title,
|
Title: title,
|
||||||
Item: posts,
|
Item: posts,
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,7 @@ func serve(cctx *cli.Context) error {
|
||||||
e.GET("/profile/:handle/feed/:rkey/liked-by", server.WebGeneric)
|
e.GET("/profile/:handle/feed/:rkey/liked-by", server.WebGeneric)
|
||||||
|
|
||||||
// profile RSS feed (DID not handle)
|
// profile RSS feed (DID not handle)
|
||||||
e.GET("/profile/:did/rss", server.WebProfileRSS)
|
e.GET("/profile/:ident/rss", server.WebProfileRSS)
|
||||||
|
|
||||||
// post endpoints; only first populates info
|
// post endpoints; only first populates info
|
||||||
e.GET("/profile/:handle/post/:rkey", server.WebPost)
|
e.GET("/profile/:handle/post/:rkey", server.WebPost)
|
||||||
|
@ -370,6 +370,7 @@ func (srv *Server) WebProfile(c echo.Context) error {
|
||||||
req := c.Request()
|
req := c.Request()
|
||||||
data["profileView"] = pv
|
data["profileView"] = pv
|
||||||
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path)
|
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path)
|
||||||
|
data["requestHost"] = req.Host
|
||||||
return c.Render(http.StatusOK, "profile.html", data)
|
return c.Render(http.StatusOK, "profile.html", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,9 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<meta name="twitter:label1" content="Account DID">
|
<meta name="twitter:label1" content="Account DID">
|
||||||
<meta name="twitter:value1" content="{{ profileView.Did }}">
|
<meta name="twitter:value1" content="{{ profileView.Did }}">
|
||||||
<link rel="alternate" type="application/rss+xml" href="/profile/{{ profileView.Did }}/rss">
|
{%- if requestHost %}
|
||||||
|
<link rel="alternate" type="application/rss+xml" href="https://{{ requestHost }}/profile/{{ profileView.Did }}/rss">
|
||||||
|
{% endif %}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue