forked from MarseyWorld/MarseyWorld
fix mp3 songs
parent
c8a3a5a569
commit
ac6a71223d
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue