Don't create embeds of profiles/posts from users who ask not to be sh… (#2189)

* Don't create embeds of profiles/posts from users who ask not to be shown in public views

* Formatting cleanup

* Bump workflow file to build an image for this branch
zio/stable
Jaz 2023-12-13 06:10:13 +09:00 committed by GitHub
parent 9ab0ff6f1d
commit bc42747297
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 17 deletions

View File

@ -4,6 +4,7 @@ on:
branches: branches:
- main - main
- traffic-reduction - traffic-reduction
- respect-optout-for-embeds
env: env:
REGISTRY: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_REGISTRY }} REGISTRY: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_REGISTRY }}
USERNAME: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_USERNAME }} USERNAME: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_USERNAME }}

View File

@ -296,21 +296,30 @@ func (srv *Server) WebPost(c echo.Context) error {
if err != nil { if err != nil {
log.Warnf("failed to fetch handle: %s\t%v", handle, err) log.Warnf("failed to fetch handle: %s\t%v", handle, err)
} else { } else {
did := pv.Did unauthedViewingOkay := true
data["did"] = did for _, label := range pv.Labels {
if label.Src == pv.Did && label.Val == "!no-unauthenticated" {
unauthedViewingOkay = false
}
}
// then fetch the post thread (with extra context) if unauthedViewingOkay {
uri := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", did, rkey) did := pv.Did
tpv, err := appbsky.FeedGetPostThread(ctx, srv.xrpcc, 1, uri) data["did"] = did
if err != nil {
log.Warnf("failed to fetch post: %s\t%v", uri, err) // then fetch the post thread (with extra context)
} else { uri := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", did, rkey)
req := c.Request() tpv, err := appbsky.FeedGetPostThread(ctx, srv.xrpcc, 1, uri)
postView := tpv.Thread.FeedDefs_ThreadViewPost.Post if err != nil {
data["postView"] = postView log.Warnf("failed to fetch post: %s\t%v", uri, err)
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) } else {
if postView.Embed != nil && postView.Embed.EmbedImages_View != nil { req := c.Request()
data["imgThumbUrl"] = postView.Embed.EmbedImages_View.Images[0].Thumb postView := tpv.Thread.FeedDefs_ThreadViewPost.Post
data["postView"] = postView
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path)
if postView.Embed != nil && postView.Embed.EmbedImages_View != nil {
data["imgThumbUrl"] = postView.Embed.EmbedImages_View.Images[0].Thumb
}
} }
} }
} }
@ -329,9 +338,17 @@ func (srv *Server) WebProfile(c echo.Context) error {
if err != nil { if err != nil {
log.Warnf("failed to fetch handle: %s\t%v", handle, err) log.Warnf("failed to fetch handle: %s\t%v", handle, err)
} else { } else {
req := c.Request() unauthedViewingOkay := true
data["profileView"] = pv for _, label := range pv.Labels {
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) if label.Src == pv.Did && label.Val == "!no-unauthenticated" {
unauthedViewingOkay = false
}
}
if unauthedViewingOkay {
req := c.Request()
data["profileView"] = pv
data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path)
}
} }
} }