diff --git a/journal/templates/wrapped.html b/journal/templates/wrapped.html
index 55ddd33e..7cb7467f 100644
--- a/journal/templates/wrapped.html
+++ b/journal/templates/wrapped.html
@@ -11,7 +11,7 @@
-
+
+ title="{% trans 'share' %}">
+ title="{% trans 'download' %}">
-
{{ year }} 年度统计
+
{{ year }} {% trans "annual summary" %}
{{ by_cat|json_script:"cat-data" }}
{{ monthly|json_script:"mon-data" }}
diff --git a/journal/views/wrapped.py b/journal/views/wrapped.py
index 532f1666..2351ca85 100644
--- a/journal/views/wrapped.py
+++ b/journal/views/wrapped.py
@@ -20,6 +20,7 @@
)
from journal.models import Comment, ShelfType
from journal.models.common import VisibilityType
+from mastodon.models.bluesky import EmbedObj
from takahe.utils import Takahe
from users.models import User
@@ -137,5 +138,9 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
pass
elif post and user.mastodon:
user.mastodon.boost_later(post.url)
+ if visibility == VisibilityType.Public and user.bluesky:
+ o = EmbedObj("🧩", "", user.absolute_url)
+ txt = comment.rstrip() + "\n\n##obj##"
+ user.bluesky.post(txt, obj=o, images=[img])
messages.add_message(request, messages.INFO, _("Summary posted to timeline."))
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
diff --git a/mastodon/models/bluesky.py b/mastodon/models/bluesky.py
index 65b95f91..7ec91c91 100644
--- a/mastodon/models/bluesky.py
+++ b/mastodon/models/bluesky.py
@@ -7,6 +7,7 @@
from atproto_client.exceptions import AtProtocolError
from atproto_identity.did.resolver import DidResolver
from atproto_identity.handle.resolver import HandleResolver
+from django.conf import settings
from django.utils import timezone
from loguru import logger
@@ -230,8 +231,9 @@ def post(
self,
content,
reply_to_id=None,
- obj: "Item | Content | None" = None,
+ obj: "Item | Content | EmbedObj | None" = None,
rating=None,
+ images=[],
**kwargs,
):
from journal.models.renderers import render_rating
@@ -257,12 +259,27 @@ def post(
else:
first = False
richtext.text(t)
- if obj:
+ if images:
+ refs = [self._client.upload_blob(image).blob for image in images]
+ embed_images = [
+ models.AppBskyEmbedImages.Image(alt="", image=r) for r in refs
+ ]
+ embed = models.AppBskyEmbedImages.Main(images=embed_images)
+ elif obj:
+ cover = getattr(obj, "cover", None)
+ blob = (
+ cover.read()
+ if cover and cover != settings.DEFAULT_ITEM_COVER
+ else getattr(obj, "image", None)
+ )
+ blob_ref = self._client.upload_blob(blob).blob if blob else None
+ # blob_ref = None
embed = models.AppBskyEmbedExternal.Main(
external=models.AppBskyEmbedExternal.External(
title=obj.display_title,
description=obj.brief_description,
uri=obj.absolute_url,
+ thumb=blob_ref,
)
)
else:
@@ -273,3 +290,11 @@ def post(
def delete_post(self, post_uri):
self._client.delete_post(post_uri)
+
+
+class EmbedObj:
+ def __init__(self, title, description, uri, image=None):
+ self.display_title = title
+ self.brief_description = description
+ self.absolute_url = uri
+ self.image = image