mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
only run 4chan filter in low quality communities
This commit is contained in:
parent
75e0231bd9
commit
6cf546facb
2 changed files with 7 additions and 7 deletions
|
@ -934,15 +934,15 @@ def post_json_to_model(activity_log, post_json, user, community) -> Post:
|
||||||
|
|
||||||
|
|
||||||
# Save two different versions of a File, after downloading it from file.source_url. Set a width parameter to None to avoid generating one of that size
|
# Save two different versions of a File, after downloading it from file.source_url. Set a width parameter to None to avoid generating one of that size
|
||||||
def make_image_sizes(file_id, thumbnail_width=50, medium_width=120, directory='posts'):
|
def make_image_sizes(file_id, thumbnail_width=50, medium_width=120, directory='posts', toxic_community=False):
|
||||||
if current_app.debug:
|
if current_app.debug:
|
||||||
make_image_sizes_async(file_id, thumbnail_width, medium_width, directory)
|
make_image_sizes_async(file_id, thumbnail_width, medium_width, directory, toxic_community)
|
||||||
else:
|
else:
|
||||||
make_image_sizes_async.apply_async(args=(file_id, thumbnail_width, medium_width, directory), countdown=randint(1, 10)) # Delay by up to 10 seconds so servers do not experience a stampede of requests all in the same second
|
make_image_sizes_async.apply_async(args=(file_id, thumbnail_width, medium_width, directory, toxic_community), countdown=randint(1, 10)) # Delay by up to 10 seconds so servers do not experience a stampede of requests all in the same second
|
||||||
|
|
||||||
|
|
||||||
@celery.task
|
@celery.task
|
||||||
def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory):
|
def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory, toxic_community):
|
||||||
file = File.query.get(file_id)
|
file = File.query.get(file_id)
|
||||||
if file and file.source_url:
|
if file and file.source_url:
|
||||||
# Videos
|
# Videos
|
||||||
|
@ -1068,7 +1068,7 @@ def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Alert regarding fascist meme content
|
# Alert regarding fascist meme content
|
||||||
if img_width < 2000: # images > 2000px tend to be real photos instead of 4chan screenshots.
|
if toxic_community and img_width < 2000: # images > 2000px tend to be real photos instead of 4chan screenshots.
|
||||||
try:
|
try:
|
||||||
image_text = pytesseract.image_to_string(Image.open(BytesIO(source_image)).convert('L'), timeout=30)
|
image_text = pytesseract.image_to_string(Image.open(BytesIO(source_image)).convert('L'), timeout=30)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -1858,7 +1858,7 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
if post.image_id:
|
if post.image_id:
|
||||||
make_image_sizes(post.image_id, 170, 512, 'posts') # the 512 sized image is for masonry view
|
make_image_sizes(post.image_id, 170, 512, 'posts', community.low_quality) # the 512 sized image is for masonry view
|
||||||
|
|
||||||
# Update list of cross posts
|
# Update list of cross posts
|
||||||
if post.url:
|
if post.url:
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Config(object):
|
||||||
RECAPTCHA_PUBLIC_KEY = os.environ.get("RECAPTCHA_PUBLIC_KEY") or None
|
RECAPTCHA_PUBLIC_KEY = os.environ.get("RECAPTCHA_PUBLIC_KEY") or None
|
||||||
RECAPTCHA_PRIVATE_KEY = os.environ.get("RECAPTCHA_PRIVATE_KEY") or None
|
RECAPTCHA_PRIVATE_KEY = os.environ.get("RECAPTCHA_PRIVATE_KEY") or None
|
||||||
MODE = os.environ.get('MODE') or 'development'
|
MODE = os.environ.get('MODE') or 'development'
|
||||||
LANGUAGES = ['de', 'en', 'fr', 'ja']
|
LANGUAGES = ['ca', 'de', 'en', 'fr', 'ja']
|
||||||
FULL_AP_CONTEXT = bool(int(os.environ.get('FULL_AP_CONTEXT', 0)))
|
FULL_AP_CONTEXT = bool(int(os.environ.get('FULL_AP_CONTEXT', 0)))
|
||||||
CACHE_TYPE = os.environ.get('CACHE_TYPE') or 'FileSystemCache'
|
CACHE_TYPE = os.environ.get('CACHE_TYPE') or 'FileSystemCache'
|
||||||
CACHE_REDIS_URL = os.environ.get('CACHE_REDIS_URL') or 'redis://localhost:6379/1'
|
CACHE_REDIS_URL = os.environ.get('CACHE_REDIS_URL') or 'redis://localhost:6379/1'
|
||||||
|
|
Loading…
Add table
Reference in a new issue