Signed-off-by: Arian Nasr <arian@2ari.ca>
This commit was merged in pull request #21.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
# March 6, 2026
|
# March 6, 2026
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from flask import Flask, request, render_template
|
from flask import Flask, request, render_template, jsonify
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
UPLOAD_FOLDER = os.environ.get('NAVIDROME_MUSIC_FOLDER', '/opt/navidrome/music')
|
UPLOAD_FOLDER = os.environ.get('NAVIDROME_MUSIC_FOLDER', '/opt/navidrome/music')
|
||||||
@@ -25,13 +25,15 @@ def ping():
|
|||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def upload_file():
|
def upload_file():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
uploaded_count = 0
|
||||||
for key, file in request.files.items():
|
for key, file in request.files.items():
|
||||||
if key.startswith('file') and file and allowed_file(file.filename) and file.filename != '':
|
if key.startswith('file') and file and allowed_file(file.filename) and file.filename != '':
|
||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||||
|
uploaded_count += 1
|
||||||
else:
|
else:
|
||||||
return render_template('error.html', error_message=f'File is not allowed.'), 400
|
return jsonify({"error": f"File '{file.filename}' is not allowed or is empty."}), 400
|
||||||
|
|
||||||
return render_template('success.html', success_message=f'{len(request.files)} file(s) uploaded successfully!'), 200
|
return jsonify({"message": f"{uploaded_count} file(s) uploaded successfully!"}), 200
|
||||||
|
|
||||||
return render_template('index.html'), 200
|
return render_template('index.html'), 200
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
<!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>
|
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}" type="text/css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Error</h1>
|
|
||||||
<p>{{ error_message }}</p>
|
|
||||||
<a href="/"><button>Upload another file</button></a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<!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>
|
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}" type="text/css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Success</h1>
|
|
||||||
<p>{{ success_message }}</p>
|
|
||||||
<a href="/"><button>Upload another file</button></a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user