multiple file uploads & ui improvements #5
@@ -1,3 +1,4 @@
|
|||||||
venv/
|
venv/
|
||||||
setup.sh
|
setup.sh
|
||||||
navidrome-upload.service
|
navidrome-upload.service
|
||||||
|
.idea/
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask, flash, request, redirect
|
from flask import Flask, request, render_template
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
UPLOAD_FOLDER = '/opt/navidrome/music'
|
UPLOAD_FOLDER = '/opt/navidrome/music'
|
||||||
@@ -15,34 +15,22 @@ def allowed_file(filename):
|
|||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def upload_file():
|
def upload_file():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# check if the post request has the file part
|
|
||||||
if 'file' not in request.files:
|
if 'file' not in request.files:
|
||||||
flash('No file part')
|
return render_template('error.html', error_message='No file part in the request'), 400
|
||||||
return redirect(request.url)
|
files = request.files.getlist('file')
|
||||||
file = request.files['file']
|
for file in files:
|
||||||
# If the user does not select a file, the browser submits an
|
if file.filename == '':
|
||||||
# empty file without a filename.
|
return render_template('error.html', error_message='No selected file'), 400
|
||||||
if file.filename == '':
|
if file and allowed_file(file.filename):
|
||||||
flash('No selected file')
|
filename = secure_filename(file.filename)
|
||||||
return redirect(request.url)
|
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||||
if file and allowed_file(file.filename):
|
else:
|
||||||
filename = secure_filename(file.filename)
|
return render_template('error.html', error_message=f'File "{file.filename}" is not allowed. Allowed types: {", ".join(ALLOWED_EXTENSIONS)}'), 400
|
||||||
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
|
||||||
# File saved successfully, return a success message
|
return render_template('success.html', success_message=f'{len(files)} file(s) uploaded successfully!')
|
||||||
return f'''
|
|
||||||
<h1>File {filename} uploaded successfully</h1>
|
return render_template('index.html')
|
||||||
<a href="{request.url}"><button>Upload another file</button></a>
|
|
||||||
''', 200
|
|
||||||
return '''
|
|
||||||
<!doctype html>
|
|
||||||
<title>Upload new File</title>
|
|
||||||
<button onclick="window.location.href='/outpost.goauthentik.io/sign_out'">Logout</button>
|
|
||||||
<h1>Upload new File</h1>
|
|
||||||
<form method=post enctype=multipart/form-data>
|
|
||||||
<input type=file name=file>
|
|
||||||
<input type=submit value=Upload>
|
|
||||||
</form>
|
|
||||||
'''
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='192.168.2.24', port=5001, debug=False)
|
app.run(host='192.168.2.24', port=5001, debug=False)
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Error - Upload Music</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #2B2726;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<button onclick="window.location.href='/outpost.goauthentik.io/sign_out'">Logout</button>
|
||||||
|
<h1>Error</h1>
|
||||||
|
<p>{{ error_message }}</p>
|
||||||
|
<a href="/"><button>Upload another file</button></a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Upload Music</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #2B2726;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<button onclick="window.location.href='/outpost.goauthentik.io/sign_out'">Logout</button>
|
||||||
|
<h1>Upload new File</h1>
|
||||||
|
<form method=post enctype=multipart/form-data>
|
||||||
|
<input type=file name=file multiple>
|
||||||
|
<input type=submit value=Upload>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Success - Upload Music</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #2B2726;
|
||||||
|
color: #FFFFFF;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<button onclick="window.location.href='/outpost.goauthentik.io/sign_out'">Logout</button>
|
||||||
|
<h1>Success</h1>
|
||||||
|
<p>{{ success_message }}</p>
|
||||||
|
<a href="/"><button>Upload another file</button></a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user