web interface support update multiple files at a time
This commit is contained in:
parent
23a0a1ce0d
commit
56036d8736
70
interface.py
70
interface.py
@ -255,47 +255,49 @@ def post():
|
||||
|
||||
@web.route('/upload', methods=["POST"])
|
||||
def upload():
|
||||
file = request.files['file']
|
||||
if not file:
|
||||
files = request.files.getlist("file[]")
|
||||
if not files:
|
||||
return redirect("./", code=406)
|
||||
|
||||
#filename = secure_filename(file.filename).strip()
|
||||
filename = file.filename
|
||||
if filename == '':
|
||||
return redirect("./", code=406)
|
||||
|
||||
targetdir = request.form['targetdir'].strip()
|
||||
if targetdir == '':
|
||||
targetdir = 'uploads/'
|
||||
elif '../' in targetdir:
|
||||
return redirect("./", code=406)
|
||||
|
||||
logging.info('Uploading file:')
|
||||
logging.info(' - filename: ' + filename)
|
||||
logging.info(' - targetdir: ' + targetdir)
|
||||
logging.info(' - mimetype: ' + file.mimetype)
|
||||
|
||||
if "audio" in file.mimetype:
|
||||
storagepath = os.path.abspath(os.path.join(var.music_folder, targetdir))
|
||||
print('storagepath:',storagepath)
|
||||
if not storagepath.startswith(os.path.abspath(var.music_folder)):
|
||||
for file in files:
|
||||
filename = file.filename
|
||||
if filename == '':
|
||||
return redirect("./", code=406)
|
||||
|
||||
try:
|
||||
os.makedirs(storagepath)
|
||||
except OSError as ee:
|
||||
if ee.errno != errno.EEXIST:
|
||||
return redirect("./", code=500)
|
||||
|
||||
filepath = os.path.join(storagepath, filename)
|
||||
logging.info(' - filepath: ' + filepath)
|
||||
if os.path.exists(filepath):
|
||||
targetdir = request.form['targetdir'].strip()
|
||||
if targetdir == '':
|
||||
targetdir = 'uploads/'
|
||||
elif '../' in targetdir:
|
||||
return redirect("./", code=406)
|
||||
|
||||
file.save(filepath)
|
||||
return redirect("./", code=302)
|
||||
else:
|
||||
return redirect("./", code=409)
|
||||
logging.info('Uploading file:')
|
||||
logging.info(' - filename: ' + filename)
|
||||
logging.info(' - targetdir: ' + targetdir)
|
||||
logging.info(' - mimetype: ' + file.mimetype)
|
||||
|
||||
if "audio" in file.mimetype:
|
||||
storagepath = os.path.abspath(os.path.join(var.music_folder, targetdir))
|
||||
print('storagepath:',storagepath)
|
||||
if not storagepath.startswith(os.path.abspath(var.music_folder)):
|
||||
return redirect("./", code=406)
|
||||
|
||||
try:
|
||||
os.makedirs(storagepath)
|
||||
except OSError as ee:
|
||||
if ee.errno != errno.EEXIST:
|
||||
return redirect("./", code=500)
|
||||
|
||||
filepath = os.path.join(storagepath, filename)
|
||||
logging.info(' - filepath: ' + filepath)
|
||||
if os.path.exists(filepath):
|
||||
return redirect("./", code=406)
|
||||
|
||||
file.save(filepath)
|
||||
else:
|
||||
return redirect("./", code=409)
|
||||
|
||||
return redirect("./", code=302)
|
||||
|
||||
|
||||
@web.route('/download', methods=["GET"])
|
||||
|
@ -207,25 +207,29 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="./upload" method="post" enctype="multipart/form-data">
|
||||
<div class="input-group">
|
||||
<div class="custom-file btn-space">
|
||||
<input type="file" name="file" class="custom-file-input" id="uploadSelectFile"
|
||||
aria-describedby="uploadSubmit" value="Browse Music file" />
|
||||
<label class="custom-file-label" for="uploadSelectFile">Choose file</label>
|
||||
<div class="row" style="margin-bottom: 5px;">
|
||||
<div id="uploadBox" class="col-lg-8 input-group">
|
||||
<div id="uploadField" style="display: flex; width: 100%">
|
||||
<div class="custom-file btn-space">
|
||||
<input type="file" name="file[]" class="custom-file-input" id="uploadSelectFile"
|
||||
aria-describedby="uploadSubmit" value="Browse Music file" multiple/>
|
||||
<label class="custom-file-label" for="uploadSelectFile">Choose file</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group-append">
|
||||
<div class="col-lg-4 input-group-append">
|
||||
<span class="input-group-text">Upload To</span>
|
||||
<input class="form-control btn-space" list="targetdirs" id="targetdir" name="targetdir"
|
||||
placeholder="uploads" />
|
||||
placeholder="uploads" />
|
||||
<datalist id="targetdirs">
|
||||
<option value="uploads">
|
||||
{% for dir in music_library.get_subdirs_recursively() %}
|
||||
<option value="{{ dir }}">
|
||||
<option value="{{ dir }}">
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
|
||||
<button class="btn btn-outline-secondary" type="submit"
|
||||
id="uploadSubmit">Upload</button>
|
||||
id="uploadSubmit">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user