From e649ffa56d060d0e5ae5dbd7fe2bdef5eec584f4 Mon Sep 17 00:00:00 2001 From: Arian Nasr Date: Wed, 4 Mar 2026 02:22:31 -0500 Subject: [PATCH 1/3] multi-file uploads --- .gitignore | 1 + main.py | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 091fc37..1814433 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ venv/ setup.sh navidrome-upload.service +.idea/ \ No newline at end of file diff --git a/main.py b/main.py index a305940..9fe4c38 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import os -from flask import Flask, flash, request, redirect +from flask import Flask, request from werkzeug.utils import secure_filename UPLOAD_FOLDER = '/opt/navidrome/music' @@ -15,31 +15,31 @@ 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''' -

File {filename} uploaded successfully

- - ''', 200 + return 'No file part', 400 + files = request.files.getlist('file') + for file in files: + if file.filename == '': + return '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 'File extension not allowed', 400 + return f''' + + Upload successful +

{len(files)} file(s) uploaded successfully

+ + ''', 200 + return ''' Upload new File

Upload new File

- +
''' From 2291e087bd1b7353630cccf94415524210f96760 Mon Sep 17 00:00:00 2001 From: Arian Nasr Date: Thu, 5 Mar 2026 00:32:35 -0500 Subject: [PATCH 2/3] relative path for redir. --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9fe4c38..bb125c9 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,7 @@ def upload_file(): Upload successful

{len(files)} file(s) uploaded successfully

- + ''', 200 return ''' From 9045434dca2e843a73d22d862e7705be1d282bdf Mon Sep 17 00:00:00 2001 From: Arian Nasr Date: Thu, 5 Mar 2026 04:50:46 -0500 Subject: [PATCH 3/3] improved UI & templating --- main.py | 28 ++++++++-------------------- templates/error.html | 20 ++++++++++++++++++++ templates/index.html | 22 ++++++++++++++++++++++ templates/success.html | 20 ++++++++++++++++++++ 4 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 templates/error.html create mode 100644 templates/index.html create mode 100644 templates/success.html diff --git a/main.py b/main.py index bb125c9..6b249e2 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import os -from flask import Flask, request +from flask import Flask, request, render_template from werkzeug.utils import secure_filename UPLOAD_FOLDER = '/opt/navidrome/music' @@ -16,33 +16,21 @@ def allowed_file(filename): def upload_file(): if request.method == 'POST': if 'file' not in request.files: - return 'No file part', 400 + 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 'No selected file', 400 + 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 'File extension not allowed', 400 - return f''' - - Upload successful -

{len(files)} file(s) uploaded successfully

- - ''', 200 + 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') - return ''' - - Upload new File - -

Upload new File

-
- - -
- ''' if __name__ == '__main__': app.run(host='192.168.2.24', port=5001, debug=False) diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..530cc3c --- /dev/null +++ b/templates/error.html @@ -0,0 +1,20 @@ + + + + + + Error - Upload Music + + + + +

Error

+

{{ error_message }}

+ + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..1f49f62 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,22 @@ + + + + + + Upload Music + + + + +

Upload new File

+
+ + +
+ + \ No newline at end of file diff --git a/templates/success.html b/templates/success.html new file mode 100644 index 0000000..2c6e569 --- /dev/null +++ b/templates/success.html @@ -0,0 +1,20 @@ + + + + + + Success - Upload Music + + + + +

Success

+

{{ success_message }}

+ + + \ No newline at end of file