From 07add62470f57da81ef41db2a3079068148d8a25 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 10 Apr 2020 16:12:21 +0200 Subject: [PATCH] Implemented socket.io Started work on darkmode Implemented queue system Started work on download tab --- server.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/server.py b/server.py index 3251c7b..7412d16 100644 --- a/server.py +++ b/server.py @@ -4,6 +4,8 @@ import webbrowser from functools import wraps from flask import Flask, url_for, render_template, jsonify, request, make_response +from flask_socketio import SocketIO, emit +import logging import webview 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') server = CustomFlask(__name__, static_folder=gui_dir, template_folder=gui_dir) 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('/') def landing(): return render_template('index.html', token=webview.token) -@server.route('/init', methods=['POST']) -def initialize(): +@socketio.on('init') +def handle_init(): can_start = app.initialize() if can_start: response = {'status': 'ok'} else: response = {'status': 'error'} - return jsonify(response) -@server.route('/mainsearch', methods=['POST']) -def mainsearch(): - data = json.loads(request.data) - return jsonify(app.mainSearch(data['term'])) +@socketio.on('mainSearch') +def mainSearch(data): + emit('mainSearch', app.mainSearch(data['term'])) -@server.route('/search', methods=['POST']) -def search(): - data = json.loads(request.data) +@socketio.on('search') +def search(data): result = app.search(data['term'], data['type'], data['start'], data['nb']) result['type'] = data['type'] - return jsonify(result) + emit('search', result) -@server.route('/download', methods=['POST']) -def download(): - data = json.loads(request.data) - app.downloadLink(data['url']) - return jsonify({}) +@socketio.on('addToQueue') +def addToQueue(data): + app.addToQueue_link(data['url'], socket=socketio) # Example code leftover, could be usefull later on @server.route('/choose/path', methods=['POST']) @@ -90,7 +92,7 @@ def do_stuff(): return jsonify(response) 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__': run_server()