upload mp3

remotes/1693045480750635534/spooky-22
Aevann1 2022-05-25 01:26:50 +02:00
parent 4f02a72d29
commit b2de1dca52
2 changed files with 49 additions and 6 deletions

View File

@ -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")}')

View File

@ -394,16 +394,31 @@
<label class="text-black w-lg-25">Profile Anthem</label>
<div class="w-lg-100">
<p>Must be a youtube video link.</p>
<p>You can use an MP3 file or a YouTube video.</p>
<form action="/settings/song_change_mp3" method="post" enctype="multipart/form-data">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<label class="btn btn-secondary format d-inline-block m-0 mb-3">
<div id="filename-show2"><i class="fas fa-file"></i>
{% if v.song and v.song == v.id|string %}
{{v.id}}.mp3
{% else %}
Use an MP3 file (Max size is 8MB)
{% endif %}
</div>
<input autocomplete="off" id="file-upload2" type="file" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} accept="audio/mp3" onchange="this.form.submit()" hidden>
</label>
</form>
<form action="/settings/song_change" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input autocomplete="off" type="text" name="song" class="form-control" value="{% if v.song %}https://youtu.be/{{v.song}}{% endif %}" placeholder='Enter a youtube video link here'>
<br><small>In some browsers, users have to click at least once anywhere in the profile page for the anthem to play.</small>
<div class="d-flex mt-2">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Change Profile Anthem">
</div>
<input class="form-control" style="display:inline;max-width:75%;font-size: min(3.5vw,16px)!important" autocomplete="off" type="text" name="song" class="form-control" value="{% if v.song and v.song != v.id|string %}https://youtu.be/{{v.song}}{% endif %}" placeholder='Enter a YouTube video link here'>
<input class="btn btn-primary" style="margin-top:-5px" autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Submit">
</form>
<br><small>In some browsers, users have to click at least once anywhere in the profile page for the anthem to play.</small>
</div>
</div>