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/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 %}