From b2de1dca527a22928fccb625027211b88291deba Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 25 May 2022 01:26:50 +0200 Subject: [PATCH] upload mp3 --- files/routes/settings.py | 28 +++++++++++++++++++++++++++ files/templates/settings_profile.html | 27 ++++++++++++++++++++------ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/files/routes/settings.py b/files/routes/settings.py index b1c1ae5e59..927e5afe77 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -787,6 +787,34 @@ def settings_name_change(v): return redirect("/settings/profile") + + +@app.post("/settings/song_change_mp3") +@limiter.limit("3/second;10/day") +@limiter.limit("3/second;10/day", key_func=lambda:f'{request.host}-{session.get("lo_user")}') +@auth_required +def settings_song_change_mp3(v): + + file = request.files['file'] + if file.content_type != 'audio/mpeg': + return render_template("settings_profile.html", v=v, error="Not a valid MP3 file") + + name = f'/songs/{v.id}.mp3' + file.save(name) + + size = os.stat(name).st_size + if size > 8 * 1024 * 1024: + os.remove(name) + return render_template("settings_profile.html", v=v, error="MP3 file must be smaller than 8MB") + + v.song = v.id + g.db.add(v) + g.db.commit() + + return redirect("/settings/profile") + + + @app.post("/settings/song_change") @limiter.limit("3/second;10/day") @limiter.limit("3/second;10/day", key_func=lambda:f'{request.host}-{session.get("lo_user")}') diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index f3e4604006..616c4c04b9 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -394,16 +394,31 @@
-

Must be a youtube video link.

+

You can use an MP3 file or a YouTube video.

+ +
+ + +
- -
In some browsers, users have to click at least once anywhere in the profile page for the anthem to play. -
- -
+ + + +
+ +
In some browsers, users have to click at least once anywhere in the profile page for the anthem to play.