From 6d808bd006254014b6cff2d129c26c580a51aac4 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 6 Aug 2023 04:20:14 +0300 Subject: [PATCH] deal with 500 error --- files/helpers/media.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/files/helpers/media.py b/files/helpers/media.py index a87c717eb..1eae2b69e 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -82,6 +82,9 @@ def process_audio(file, v): abort(413, f"Max image/audio size is {MAX_IMAGE_AUDIO_SIZE_MB} MB ({MAX_IMAGE_AUDIO_SIZE_MB_PATRON} MB for {patron.lower()}s)") extension = guess_extension(file.content_type) + if not extension: + os.remove(old) + abort(400) new = old + extension try: @@ -138,6 +141,9 @@ def process_video(file, v): abort(413, f"Max video size is {MAX_VIDEO_SIZE_MB} MB ({MAX_VIDEO_SIZE_MB_PATRON} MB for {patron}s)") extension = guess_extension(file.content_type) + if not extension: + os.remove(old) + abort(400) new = old + extension if extension != '.mp4':