impl multiCollapse and fileupload
This commit is contained in:
13
interface.py
13
interface.py
@@ -122,6 +122,7 @@ def index():
|
|||||||
user=var.user)
|
user=var.user)
|
||||||
|
|
||||||
|
|
||||||
|
@web.route('/upload', methods=["POST"])
|
||||||
def upload():
|
def upload():
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
if not file:
|
if not file:
|
||||||
@@ -137,14 +138,15 @@ def upload():
|
|||||||
elif '../' in targetdir:
|
elif '../' in targetdir:
|
||||||
return redirect("./", code=406)
|
return redirect("./", code=406)
|
||||||
|
|
||||||
# print('Uploading file:')
|
print('Uploading file:')
|
||||||
# print('filename:', filename)
|
print('filename:', filename)
|
||||||
# print('targetdir:', targetdir)
|
print('targetdir:', targetdir)
|
||||||
# print('mimetype:', file.mimetype)
|
print('mimetype:', file.mimetype)
|
||||||
|
|
||||||
if "audio" in file.mimetype:
|
if "audio" in file.mimetype:
|
||||||
storagepath = os.path.abspath(os.path.join(var.music_folder, targetdir))
|
storagepath = os.path.abspath(os.path.join(var.music_folder, targetdir))
|
||||||
if not storagepath.startswith(var.music_folder):
|
print('storagepath:',storagepath)
|
||||||
|
if not storagepath.startswith(os.path.abspath(var.music_folder)):
|
||||||
return redirect("./", code=406)
|
return redirect("./", code=406)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -154,6 +156,7 @@ def upload():
|
|||||||
return redirect("./", code=500)
|
return redirect("./", code=500)
|
||||||
|
|
||||||
filepath = os.path.join(storagepath, filename)
|
filepath = os.path.join(storagepath, filename)
|
||||||
|
print('filepath:',filepath)
|
||||||
if os.path.exists(filepath):
|
if os.path.exists(filepath):
|
||||||
return redirect("./", code=406)
|
return redirect("./", code=406)
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for subdirname, subdirobj in dir.get_subdirs().items() %}
|
{% for subdirname, subdirobj in dir.get_subdirs().items() %}
|
||||||
{%- set subdirpath = os.path.relpath(subdirobj.fullpath, music_library.fullpath) %}
|
{%- set subdirpath = os.path.relpath(subdirobj.fullpath, music_library.fullpath) %}
|
||||||
|
{%- set subdirid = subdirpath.replace("/","-") %}
|
||||||
<li class="directory list-group-item list-group-item-primary">
|
<li class="directory list-group-item list-group-item-primary">
|
||||||
<span>{{ subdirpath }}/ </span>
|
<span>{{ subdirpath }}/ </span>
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
@@ -17,9 +18,14 @@
|
|||||||
<input type="text" value="{{ subdirpath }}" name="directory" hidden>
|
<input type="text" value="{{ subdirpath }}" name="directory" hidden>
|
||||||
<button type="submit" class="btn btn-secondary">Download entire directory</button>
|
<button type="submit" class="btn btn-secondary">Download entire directory</button>
|
||||||
</form>
|
</form>
|
||||||
|
<button class="btn btn-primary" type="button" data-toggle="collapse"
|
||||||
|
data-target="#multiCollapse-{{ subdirid }}" aria-expanded="true"
|
||||||
|
aria-controls="multiCollapse-{{ subdirid }}">Toggle Collapse</button>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{{- dirlisting(subdirobj, subdirpath) -}}
|
<div class="collapse multi-collapse" id="multiCollapse-{{ subdirid }}">
|
||||||
|
{{- dirlisting(subdirobj, subdirpath) -}}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{%- set files = dir.get_files() %}
|
{%- set files = dir.get_files() %}
|
||||||
{%- if files %}
|
{%- if files %}
|
||||||
@@ -55,90 +61,96 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div id="playlist" class="card">
|
<div class="col">
|
||||||
<div class="card-head">
|
<div id="playlist" class="card">
|
||||||
<h2 class="card-title">Play List</h2>
|
<div class="card-header">
|
||||||
</div>
|
<h2 class="card-title">Play List</h2>
|
||||||
|
|
||||||
<div class="card-body">
|
|
||||||
<div>
|
|
||||||
Currently Playing :
|
|
||||||
{% if playlist|length > 0 %}
|
|
||||||
{% if 'url' in playlist[0] %}
|
|
||||||
(<a href="{{ playlist[0]['url'] }}">{{ playlist[0]['url'] }}</a>)
|
|
||||||
{% elif 'path' in playlist[0] %}
|
|
||||||
({{ playlist[0]['path'] }})
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
No music
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
Playlist :
|
|
||||||
<form method="post">
|
|
||||||
<input type="text" value="randomize" name="action" hidden>
|
|
||||||
<button type="submit" class="btn btn-primary">Randomize playlist</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<table class="table">
|
<div class="card-body">
|
||||||
<thead>
|
<div>
|
||||||
<tr>
|
Currently Playing :
|
||||||
<th scope="col">Type</th>
|
{% if playlist|length > 0 %}
|
||||||
<th scope="col">Title</th>
|
{% if 'url' in playlist[0] %}
|
||||||
<th scope="col">Url/Path</th>
|
<a href="{{ playlist[0]['url'] }}">{{ playlist[0]['url'] }}</a>
|
||||||
<th scope="col">Action</th>
|
{% elif 'path' in playlist[0] %}
|
||||||
</tr>
|
{{ playlist[0]['path'] }}
|
||||||
</thead>
|
{% endif %}
|
||||||
<tbody>
|
{% else %}
|
||||||
{% for m in playlist[1:] %}
|
No music
|
||||||
<tr>
|
{% endif %}
|
||||||
<th>{{ m['type'] }}</th>
|
</div>
|
||||||
<th>
|
<form method="post">
|
||||||
{% if 'title' in m %}
|
<input type="text" value="randomize" name="action" hidden>
|
||||||
({{ m['title'] }})
|
<button type="submit" class="btn btn-primary">Randomize playlist</button>
|
||||||
{% else %}
|
</form>
|
||||||
No title
|
|
||||||
{% endif %}
|
<table class="table">
|
||||||
</th>
|
<thead>
|
||||||
<th>
|
<tr>
|
||||||
{% if 'url' in m %}
|
<th scope="col">#</th>
|
||||||
(<a href="{{ m['url'] }}">{{ m['url'] }}</a>)
|
<th scope="col">Type</th>
|
||||||
{% elif 'path' in m %}
|
<th scope="col">Title</th>
|
||||||
({{ m['path'] }})
|
<th scope="col">Url/Path</th>
|
||||||
{% endif %}
|
<th scope="col">Action</th>
|
||||||
</th>
|
</tr>
|
||||||
<th>
|
</thead>
|
||||||
<form method="post">
|
<tbody>
|
||||||
<input type="text" value="{{ loop.index }}" name="delete_music" hidden>
|
{% for m in playlist[1:] %}
|
||||||
<button type="submit" class="btn btn-primary">Remove</button>
|
<tr>
|
||||||
</form>
|
<th scope="row">{{ loop.index }}</th>
|
||||||
</th>
|
<td>{{ m['type'] }}</td>
|
||||||
</tr>
|
<td>
|
||||||
{% endfor %}
|
{% if 'title' in m %}
|
||||||
</tbody>
|
({{ m['title'] }})
|
||||||
</table>
|
{% else %}
|
||||||
|
No title
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if 'url' in m %}
|
||||||
|
<a href="{{ m['url'] }}">{{ m['url'] }}</a>
|
||||||
|
{% elif 'path' in m %}
|
||||||
|
{{ m['path'] }}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<form method="post">
|
||||||
|
<input type="text" value="{{ loop.index }}" name="delete_music" hidden>
|
||||||
|
<button type="submit" class="btn btn-primary">Remove</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div id="browser" class="card">
|
<div class="col">
|
||||||
<div class="card-header">
|
<div id="browser" class="card">
|
||||||
<h2 class="card-title">Music library</h2>
|
<div class="card-header">
|
||||||
</div>
|
<h2 class="card-title">Music library</h2>
|
||||||
<div class="card-body">
|
</div>
|
||||||
<div class="btn-group" role="group">
|
|
||||||
<form action="./download" method="get" class="directory form1">
|
<div class="card-body">
|
||||||
<input type="text" value="./" name="directory" hidden>
|
<div class="btn-group" role="group">
|
||||||
<button type="submit" class="btn btn-primary">Download entire music library</button>
|
<form action="./download" method="get" class="directory form1">
|
||||||
</form>
|
<input type="text" value="./" name="directory" hidden>
|
||||||
<form method="post" class="directory form3">
|
<button type="submit" class="btn btn-primary">Download entire music library</button>
|
||||||
<input type="text" value="./" name="add_folder_recursively" hidden>
|
</form>
|
||||||
<button type="submit" class="btn btn-primary">Add all tracks from music library
|
<form method="post" class="directory form3">
|
||||||
(recursively)</button>
|
<input type="text" value="./" name="add_folder_recursively" hidden>
|
||||||
</form>
|
<button type="submit" class="btn btn-primary">Add all tracks from music library
|
||||||
|
(recursively)</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
{{ dirlisting(music_library) }}
|
||||||
</div>
|
</div>
|
||||||
<br />
|
|
||||||
{{ dirlisting(music_library) }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -160,6 +172,7 @@
|
|||||||
<label class="custom-file-label" for="uploadSelectFile">Choose file</label>
|
<label class="custom-file-label" for="uploadSelectFile">Choose file</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
|
<span class="input-group-text">Upload To</span>
|
||||||
<input class="form-control" list="targetdirs" id="targetdir" name="targetdir"
|
<input class="form-control" list="targetdirs" id="targetdir" name="targetdir"
|
||||||
placeholder="uploads" />
|
placeholder="uploads" />
|
||||||
<datalist id="targetdirs">
|
<datalist id="targetdirs">
|
||||||
@@ -169,7 +182,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</datalist>
|
</datalist>
|
||||||
<button class="btn btn-outline-secondary" type="submit"
|
<button class="btn btn-outline-secondary" type="submit"
|
||||||
id="uploadSubmit">Button</button>
|
id="uploadSubmit">Upload</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@@ -209,6 +222,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="/static/js/jquery-3.4.1.min.js" crossorigin="anonymous"></script>
|
||||||
<script src="/static/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
|
<script src="/static/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user