multiple file uploads & ui improvements #5

Manually merged
arian merged 4 commits from multi-uploads into main 2026-03-05 10:12:39 +00:00
5 changed files with 79 additions and 28 deletions
+1
View File
@@ -1,3 +1,4 @@
venv/
setup.sh
navidrome-upload.service
.idea/
+16 -28
View File
@@ -1,5 +1,5 @@
import os
from flask import Flask, flash, request, redirect
from flask import Flask, request, render_template
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = '/opt/navidrome/music'
@@ -15,34 +15,22 @@ def allowed_file(filename):
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('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 == '':
flash('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.config['UPLOAD_FOLDER'], filename))
# File saved successfully, return a success message
return f'''
<h1>File {filename} uploaded successfully</h1>
<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>
'''
return render_template('error.html', error_message='No file part in the request'), 400
files = request.files.getlist('file')
for file in files:
if file.filename == '':
return render_template('error.html', error_message='No selected file'), 400
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
else:
return render_template('error.html', error_message=f'File "{file.filename}" is not allowed. Allowed types: {", ".join(ALLOWED_EXTENSIONS)}'), 400
return render_template('success.html', success_message=f'{len(files)} file(s) uploaded successfully!')
return render_template('index.html')
if __name__ == '__main__':
app.run(host='192.168.2.24', port=5001, debug=False)
+20
View File
@@ -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>
+22
View File
@@ -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>
+20
View File
@@ -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>