From 6cf546facb652d435f9b99ed7acb103a8708fd68 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:28:10 +1200 Subject: [PATCH] only run 4chan filter in low quality communities --- app/activitypub/util.py | 12 ++++++------ config.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 4cf40b4a..310af7e0 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -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 -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: - 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: - 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 -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) if file and file.source_url: # Videos @@ -1068,7 +1068,7 @@ def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory): db.session.commit() # 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: image_text = pytesseract.image_to_string(Image.open(BytesIO(source_image)).convert('L'), timeout=30) except Exception as e: @@ -1858,7 +1858,7 @@ def create_post(activity_log: ActivityPubLog, community: Community, request_json db.session.commit() 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 if post.url: diff --git a/config.py b/config.py index 7156b781..504663f2 100644 --- a/config.py +++ b/config.py @@ -22,7 +22,7 @@ class Config(object): RECAPTCHA_PUBLIC_KEY = os.environ.get("RECAPTCHA_PUBLIC_KEY") or None RECAPTCHA_PRIVATE_KEY = os.environ.get("RECAPTCHA_PRIVATE_KEY") or None 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))) CACHE_TYPE = os.environ.get('CACHE_TYPE') or 'FileSystemCache' CACHE_REDIS_URL = os.environ.get('CACHE_REDIS_URL') or 'redis://localhost:6379/1'