From c25fad8be0f74f3d3dbb47978c93980909155253 Mon Sep 17 00:00:00 2001 From: Terry Geng Date: Wed, 5 Feb 2020 10:14:56 +0800 Subject: [PATCH] web interface add delete file function, debug --- interface.py | 14 ++++++++++++++ mumbleBot.py | 3 +++ templates/index.html | 26 ++++++++++++++++++++------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/interface.py b/interface.py index cf54b9b..c9f6260 100644 --- a/interface.py +++ b/interface.py @@ -5,12 +5,15 @@ from flask import Flask, render_template, request, redirect, send_file, Response import variables as var import util from datetime import datetime +import os import os.path +import shutil import random from werkzeug.utils import secure_filename import errno import media import logging +import time class ReverseProxied(object): @@ -163,6 +166,17 @@ def index(): var.botamusique.pause() var.botamusique.launch_music(int(request.form['play_music'])) + elif 'delete_music_file' in request.form and ".." not in request.form['delete_music_file']: + path = var.config.get('bot', 'music_folder') + request.form['delete_music_file'] + logging.info("web interface delete file " + path) + os.remove(path) + + elif 'delete_folder' in request.form and ".." not in request.form['delete_folder']: + path = var.config.get('bot', 'music_folder') + request.form['delete_folder'] + logging.info("web interface delete folder " + path) + shutil.rmtree(path) + time.sleep(0.1) + elif 'action' in request.form: action = request.form['action'] if action == "randomize": diff --git a/mumbleBot.py b/mumbleBot.py index 02f619b..179fc03 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -608,6 +608,9 @@ class MumbleBot: def launch_music(self, index=-1): uri = "" music = None + if var.playlist.length() == 0: + return + if index == -1: music = var.playlist.current_item() else: diff --git a/templates/index.html b/templates/index.html index 837919f..461a587 100644 --- a/templates/index.html +++ b/templates/index.html @@ -25,15 +25,22 @@ -
- - -
{{ subdirpath }}/ + +
+
+ + +
+
+ + +
+
{{- dirlisting(subdirobj, subdirpath) -}} @@ -65,12 +72,19 @@
+ + {{ filepath }} + +
-
  - {{ filepath }} +
+ + +
+ {% endfor %} {%- endif %}