fix mp3 songs getting cached

master
Aevann1 2022-07-10 17:43:27 +02:00
parent a26f2656aa
commit fecaed8223
2 changed files with 10 additions and 5 deletions

View File

@ -761,7 +761,9 @@ def settings_song_change_mp3(v):
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'
song = str(time.time()).replace('.','')
name = f'/songs/{song}.mp3'
file.save(name)
size = os.stat(name).st_size
@ -769,7 +771,10 @@ def settings_song_change_mp3(v):
os.remove(name)
return render_template("settings_profile.html", v=v, error="MP3 file must be smaller than 8MB")
v.song = v.id
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")
v.song = song
g.db.add(v)
return redirect("/settings/profile")

View File

@ -400,8 +400,8 @@
<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
{% if v.song and v.song|length == 17 %}
{{v.song}}.mp3
{% else %}
Use an MP3 file (Max size is 8MB)
{% endif %}
@ -413,7 +413,7 @@
<form action="/settings/song_change" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<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="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|length != 17 %}https://youtu.be/{{v.song}}{% endif %}" placeholder='Enter a YouTube video link here'>
<input class="btn btn-primary" style="font-size: min(3.5vw,16px)!important" autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Submit">
</form>