Proxy, Upload
Proxy paramter if behinf nginx Upload can be done into a folder directly from the webpage
This commit is contained in:
parent
4f31a99374
commit
54068a151e
@ -1,8 +1,9 @@
|
||||
[bot]
|
||||
comment = Coucou, Je suis née du savoir du Azlux
|
||||
comment = Coucou, Je suis née du savoir du Azlux, accès au https://azlux.fr/bot
|
||||
volume = 0.1
|
||||
admin = Azlux;AzMobile
|
||||
music_folder = /home/dmichel/botamusique/music/
|
||||
is_proxified = True
|
||||
|
||||
[debug]
|
||||
ffmpeg = False
|
||||
|
33
interface.py
33
interface.py
@ -1,10 +1,11 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from flask import Flask, render_template, request
|
||||
from flask import Flask, render_template, request, redirect
|
||||
import variables as var
|
||||
import os.path
|
||||
from os import listdir
|
||||
import random
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
|
||||
class ReverseProxied(object):
|
||||
@ -46,6 +47,11 @@ class ReverseProxied(object):
|
||||
|
||||
|
||||
web = Flask(__name__)
|
||||
|
||||
|
||||
def init_proxy():
|
||||
global web
|
||||
if var.is_proxified:
|
||||
web.wsgi_app = ReverseProxied(web.wsgi_app)
|
||||
|
||||
|
||||
@ -81,8 +87,29 @@ def index():
|
||||
current_music=current_music,
|
||||
user=var.user,
|
||||
playlist=var.playlist,
|
||||
all_files=files
|
||||
)
|
||||
all_files=files)
|
||||
|
||||
|
||||
@web.route('/download', methods=["POST"])
|
||||
def download():
|
||||
print(request.form)
|
||||
|
||||
file = request.files['music_file']
|
||||
if not file:
|
||||
return redirect("./", code=406)
|
||||
elif file.filename == '':
|
||||
return redirect("./", code=406)
|
||||
elif '..' in request.form['directory']:
|
||||
return redirect("./", code=406)
|
||||
|
||||
if file.name == "music_file" and "audio" in file.headers.to_list()[1][1]:
|
||||
web.config['UPLOAD_FOLDER'] = var.music_folder + request.form['directory']
|
||||
filename = secure_filename(file.filename)
|
||||
print(filename)
|
||||
file.save(os.path.join(web.config['UPLOAD_FOLDER'], filename))
|
||||
return redirect("./", code=302)
|
||||
else:
|
||||
return redirect("./", code=409)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -31,15 +31,19 @@ class MumbleBot:
|
||||
|
||||
args = parser.parse_args()
|
||||
self.volume = self.config.getfloat('bot', 'volume')
|
||||
|
||||
self.channel = args.channel
|
||||
var.current_music = None
|
||||
var.playlist = []
|
||||
var.user = args.user
|
||||
var.music_folder = self.config.get('bot', 'music_folder')
|
||||
var.is_proxified = self.config.getboolean("bot", "is_proxified")
|
||||
self.exit = False
|
||||
self.nb_exit = 0
|
||||
self.thread = None
|
||||
|
||||
interface.init_proxy()
|
||||
|
||||
t = threading.Thread(target=start_web_interface)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
@ -9,7 +9,17 @@
|
||||
<body>
|
||||
<a href="."><h5>Refresh</h5></a>
|
||||
<br>
|
||||
|
||||
<div id="download">
|
||||
<form action="./download" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="music_file" value="Browse Music file"/>
|
||||
<select name="directory">
|
||||
{% for dir in all_files %}
|
||||
<option value={{ dir }}>{{ dir }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="submit" value="Upload"/>
|
||||
</form>
|
||||
</div>
|
||||
<div id="playlist">
|
||||
Current Playing :
|
||||
{% if current_music %}
|
||||
|
@ -2,3 +2,4 @@ current_music = ""
|
||||
playlist = []
|
||||
user = ""
|
||||
music_folder = ""
|
||||
is_proxified = False
|
Loading…
x
Reference in New Issue
Block a user