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>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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" %}
|
{% include "common_libs.html" %}
|
||||||
{% comment %} <script src="{{ cdn_url }}/npm/rough-viz@2.0.5/dist/roughviz.umd.min.js"></script> {% endcomment %}
|
{% 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>
|
<script src="{% static 'js/roughviz.umd.js' %}"></script>
|
||||||
|
@ -35,20 +35,20 @@
|
||||||
<div class="grid__main">
|
<div class="grid__main">
|
||||||
<span class="action">
|
<span class="action">
|
||||||
<span>
|
<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>
|
||||||
<span>
|
<span>
|
||||||
<a hx-get="{% url 'journal:wrapped_share' year %}"
|
<a hx-get="{% url 'journal:wrapped_share' year %}"
|
||||||
hx-target="body"
|
hx-target="body"
|
||||||
hx-swap="beforeend"
|
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>
|
||||||
<span>
|
<span>
|
||||||
<a onclick="saveSvgAsPng($('#viz0').children('svg')[0], '{{ year }}-wrapped.png');"
|
<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>
|
||||||
</span>
|
</span>
|
||||||
<h5>{{ year }} 年度统计</h5>
|
<h5>{{ year }} {% trans "annual summary" %}</h5>
|
||||||
<div id="viz0" style="max-width: 100%; aspect-ratio: 1 / 1;"></div>
|
<div id="viz0" style="max-width: 100%; aspect-ratio: 1 / 1;"></div>
|
||||||
{{ by_cat|json_script:"cat-data" }}
|
{{ by_cat|json_script:"cat-data" }}
|
||||||
{{ monthly|json_script:"mon-data" }}
|
{{ monthly|json_script:"mon-data" }}
|
||||||
|
|
|
@ -20,6 +20,7 @@ from catalog.models import (
|
||||||
)
|
)
|
||||||
from journal.models import Comment, ShelfType
|
from journal.models import Comment, ShelfType
|
||||||
from journal.models.common import VisibilityType
|
from journal.models.common import VisibilityType
|
||||||
|
from mastodon.models.bluesky import EmbedObj
|
||||||
from takahe.utils import Takahe
|
from takahe.utils import Takahe
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
|
||||||
|
@ -137,5 +138,9 @@ class WrappedShareView(LoginRequiredMixin, TemplateView):
|
||||||
pass
|
pass
|
||||||
elif post and user.mastodon:
|
elif post and user.mastodon:
|
||||||
user.mastodon.boost_later(post.url)
|
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."))
|
messages.add_message(request, messages.INFO, _("Summary posted to timeline."))
|
||||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||||
|
|
|
@ -7,6 +7,7 @@ from atproto_client import models
|
||||||
from atproto_client.exceptions import AtProtocolError
|
from atproto_client.exceptions import AtProtocolError
|
||||||
from atproto_identity.did.resolver import DidResolver
|
from atproto_identity.did.resolver import DidResolver
|
||||||
from atproto_identity.handle.resolver import HandleResolver
|
from atproto_identity.handle.resolver import HandleResolver
|
||||||
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
@ -230,8 +231,9 @@ class BlueskyAccount(SocialAccount):
|
||||||
self,
|
self,
|
||||||
content,
|
content,
|
||||||
reply_to_id=None,
|
reply_to_id=None,
|
||||||
obj: "Item | Content | None" = None,
|
obj: "Item | Content | EmbedObj | None" = None,
|
||||||
rating=None,
|
rating=None,
|
||||||
|
images=[],
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
from journal.models.renderers import render_rating
|
from journal.models.renderers import render_rating
|
||||||
|
@ -257,12 +259,27 @@ class BlueskyAccount(SocialAccount):
|
||||||
else:
|
else:
|
||||||
first = False
|
first = False
|
||||||
richtext.text(t)
|
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(
|
embed = models.AppBskyEmbedExternal.Main(
|
||||||
external=models.AppBskyEmbedExternal.External(
|
external=models.AppBskyEmbedExternal.External(
|
||||||
title=obj.display_title,
|
title=obj.display_title,
|
||||||
description=obj.brief_description,
|
description=obj.brief_description,
|
||||||
uri=obj.absolute_url,
|
uri=obj.absolute_url,
|
||||||
|
thumb=blob_ref,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@ -273,3 +290,11 @@ class BlueskyAccount(SocialAccount):
|
||||||
|
|
||||||
def delete_post(self, post_uri):
|
def delete_post(self, post_uri):
|
||||||
self._client.delete_post(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