diff --git a/files/__main__.py b/files/__main__.py index 3b23e206a..ced14b7a2 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -75,7 +75,8 @@ if not path.isfile(f'/site_settings.json'): @app.before_request def before_request(): - app.config['SESSION_COOKIE_DOMAIN'] = f'.{request.host}' + if SITE != 'localhost': + app.config['SESSION_COOKIE_DOMAIN'] = f'.{request.host}' if request.host == 'marsey.world' and request.path != '/kofi': abort(404) diff --git a/files/assets/images/hats/A Beautiful Mind.webp b/files/assets/images/hats/A Beautiful Mind.webp index 0c79a5d9b..f0414367b 100644 Binary files a/files/assets/images/hats/A Beautiful Mind.webp and b/files/assets/images/hats/A Beautiful Mind.webp differ diff --git a/files/assets/images/hats/Roulette.webp b/files/assets/images/hats/Roulette.webp index bd644eb56..f2ae4def3 100644 Binary files a/files/assets/images/hats/Roulette.webp and b/files/assets/images/hats/Roulette.webp differ diff --git a/files/assets/images/hats/Yolo swag 420 rekt.webp b/files/assets/images/hats/Yolo swag 420 rekt.webp index 61126d0f9..eb0f5b1c3 100644 Binary files a/files/assets/images/hats/Yolo swag 420 rekt.webp and b/files/assets/images/hats/Yolo swag 420 rekt.webp differ diff --git a/files/helpers/media.py b/files/helpers/media.py index 28ba9d15c..5cccc4323 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -154,36 +154,32 @@ def process_image(filename=None, resize=0, trim=False, uploader=None, patron=Fal i.save(filename, format="WEBP", method=6, quality=88) - if resize in (300,400,1200): + if resize: if os.stat(filename).st_size > MAX_IMAGE_SIZE_BANNER_RESIZED_KB * 1024: os.remove(filename) abort(413, f"Max size for banners, sidebars, and badges is {MAX_IMAGE_SIZE_BANNER_RESIZED_KB} KB") - if resize == 1200: - path = f'files/assets/images/{SITE_NAME}/banners' - elif resize == 400: - path = f'files/assets/images/{SITE_NAME}/sidebar' - else: - path = f'files/assets/images/badges' + if filename.startswith('files/assets/images/'): + path = filename.rsplit('/', 1)[0] - hashes = {} + hashes = {} - for img in os.listdir(path): - if resize == 400 and img in ('256.webp','585.webp'): continue - img_path = f'{path}/{img}' - if img_path == filename: continue - img = Image.open(img_path) - i_hash = str(imagehash.phash(img)) + for img in os.listdir(path): + if resize == 400 and img in ('256.webp','585.webp'): continue + img_path = f'{path}/{img}' + if img_path == filename: continue + img = Image.open(img_path) + i_hash = str(imagehash.phash(img)) + if i_hash in hashes.keys(): + print(hashes[i_hash], flush=True) + print(img_path, flush=True) + else: hashes[i_hash] = img_path + + i = Image.open(filename) + i_hash = str(imagehash.phash(i)) if i_hash in hashes.keys(): - print(hashes[i_hash], flush=True) - print(img_path, flush=True) - else: hashes[i_hash] = img_path - - i = Image.open(filename) - i_hash = str(imagehash.phash(i)) - if i_hash in hashes.keys(): - os.remove(filename) - abort(409, "Image already exists!") + os.remove(filename) + abort(409, "Image already exists!") db = db or g.db diff --git a/files/routes/admin.py b/files/routes/admin.py index 393db7281..c6fcdc867 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -843,7 +843,7 @@ def agendaposter(user_id, v): g.db.add(user) if days: - days_txt = str(days).rstrip('.0') + days_txt = str(days).split('.0')[0] note = f"for {days_txt} days" else: note = "permanently" @@ -1013,7 +1013,7 @@ def ban_user(user_id, v): duration = "permanently" if days: - days_txt = str(days).rstrip('.0') + days_txt = str(days).split('.0')[0] duration = f"for {days_txt} day" if days != 1: duration += "s" if reason: text = f"@{v.username} (Admin) has banned you for **{days_txt}** days for the following reason:\n\n> {reason}" diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index e63b12f44..fcef24e59 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -244,7 +244,7 @@ if SITE not in ('pcmemes.net', 'watchpeopledie.tv'): filename = f'/asset_submissions/hats/{name}.webp' copyfile(highquality, filename) - process_image(filename) + process_image(filename, resize=100) hat = HatDef(name=name, author_id=author.id, description=description, price=price, submitter_id=v.id) g.db.add(hat) @@ -451,7 +451,7 @@ if SITE not in ('pcmemes.net', 'watchpeopledie.tv'): filename = f"files/assets/images/hats/{name}.webp" copyfile(new_path, filename) - process_image(filename) + process_image(filename, resize=100) purge_files_in_cache([f"https://{SITE}/i/hats/{name}.webp", f"https://{SITE}/assets/images/hats/{name}.webp", f"https://{SITE}/asset_submissions/hats/original/{name}.{format}"]) ma = ModAction( kind="update_hat", diff --git a/files/routes/subs.py b/files/routes/subs.py index 6141e2088..41f04b29c 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -480,7 +480,7 @@ def sub_banner(v, sub): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - bannerurl = process_image(name, patron=v.patron) + bannerurl = process_image(name, patron=v.patron, resize=1200) if bannerurl: if sub.bannerurl and '/images/' in sub.bannerurl: @@ -512,7 +512,7 @@ def sub_sidebar(v, sub): file = request.files["sidebar"] name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - sidebarurl = process_image(name, patron=v.patron) + sidebarurl = process_image(name, patron=v.patron, resize=400) if sidebarurl: if sub.sidebarurl and '/images/' in sub.sidebarurl: @@ -544,7 +544,7 @@ def sub_marsey(v, sub): file = request.files["marsey"] name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - marseyurl = process_image(name, patron=v.patron) + marseyurl = process_image(name, patron=v.patron, resize=200) if marseyurl: if sub.marseyurl and '/images/' in sub.marseyurl: