mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
27ecfafcd4
4 changed files with 42 additions and 36 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
{% set post_title = post.title.replace('`', "'") %}
|
||||
<div class="item{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}{{ ' blur' if blur_content }}"
|
||||
{% if content_blocked %} title="{{ _('Filtered: ') }}{{ content_blocked }}"{% endif %}>
|
||||
{% if post.image_id %}
|
||||
{% if post.image_id and not (post.url and (post.url.endswith('.mp4') or post.url.endswith('.webm'))) %}
|
||||
<div class="masonry_thumb" title="{{ post_title }}">
|
||||
{% 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' }}" /></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="masonry_info">
|
||||
<div class="row">
|
||||
<div class="col col-3">
|
||||
<div class="voting_buttons_masonry">
|
||||
{% include "post/_post_voting_buttons_masonry.html" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-8">
|
||||
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}" title="{{ post_title }}">{{ post_title }}</a></p>
|
||||
</div>
|
||||
<div class="col col-1 reply_col">
|
||||
<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}" aria-hidden="true"><span class="fe fe-reply"></span></a>
|
||||
{% if post.reply_count %}<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}">{{ post.reply_count }}</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% 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')) %}
|
||||
<div class="masonry_thumb" title="{{ post_title }}">
|
||||
|
@ -74,11 +58,37 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
{% elif post.url and (post.url.endswith('.mp4') or post.url.endswith('.webm')) -%}
|
||||
<div class="masonry_thumb" title="{{ post_title }}">
|
||||
<video class="responsive-video" controls preload="auto" {{ 'autoplay muted' if autoplay }} {{ 'loop' if post.community.loop_videos() }}>
|
||||
{% if post.url.endswith('.mp4') -%}
|
||||
<source src="{{ post.url }}" type="video/mp4" />
|
||||
{% elif post.url.endswith('.webm') -%}
|
||||
<source src="{{ post.url }}" type="video/webm" />
|
||||
{% endif -%}
|
||||
</video>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="masonry_info_no_image">
|
||||
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}">{{ post_title }}</a></p>
|
||||
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}"></a></p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<div class="masonry_info">
|
||||
<div class="row">
|
||||
<div class="col col-3">
|
||||
<div class="voting_buttons_masonry">
|
||||
{% include "post/_post_voting_buttons_masonry.html" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-8">
|
||||
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}" title="{{ post_title }}">{{ post_title }}</a></p>
|
||||
</div>
|
||||
<div class="col col-1 reply_col">
|
||||
<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}" aria-hidden="true"><span class="fe fe-reply"></span></a>
|
||||
{% if post.reply_count %}<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}">{{ post.reply_count }}</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue