From 1434e7502a0eb4aba0943be59a63aae714739ce8 Mon Sep 17 00:00:00 2001 From: moanos Date: Mon, 11 Aug 2025 12:43:15 +0200 Subject: [PATCH] fix: Limit upload of fediverse images to 6 --- src/fellchensammlung/tools/fedi.py | 8 +++++++- src/fellchensammlung/views.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fellchensammlung/tools/fedi.py b/src/fellchensammlung/tools/fedi.py index dfccdcd..f371363 100644 --- a/src/fellchensammlung/tools/fedi.py +++ b/src/fellchensammlung/tools/fedi.py @@ -58,6 +58,9 @@ class FediClient: response = requests.post(status_endpoint, headers=self.headers, data=payload) # Raise exception if posting fails + if response.status_code >= 300: + logging.error(f"Request= {response.request.body}") + logging.error(f"Response= {response.json()}") response.raise_for_status() return response.json() @@ -70,8 +73,11 @@ class FediClient: :param alt_text: The alt text for the image. :return: The response from the Mastodon API. """ + MAX_NUM_OF_IMAGES = 6 + if len(images) > MAX_NUM_OF_IMAGES: + logging.warning(f"Too many images ({len(images)}) to post. Selecting the first {MAX_NUM_OF_IMAGES} images.") media_ids = [] - for image in images: + for image in images[:MAX_NUM_OF_IMAGES]: # Upload the image and get the media ID media_ids.append(self.upload_media(f"{settings.MEDIA_ROOT}/{image.image}", image.alt_text)) diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index df8efbc..19a8c88 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -877,6 +877,7 @@ def moderation_tools_overview(request): if action == "post_to_fedi": adoption_notice = SocialMediaPost.get_an_to_post() if adoption_notice is not None: + logging.info(f"Posting adoption notice: {adoption_notice} ({adoption_notice.id})") try: post = post_an_to_fedi(adoption_notice) context = {"action_was_posting": True, "post": post, "posted_successfully": True}