From ac6a71223d9fdeb0164f17a20bcceebda4833e22 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 17 Sep 2023 23:14:41 +0300 Subject: [PATCH] fix mp3 songs --- files/helpers/get.py | 6 ++++++ files/helpers/media.py | 6 ++++-- files/routes/settings.py | 11 ++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/files/helpers/get.py b/files/helpers/get.py index cb55cb16f..eacf5cc2a 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -339,6 +339,12 @@ def get_profile_picture(identifier): return x.profile_url if x else 'not_found' +def get_msg(): + if request.referrer and request.referrer.split('?')[0] == request.base_url: + return request.values.get("msg") + else: + return None + def get_error(): if request.referrer and request.referrer.split('?')[0] == request.base_url: return request.values.get("error") diff --git a/files/helpers/media.py b/files/helpers/media.py index f3ebf64de..92f6b792a 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -74,8 +74,10 @@ def process_files(files, v, body, is_dm=False, dm_user=None): return body.replace('\n ', '\n') -def process_audio(file, v): - old = f'/audio/{time.time()}'.replace('.','') +def process_audio(file, v, old): + if not old: + old = f'/audio/{time.time()}'.replace('.','') + file.save(old) size = os.stat(old).st_size diff --git a/files/routes/settings.py b/files/routes/settings.py index 5e6292020..fcd27ba7d 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -38,7 +38,7 @@ def settings(v): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required def settings_personal(v): - return render_template("settings/personal.html", v=v, error=get_error()) + return render_template("settings/personal.html", v=v, msg=get_msg(), error=get_error()) @app.post('/settings/remove_background') @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @@ -775,14 +775,7 @@ def settings_song_change_mp3(v): song = str(time.time()).replace('.','') - name = f'/songs/{song}.mp3' - file.save(name) - process_audio(file, v) #to ensure not malware - - size = os.stat(name).st_size - if size > 8 * 1024 * 1024: - os.remove(name) - return redirect("/settings/personal?error=MP3 file must be smaller than 8MB") + process_audio(file, v, f'/songs/{song}') #to ensure not malware if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: os.remove(f"/songs/{v.song}.mp3")