]> git.0d.be Git - botaradio.git/commitdiff
impl multiCollapse and fileupload
author神楽坂·喵 <yuronglong1996@gmail.com>
Fri, 22 Nov 2019 02:51:23 +0000 (10:51 +0800)
committer神楽坂·喵 <yuronglong1996@gmail.com>
Fri, 22 Nov 2019 02:51:23 +0000 (10:51 +0800)
interface.py
templates/index.html

index 1909fad18a8ece1fdf9475952cbe973e5527f50f..e4b01e2734109079ac9aff4cfbc2e7c6f05cd73f 100644 (file)
@@ -122,6 +122,7 @@ def index():
                            user=var.user)
 
 
+@web.route('/upload', methods=["POST"])
 def upload():
     file = request.files['file']
     if not file:
@@ -137,14 +138,15 @@ def upload():
     elif '../' in targetdir:
         return redirect("./", code=406)
 
-    print('Uploading file:')
-    print('filename:', filename)
-    print('targetdir:', targetdir)
-    print('mimetype:', file.mimetype)
+    print('Uploading file:')
+    print('filename:', filename)
+    print('targetdir:', targetdir)
+    print('mimetype:', file.mimetype)
 
     if "audio" in file.mimetype:
         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)
 
         try:
@@ -154,6 +156,7 @@ def upload():
                 return redirect("./", code=500)
 
         filepath = os.path.join(storagepath, filename)
+        print('filepath:',filepath)
         if os.path.exists(filepath):
             return redirect("./", code=406)
 
index 70f3d4c555e504c034e9a9a9533d3e1021f63528..5104ff68317134b1e2dc601246848c1b23ae3f80 100644 (file)
@@ -2,6 +2,7 @@
 <ul class="list-group">
     {% for subdirname, subdirobj in dir.get_subdirs().items() %}
     {%- set subdirpath = os.path.relpath(subdirobj.fullpath, music_library.fullpath) %}
+    {%- set subdirid = subdirpath.replace("/","-") %}
     <li class="directory list-group-item list-group-item-primary">
         <span>{{ subdirpath }}/&nbsp;</span>
         <div class="btn-group" role="group">
                 <input type="text" value="{{ subdirpath }}" name="directory" hidden>
                 <button type="submit" class="btn btn-secondary">Download entire directory</button>
             </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>
     </li>
-    {{- dirlisting(subdirobj, subdirpath) -}}
+    <div class="collapse multi-collapse" id="multiCollapse-{{ subdirid }}">
+        {{- dirlisting(subdirobj, subdirpath) -}}
+    </div>
     {% endfor %}
     {%- set files = dir.get_files() %}
     {%- if files %}
 <body>
     <div class="container">
         <div class="row">
-            <div id="playlist" class="card">
-                <div class="card-head">
-                    <h2 class="card-title">Play List</h2>
-                </div>
-
-                <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 class="col">
+                <div id="playlist" class="card">
+                    <div class="card-header">
+                        <h2 class="card-title">Play List</h2>
                     </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">
-                        <thead>
-                            <tr>
-                                <th scope="col">Type</th>
-                                <th scope="col">Title</th>
-                                <th scope="col">Url/Path</th>
-                                <th scope="col">Action</th>
-                            </tr>
-                        </thead>
-                        <tbody>
-                            {% for m in playlist[1:] %}
-                            <tr>
-                                <th>{{ m['type'] }}</th>
-                                <th>
-                                    {% if 'title' in m %}
-                                    ({{ m['title'] }})
-                                    {% else %}
-                                    No title
-                                    {% endif %}
-                                </th>
-                                <th>
-                                    {% if 'url' in m %}
-                                    (<a href="{{ m['url'] }}">{{ m['url'] }}</a>)
-                                    {% elif 'path' in m %}
-                                    ({{ m['path'] }})
-                                    {% endif %}
-                                </th>
-                                <th>
-                                    <form method="post">
-                                        <input type="text" value="{{ loop.index }}" name="delete_music" hidden>
-                                        <button type="submit" class="btn btn-primary">Remove</button>
-                                    </form>
-                                </th>
-                            </tr>
-                            {% endfor %}
-                        </tbody>
-                    </table>
+                    <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>
+                        <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">
+                            <thead>
+                                <tr>
+                                    <th scope="col">#</th>
+                                    <th scope="col">Type</th>
+                                    <th scope="col">Title</th>
+                                    <th scope="col">Url/Path</th>
+                                    <th scope="col">Action</th>
+                                </tr>
+                            </thead>
+                            <tbody>
+                                {% for m in playlist[1:] %}
+                                <tr>
+                                    <th scope="row">{{ loop.index }}</th>
+                                    <td>{{ m['type'] }}</td>
+                                    <td>
+                                        {% if 'title' in m %}
+                                        ({{ m['title'] }})
+                                        {% 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 class="row">
-            <div id="browser" class="card">
-                <div class="card-header">
-                    <h2 class="card-title">Music library</h2>
-                </div>
-                <div class="card-body">
-                    <div class="btn-group" role="group">
-                        <form action="./download" method="get" class="directory form1">
-                            <input type="text" value="./" name="directory" hidden>
-                            <button type="submit" class="btn btn-primary">Download entire music library</button>
-                        </form>
-                        <form method="post" class="directory form3">
-                            <input type="text" value="./" name="add_folder_recursively" hidden>
-                            <button type="submit" class="btn btn-primary">Add all tracks from music library
-                                (recursively)</button>
-                        </form>
+            <div class="col">
+                <div id="browser" class="card">
+                    <div class="card-header">
+                        <h2 class="card-title">Music library</h2>
+                    </div>
+
+                    <div class="card-body">
+                        <div class="btn-group" role="group">
+                            <form action="./download" method="get" class="directory form1">
+                                <input type="text" value="./" name="directory" hidden>
+                                <button type="submit" class="btn btn-primary">Download entire music library</button>
+                            </form>
+                            <form method="post" class="directory form3">
+                                <input type="text" value="./" name="add_folder_recursively" hidden>
+                                <button type="submit" class="btn btn-primary">Add all tracks from music library
+                                    (recursively)</button>
+                            </form>
+                        </div>
+                        <br />
+                        {{ dirlisting(music_library) }}
                     </div>
-                    <br />
-                    {{ dirlisting(music_library) }}
                 </div>
             </div>
         </div>
                                     <label class="custom-file-label" for="uploadSelectFile">Choose file</label>
                                 </div>
                                 <div class="input-group-append">
+                                    <span class="input-group-text">Upload To</span>
                                     <input class="form-control" list="targetdirs" id="targetdir" name="targetdir"
                                         placeholder="uploads" />
                                     <datalist id="targetdirs">
                                             {% endfor %}
                                     </datalist>
                                     <button class="btn btn-outline-secondary" type="submit"
-                                        id="uploadSubmit">Button</button>
+                                        id="uploadSubmit">Upload</button>
                                 </div>
                             </div>
                         </form>
         </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>
 </body>