mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
improve consistency of image post handling
when a link post is created and the link is to an image, create an image post instead
This commit is contained in:
parent
6d2b722f0e
commit
ad62df7c10
2 changed files with 12 additions and 10 deletions
|
@ -9,7 +9,7 @@ from sqlalchemy import or_, desc
|
||||||
|
|
||||||
from app import db, constants, cache
|
from app import db, constants, cache
|
||||||
from app.activitypub.signature import RsaKeys, post_request
|
from app.activitypub.signature import RsaKeys, post_request
|
||||||
from app.activitypub.util import default_context, notify_about_post, find_actor_or_create
|
from app.activitypub.util import default_context, notify_about_post, find_actor_or_create, make_image_sizes
|
||||||
from app.chat.util import send_message
|
from app.chat.util import send_message
|
||||||
from app.community.forms import SearchRemoteCommunity, CreatePostForm, ReportCommunityForm, \
|
from app.community.forms import SearchRemoteCommunity, CreatePostForm, ReportCommunityForm, \
|
||||||
DeleteCommunityForm, AddCommunityForm, EditCommunityForm, AddModeratorForm, BanUserCommunityForm
|
DeleteCommunityForm, AddCommunityForm, EditCommunityForm, AddModeratorForm, BanUserCommunityForm
|
||||||
|
@ -465,6 +465,8 @@ def add_post(actor):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}"
|
post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}"
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
if post.image_id and post.image.file_path is None:
|
||||||
|
make_image_sizes(post.image_id, 150, 512, 'posts') # the 512 sized image is for masonry view
|
||||||
|
|
||||||
notify_about_post(post)
|
notify_about_post(post)
|
||||||
|
|
||||||
|
|
|
@ -210,13 +210,13 @@ def save_post(form, post: Post):
|
||||||
remove_old_file(post.image_id)
|
remove_old_file(post.image_id)
|
||||||
post.image_id = None
|
post.image_id = None
|
||||||
|
|
||||||
unused, file_extension = os.path.splitext(form.link_url.data) # do not use _ here instead of 'unused'
|
unused, file_extension = os.path.splitext(form.link_url.data)
|
||||||
# this url is a link to an image - generate a thumbnail of it
|
# this url is a link to an image - turn it into a image post
|
||||||
if file_extension.lower() in allowed_extensions:
|
if file_extension.lower() in allowed_extensions:
|
||||||
file = url_to_thumbnail_file(form.link_url.data)
|
file = File(source_url=form.link_url.data)
|
||||||
if file:
|
post.image = file
|
||||||
post.image = file
|
db.session.add(file)
|
||||||
db.session.add(file)
|
post.type = POST_TYPE_IMAGE
|
||||||
else:
|
else:
|
||||||
# check opengraph tags on the page and make a thumbnail if an image is available in the og:image meta tag
|
# check opengraph tags on the page and make a thumbnail if an image is available in the og:image meta tag
|
||||||
opengraph = opengraph_parse(form.link_url.data)
|
opengraph = opengraph_parse(form.link_url.data)
|
||||||
|
@ -270,13 +270,13 @@ def save_post(form, post: Post):
|
||||||
img = ImageOps.exif_transpose(img)
|
img = ImageOps.exif_transpose(img)
|
||||||
img_width = img.width
|
img_width = img.width
|
||||||
img_height = img.height
|
img_height = img.height
|
||||||
if img.width > 2000 or img.height > 2000:
|
if img.width > 512 or img.height > 512:
|
||||||
img.thumbnail((2000, 2000))
|
img.thumbnail((512, 512))
|
||||||
img.save(final_place)
|
img.save(final_place)
|
||||||
img_width = img.width
|
img_width = img.width
|
||||||
img_height = img.height
|
img_height = img.height
|
||||||
# save a second, smaller, version as a thumbnail
|
# save a second, smaller, version as a thumbnail
|
||||||
img.thumbnail((256, 256))
|
img.thumbnail((150, 150))
|
||||||
img.save(final_place_thumbnail, format="WebP", quality=93)
|
img.save(final_place_thumbnail, format="WebP", quality=93)
|
||||||
thumbnail_width = img.width
|
thumbnail_width = img.width
|
||||||
thumbnail_height = img.height
|
thumbnail_height = img.height
|
||||||
|
|
Loading…
Add table
Reference in a new issue