From eba4452d79d9578d2fe2b726bb62adee59c82fe9 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 18 Jun 2022 22:41:00 +0200 Subject: [PATCH] fix 500 error --- files/helpers/media.py | 8 ++++---- files/routes/comments.py | 10 +++++----- files/routes/posts.py | 6 +++--- files/routes/settings.py | 6 +++--- files/routes/subs.py | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/files/helpers/media.py b/files/helpers/media.py index 96329c6c8..feea19da8 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -3,7 +3,7 @@ from PIL.ImageSequence import Iterator from webptools import gifwebp import subprocess import os -from flask import abort +from flask import abort, g import requests import time from .const import * @@ -17,7 +17,7 @@ def process_files(): if file.content_type.startswith('image/'): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - url = process_image(v.patron, name) + url = process_image(name) body += f"\n\n![]({url})" elif file.content_type.startswith('video/'): body += f"\n\n{process_video(file)}" @@ -69,10 +69,10 @@ def process_video(file): return f'{SITE_FULL}{new}' -def process_image(patron, filename=None, resize=0): +def process_image(filename=None, resize=0): size = os.stat(filename).st_size - if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024: + if size > 16 * 1024 * 1024 or not g.v.patron and size > 8 * 1024 * 1024: os.remove(filename) abort(413) diff --git a/files/routes/comments.py b/files/routes/comments.py index 136a0790b..e1000cdb8 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -219,7 +219,7 @@ def api_comment(v): if file.content_type.startswith('image/'): oldname = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(oldname) - image = process_image(v.patron, oldname) + image = process_image(oldname) if image == "": return {"error":"Image upload failed"} if v.admin_level > 2 and level == 1: if parent_post.id == 37696: @@ -228,14 +228,14 @@ def api_comment(v): num = int(li.split('.webp')[0]) + 1 filename = f'files/assets/images/{SITE_NAME}/sidebar/{num}.webp' copyfile(oldname, filename) - process_image(v.patron, filename, 400) + process_image(filename, 400) elif parent_post.id == 37697: li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/banners'), key=lambda e: int(e.split('.webp')[0]))[-1] num = int(li.split('.webp')[0]) + 1 filename = f'files/assets/images/{SITE_NAME}/banners/{num}.webp' copyfile(oldname, filename) - process_image(v.patron, filename) + process_image(filename) elif parent_post.id == 37833: try: badge_def = loads(body) @@ -249,7 +249,7 @@ def api_comment(v): g.db.flush() filename = f'files/assets/images/badges/{badge.id}.webp' copyfile(oldname, filename) - process_image(v.patron, filename, 200) + process_image(filename, 200) requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data=f'{{"files": ["https://{request.host}/assets/images/badges/{badge.id}.webp"]}}', timeout=5) except Exception as e: @@ -272,7 +272,7 @@ def api_comment(v): filename = f'files/assets/images/emojis/{name}.webp' copyfile(oldname, filename) - process_image(v.patron, filename, 200) + process_image(filename, 200) marsey = Marsey(name=name, author_id=user.id, tags=tags, count=0) g.db.add(marsey) diff --git a/files/routes/posts.py b/files/routes/posts.py index 4df142905..0d6bc28e4 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -701,7 +701,7 @@ def thumbnail_thread(pid): for chunk in image_req.iter_content(1024): file.write(chunk) - post.thumburl = process_image(0, name, resize=100) + post.thumburl = process_image(name, resize=100) db.add(post) db.commit() db.close() @@ -1054,11 +1054,11 @@ def submit_post(v, sub=None): if file.content_type.startswith('image/'): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - post.url = process_image(v.patron, name) + post.url = process_image(name) name2 = name.replace('.webp', 'r.webp') copyfile(name, name2) - post.thumburl = process_image(v.patron, name2, resize=100) + post.thumburl = process_image(name2, resize=100) elif file.content_type.startswith('video/'): post.url = process_video(file) elif file.content_type.startswith('audio/'): diff --git a/files/routes/settings.py b/files/routes/settings.py index ef2dac2f9..eb7118f84 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -543,13 +543,13 @@ def settings_images_profile(v): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - highres = process_image(v.patron, name) + highres = process_image(name) if not highres: abort(400) name2 = name.replace('.webp', 'r.webp') copyfile(name, name2) - imageurl = process_image(v.patron, name2, resize=100) + imageurl = process_image(name2, resize=100) if not imageurl: abort(400) @@ -579,7 +579,7 @@ def settings_images_banner(v): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - bannerurl = process_image(v.patron, name) + bannerurl = process_image(name) if bannerurl: if v.bannerurl and '/images/' in v.bannerurl: diff --git a/files/routes/subs.py b/files/routes/subs.py index 3a13719d5..20e1d6ae2 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -403,7 +403,7 @@ def sub_banner(v, sub): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - bannerurl = process_image(v.patron, name) + bannerurl = process_image(name) if bannerurl: if sub.bannerurl and '/images/' in sub.bannerurl: @@ -430,7 +430,7 @@ def sub_sidebar(v, sub): file = request.files["sidebar"] name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - sidebarurl = process_image(v.patron, name) + sidebarurl = process_image(name) if sidebarurl: if sub.sidebarurl and '/images/' in sub.sidebarurl: