annual summary can be shared to bluesky
This commit is contained in:
parent
6e3e8ce472
commit
ae7c65054b
3 changed files with 37 additions and 7 deletions
|
@ -11,7 +11,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ site_name }} - {{ identity.display_name }} - {{ year }} 年度统计</title>
|
||||
<title>{{ site_name }} - {{ identity.display_name }} - {{ year }} {% trans "annual summary" %}</title>
|
||||
{% include "common_libs.html" %}
|
||||
{% comment %} <script src="{{ cdn_url }}/npm/rough-viz@2.0.5/dist/roughviz.umd.min.js"></script> {% endcomment %}
|
||||
<script src="{% static 'js/roughviz.umd.js' %}"></script>
|
||||
|
@ -35,20 +35,20 @@
|
|||
<div class="grid__main">
|
||||
<span class="action">
|
||||
<span>
|
||||
<a onclick="restyle()" title="随机风格"><i class="fa-solid fa-shuffle"></i></a>
|
||||
<a onclick="restyle()" title="{% trans 'another style' %}"><i class="fa-solid fa-shuffle"></i></a>
|
||||
</span>
|
||||
<span>
|
||||
<a hx-get="{% url 'journal:wrapped_share' year %}"
|
||||
hx-target="body"
|
||||
hx-swap="beforeend"
|
||||
title="转发到时间轴"><i class="fa-solid fa-share-from-square"></i></a>
|
||||
title="{% trans 'share' %}"><i class="fa-solid fa-share-from-square"></i></a>
|
||||
</span>
|
||||
<span>
|
||||
<a onclick="saveSvgAsPng($('#viz0').children('svg')[0], '{{ year }}-wrapped.png');"
|
||||
title="下载图片"><i class="fa-solid fa-download"></i></a>
|
||||
title="{% trans 'download' %}"><i class="fa-solid fa-download"></i></a>
|
||||
</span>
|
||||
</span>
|
||||
<h5>{{ year }} 年度统计</h5>
|
||||
<h5>{{ year }} {% trans "annual summary" %}</h5>
|
||||
<div id="viz0" style="max-width: 100%; aspect-ratio: 1 / 1;"></div>
|
||||
{{ by_cat|json_script:"cat-data" }}
|
||||
{{ monthly|json_script:"mon-data" }}
|
||||
|
|
|
@ -20,6 +20,7 @@ from catalog.models import (
|
|||
)
|
||||
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 @@ class WrappedShareView(LoginRequiredMixin, TemplateView):
|
|||
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", "/"))
|
||||
|
|
|
@ -7,6 +7,7 @@ from atproto_client import models
|
|||
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 @@ class BlueskyAccount(SocialAccount):
|
|||
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 @@ class BlueskyAccount(SocialAccount):
|
|||
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 @@ class BlueskyAccount(SocialAccount):
|
|||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue