diff --git a/app/activitypub/util.py b/app/activitypub/util.py index a92a9600..c4aa0014 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -927,9 +927,6 @@ def post_json_to_model(activity_log, post_json, user, community) -> Post: post.image = image elif is_video_url(post.url): post.type = POST_TYPE_VIDEO - image = File(source_url=post.url) - db.session.add(image) - post.image = image else: post.type = POST_TYPE_LINK post.url = remove_tracking_from_link(post.url) @@ -1012,7 +1009,7 @@ def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory, to session = get_task_session() file: File = session.query(File).get(file_id) if file and file.source_url: - # Videos + # Videos (old code. not invoked because file.source_url won't end .mp4 or .webm) if file.source_url.endswith('.mp4') or file.source_url.endswith('.webm'): new_filename = gibberish(15) @@ -1863,12 +1860,6 @@ def update_post_from_activity(post: Post, request_json: dict): image = File(source_url=new_url) if 'name' in request_json['object']['attachment'][0] and request_json['object']['attachment'][0]['name'] is not None: image.alt_text = request_json['object']['attachment'][0]['name'] - elif is_video_url(new_url): - post.type = POST_TYPE_VIDEO - if 'image' in request_json['object'] and 'url' in request_json['object']['image']: - image = File(source_url=request_json['object']['image']['url']) - else: - image = File(source_url=new_url) else: if 'image' in request_json['object'] and 'url' in request_json['object']['image']: image = File(source_url=request_json['object']['image']['url']) @@ -1882,7 +1873,7 @@ def update_post_from_activity(post: Post, request_json: dict): filename = opengraph.get('og:image') or opengraph.get('og:image:url') if not filename.startswith('/'): image = File(source_url=filename, alt_text=shorten_string(opengraph.get('og:title'), 295)) - if is_video_hosting_site(new_url): + if is_video_hosting_site(new_url) or is_video_url(new_url): post.type = POST_TYPE_VIDEO else: post.type = POST_TYPE_LINK diff --git a/app/models.py b/app/models.py index 0e0a410d..d2c09832 100644 --- a/app/models.py +++ b/app/models.py @@ -1260,12 +1260,7 @@ class Post(db.Model): post.image = image elif is_video_url(post.url): # youtube is detected later post.type = constants.POST_TYPE_VIDEO - if 'image' in request_json['object'] and 'url' in request_json['object']['image']: - image = File(source_url=request_json['object']['image']['url']) - else: - image = File(source_url=post.url) - db.session.add(image) - post.image = image + # custom thumbnails will be added below in the "if 'image' in request_json['object'] and post.image is None:" section else: post.type = constants.POST_TYPE_LINK domain = domain_from_url(post.url) diff --git a/app/post/routes.py b/app/post/routes.py index d872e062..4b94f67b 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -23,7 +23,7 @@ from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, SUBSCRIPTION_ from app.models import Post, PostReply, \ PostReplyVote, PostVote, Notification, utcnow, UserBlock, DomainBlock, InstanceBlock, Report, Site, Community, \ Topic, User, Instance, NotificationSubscription, UserFollower, Poll, PollChoice, PollChoiceVote, PostBookmark, \ - PostReplyBookmark, CommunityBlock + PostReplyBookmark, CommunityBlock, File from app.post import bp from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \ shorten_string, markdown_to_text, gibberish, ap_datetime, return_304, \ @@ -1914,6 +1914,16 @@ def post_fixup_from_remote(post_id: int): remote_post_json = remote_post_request.json() remote_post_request.close() if 'type' in remote_post_json and remote_post_json['type'] == 'Page': + post.domain_id = None + file_entry_to_delete = None + if post.image_id: + file_entry_to_delete = post.image_id + post.image_id = None + post.url = None + db.session.commit() + if file_entry_to_delete: + File.query.filter_by(id=file_entry_to_delete).delete() + db.session.commit() update_json = {'type': 'Update', 'object': remote_post_json} update_post_from_activity(post, update_json) diff --git a/app/templates/post/_post_teaser_masonry.html b/app/templates/post/_post_teaser_masonry.html index 69ccabd5..0bf96b33 100644 --- a/app/templates/post/_post_teaser_masonry.html +++ b/app/templates/post/_post_teaser_masonry.html @@ -12,7 +12,7 @@ {% set post_title = post.title.replace('`', "'") %}
- {% if post.image_id %} + {% if post.image_id and not (post.url and (post.url.endswith('.mp4') or post.url.endswith('.webm'))) %}
{% if post.type == POST_TYPE_LINK or post.type == POST_TYPE_VIDEO %} {% if post.image.medium_url() %} @@ -36,22 +36,6 @@ alt="{{ post.image.alt_text if post.image.alt_text else '' }}" loading="{{ 'lazy' if low_bandwidth else 'eager' }}" /> {% endif %}
-
-
-
-
- {% include "post/_post_voting_buttons_masonry.html" %} -
-
- -
- - {% if post.reply_count %}{{ post.reply_count }}{% endif %} -
-
-
{% else %} {% if post.url and (post.url.endswith('.jpg') or post.url.endswith('.webp') or post.url.endswith('.png') or post.url.endswith('.gif') or post.url.endswith('.avif') or post.url.endswith('.jpeg')) %}
@@ -74,11 +58,37 @@
+ {% elif post.url and (post.url.endswith('.mp4') or post.url.endswith('.webm')) -%} +
+ +
{% else %}
-

{{ post_title }}

+

{% endif %} {% endif %} +
+
+
+
+ {% include "post/_post_voting_buttons_masonry.html" %} +
+
+ +
+ + {% if post.reply_count %}{{ post.reply_count }}{% endif %} +
+
+
{% endif %}