From 96f4f8499fa72f0eaabb0bcbb62145ef5aa37e36 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 6 Oct 2022 09:30:38 +0200 Subject: [PATCH] fix 500 errors --- files/helpers/media.py | 6 +++--- files/routes/comments.py | 2 +- files/routes/posts.py | 2 +- files/routes/settings.py | 4 ++-- files/routes/subs.py | 6 +++--- sql/20221006-media-table.sql | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/files/helpers/media.py b/files/helpers/media.py index de077294a..db856d8af 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -21,7 +21,7 @@ def process_files(): if file.content_type.startswith('image/'): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - url = process_image(name) + url = process_image(name, patron=g.v.patron) body += f"\n\n![]({url})" elif file.content_type.startswith('video/'): body += f"\n\n{process_video(file)}" @@ -112,10 +112,10 @@ def process_video(file): -def process_image(filename=None, resize=0, trim=False): +def process_image(filename=None, resize=0, trim=False, patron=False): size = os.stat(filename).st_size - if size > 16 * 1024 * 1024 or not g.v.patron and size > 8 * 1024 * 1024: + if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024: os.remove(filename) abort(413) diff --git a/files/routes/comments.py b/files/routes/comments.py index 666059d5f..86d46861c 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -194,7 +194,7 @@ def comment(v): if file.content_type.startswith('image/'): oldname = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(oldname) - image = process_image(oldname) + image = process_image(oldname, patron=v.patron) if image == "": return {"error":"Image upload failed"}, 400 if v.admin_level > 2 and level == 1: if parent_post.id == SIDEBAR_THREAD: diff --git a/files/routes/posts.py b/files/routes/posts.py index 654cb8dcc..09b50bfc5 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -949,7 +949,7 @@ 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(name) + post.url = process_image(name, patron=v.patron) name2 = name.replace('.webp', 'r.webp') copyfile(name, name2) diff --git a/files/routes/settings.py b/files/routes/settings.py index 92bd7476f..c7a036c72 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -518,7 +518,7 @@ def settings_images_profile(v): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - highres = process_image(name) + highres = process_image(name, patron=v.patron) if not highres: abort(400) @@ -556,7 +556,7 @@ def settings_images_banner(v): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - bannerurl = process_image(name) + bannerurl = process_image(name, patron=v.patron) if bannerurl: if v.bannerurl and '/images/' in v.bannerurl: diff --git a/files/routes/subs.py b/files/routes/subs.py index 2fcee35e0..ad40ef5ff 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -486,7 +486,7 @@ def sub_banner(v, sub): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - bannerurl = process_image(name) + bannerurl = process_image(name, patron=v.patron) if bannerurl: if sub.bannerurl and '/images/' in sub.bannerurl: @@ -518,7 +518,7 @@ def sub_sidebar(v, sub): file = request.files["sidebar"] name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - sidebarurl = process_image(name) + sidebarurl = process_image(name, patron=v.patron) if sidebarurl: if sub.sidebarurl and '/images/' in sub.sidebarurl: @@ -550,7 +550,7 @@ def sub_marsey(v, sub): file = request.files["marsey"] name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - marseyurl = process_image(name) + marseyurl = process_image(name, patron=v.patron) if marseyurl: if sub.marseyurl and '/images/' in sub.marseyurl: diff --git a/sql/20221006-media-table.sql b/sql/20221006-media-table.sql index 6db368af3..fa0dc4f4d 100644 --- a/sql/20221006-media-table.sql +++ b/sql/20221006-media-table.sql @@ -1,6 +1,6 @@ CREATE TABLE public.media ( kind character varying(5) NOT NULL, - filename character varying(23) NOT NULL, + filename character varying(55) NOT NULL, user_id Integer NOT NULL, created_utc integer NOT NULL, size integer NOT NULL