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