mirror of
https://gitlab.com/RemixDev/deemix-gui-pyweb.git
synced 2025-01-01 12:26:13 +00:00
Implemented socket.io
Started work on darkmode Implemented queue system Started work on download tab
This commit is contained in:
parent
83ebf6bdad
commit
07add62470
36
server.py
36
server.py
|
@ -4,6 +4,8 @@ import webbrowser
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from flask import Flask, url_for, render_template, jsonify, request, make_response
|
from flask import Flask, url_for, render_template, jsonify, request, make_response
|
||||||
|
from flask_socketio import SocketIO, emit
|
||||||
|
import logging
|
||||||
import webview
|
import webview
|
||||||
import deemix.app.main as app
|
import deemix.app.main as app
|
||||||
|
|
||||||
|
@ -23,37 +25,37 @@ if not os.path.exists(gui_dir): # frozen executable path
|
||||||
gui_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'public')
|
gui_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'public')
|
||||||
server = CustomFlask(__name__, static_folder=gui_dir, template_folder=gui_dir)
|
server = CustomFlask(__name__, static_folder=gui_dir, template_folder=gui_dir)
|
||||||
server.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1 # disable caching
|
server.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1 # disable caching
|
||||||
|
socketio = SocketIO(server)
|
||||||
|
|
||||||
|
serverLog = logging.getLogger('werkzeug')
|
||||||
|
serverLog.disabled = True
|
||||||
|
server.logger.disabled = True
|
||||||
|
|
||||||
@server.route('/')
|
@server.route('/')
|
||||||
def landing():
|
def landing():
|
||||||
return render_template('index.html', token=webview.token)
|
return render_template('index.html', token=webview.token)
|
||||||
|
|
||||||
@server.route('/init', methods=['POST'])
|
@socketio.on('init')
|
||||||
def initialize():
|
def handle_init():
|
||||||
can_start = app.initialize()
|
can_start = app.initialize()
|
||||||
if can_start:
|
if can_start:
|
||||||
response = {'status': 'ok'}
|
response = {'status': 'ok'}
|
||||||
else:
|
else:
|
||||||
response = {'status': 'error'}
|
response = {'status': 'error'}
|
||||||
return jsonify(response)
|
|
||||||
|
|
||||||
@server.route('/mainsearch', methods=['POST'])
|
@socketio.on('mainSearch')
|
||||||
def mainsearch():
|
def mainSearch(data):
|
||||||
data = json.loads(request.data)
|
emit('mainSearch', app.mainSearch(data['term']))
|
||||||
return jsonify(app.mainSearch(data['term']))
|
|
||||||
|
|
||||||
@server.route('/search', methods=['POST'])
|
@socketio.on('search')
|
||||||
def search():
|
def search(data):
|
||||||
data = json.loads(request.data)
|
|
||||||
result = app.search(data['term'], data['type'], data['start'], data['nb'])
|
result = app.search(data['term'], data['type'], data['start'], data['nb'])
|
||||||
result['type'] = data['type']
|
result['type'] = data['type']
|
||||||
return jsonify(result)
|
emit('search', result)
|
||||||
|
|
||||||
@server.route('/download', methods=['POST'])
|
@socketio.on('addToQueue')
|
||||||
def download():
|
def addToQueue(data):
|
||||||
data = json.loads(request.data)
|
app.addToQueue_link(data['url'], socket=socketio)
|
||||||
app.downloadLink(data['url'])
|
|
||||||
return jsonify({})
|
|
||||||
|
|
||||||
# Example code leftover, could be usefull later on
|
# Example code leftover, could be usefull later on
|
||||||
@server.route('/choose/path', methods=['POST'])
|
@server.route('/choose/path', methods=['POST'])
|
||||||
|
@ -90,7 +92,7 @@ def do_stuff():
|
||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
|
||||||
def run_server():
|
def run_server():
|
||||||
server.run(host='127.0.0.1', port=33333, threaded=True)
|
socketio.run(server, host='127.0.0.1', port=33333)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run_server()
|
run_server()
|
||||||
|
|
Loading…
Reference in a new issue