still about the file backup

This commit is contained in:
piair 2023-08-21 19:59:49 +02:00
parent 84b9c02a72
commit d2741e8c7a
2 changed files with 31 additions and 7 deletions

View File

@ -412,8 +412,28 @@ def download(filename):
print("file send !") print("file send !")
return send_from_directory(directory='/app/MsRewards-Reborn/user_data/', path=filename, as_attachment=True) return send_from_directory(directory='/app/MsRewards-Reborn/user_data/', path=filename, as_attachment=True)
ALLOWED_EXTENSIONS = [".json"]
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/upload_file/', methods=['POST'])
@login_required
def upload_file():
# check if the post request has the file part
if 'file' not in request.files:
print('No file part')
return redirect(request.url)
file = request.files['file']
# If the user does not select a file, the browser submits an
# empty file without a filename.
if file.filename == '':
print('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join('/app/MsRewards-Reborn/user_data/', filename))
return redirect(url_for('download_file', name=filename))
def maxi(dict): def maxi(dict):
m = 0 m = 0

View File

@ -64,12 +64,16 @@
<tr><td>logs viewer</td></tr> <tr><td>logs viewer</td></tr>
</table> </table>
</form> </form>
<h1>Backup config files</h1> <table>
<a href="/download/configs.json">download account config</a> <tr><h2>Backup config files</h2></tr>
<a href="/download/discord.json">download discord config</a> <tr><td><a href="/download/configs.json">download account config</a></td></tr>
<a href="/download/flask.json">download flask config</a> <tr><td><a href="/download/discord.json">download discord config</a></td></tr>
<a href="/download/proxy.json">download proxy config</a> <tr><td><a href="/download/flask.json">download flask config</a></td></tr>
<a href="/download/settings.json">download settings</a> <tr><td><a href="/download/proxy.json">download proxy config</a></td></tr>
<tr><td><a href="/download/settings.json">download settings</a></td></tr>
</table>
{% endif %} {% endif %}
{%endblock %} {%endblock %}