api支持
This commit is contained in:
parent
49238a09e0
commit
0589d13e39
@ -50,18 +50,18 @@ class ConfigManager(metaclass=Singleton):
|
|||||||
if not os.path.exists(config_file):
|
if not os.path.exists(config_file):
|
||||||
_log.warning("配置文件不存在,写入初始化配置")
|
_log.warning("配置文件不存在,写入初始化配置")
|
||||||
self._current_config = self._default_config
|
self._current_config = self._default_config
|
||||||
self._write_config()
|
self.save_config()
|
||||||
else:
|
else:
|
||||||
self._read_config()
|
self.load_config()
|
||||||
|
|
||||||
def _read_config(self):
|
def load_config(self):
|
||||||
_log.debug("读取文件%s的配置内容", self._config_file)
|
_log.debug("读取文件%s的配置内容", self._config_file)
|
||||||
with open(self._config_file, "r", encoding="UTF8") as _f:
|
with open(self._config_file, "r", encoding="UTF8") as _f:
|
||||||
yaml = YAML(typ="unsafe", pure=True)
|
yaml = YAML(typ="unsafe", pure=True)
|
||||||
self._current_config = yaml.load(_f)
|
self._current_config = yaml.load(_f)
|
||||||
_log.debug("读取文件%s的配置内容完毕", self._config_file)
|
_log.debug("读取文件%s的配置内容完毕", self._config_file)
|
||||||
|
|
||||||
def _write_config(self):
|
def save_config(self):
|
||||||
_log.debug("向文件%s写入配置", self._config_file)
|
_log.debug("向文件%s写入配置", self._config_file)
|
||||||
with open(self._config_file, "w", encoding="UTF8") as _f:
|
with open(self._config_file, "w", encoding="UTF8") as _f:
|
||||||
_log.debug("配置内容:", self._current_config)
|
_log.debug("配置内容:", self._current_config)
|
||||||
|
68
core/controller/manager_blueprint.py
Normal file
68
core/controller/manager_blueprint.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
from flask import Blueprint, request, jsonify
|
||||||
|
|
||||||
|
from core import CoreManager
|
||||||
|
|
||||||
|
blueprint = Blueprint("api_manager", __name__, url_prefix="/api/manager")
|
||||||
|
|
||||||
|
c = CoreManager()
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.post("/on_broadcast")
|
||||||
|
def on_broadcast():
|
||||||
|
form = request.form
|
||||||
|
if "room_id" in form:
|
||||||
|
c.on_broadcast(room_id=form['room_id'])
|
||||||
|
return jsonify(
|
||||||
|
message="OK",
|
||||||
|
code=0,
|
||||||
|
success=True,
|
||||||
|
data=None
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return jsonify(
|
||||||
|
message="Missing Param [room_id]",
|
||||||
|
code=403,
|
||||||
|
success=False,
|
||||||
|
data=None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.post("/open_url")
|
||||||
|
def open_url():
|
||||||
|
form = request.form
|
||||||
|
if "url" in form:
|
||||||
|
c.open_tab(form['url'])
|
||||||
|
return jsonify(
|
||||||
|
message="OK",
|
||||||
|
code=0,
|
||||||
|
success=True,
|
||||||
|
data=None
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return jsonify(
|
||||||
|
message="Missing Param [room_id]",
|
||||||
|
code=403,
|
||||||
|
success=False,
|
||||||
|
data=None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.get("/config")
|
||||||
|
def get_config():
|
||||||
|
return jsonify(
|
||||||
|
message="OK",
|
||||||
|
code=0,
|
||||||
|
success=True,
|
||||||
|
data=c.config_manager.config,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.post("/config")
|
||||||
|
def write_config():
|
||||||
|
c.config_manager.save_config()
|
||||||
|
return jsonify(
|
||||||
|
message="OK",
|
||||||
|
code=0,
|
||||||
|
success=True,
|
||||||
|
data=None
|
||||||
|
)
|
@ -61,6 +61,7 @@ class CoreManager(metaclass=Singleton):
|
|||||||
_log.info("初始化浏览器管理器完毕")
|
_log.info("初始化浏览器管理器完毕")
|
||||||
_log.debug("初始化输出管理器")
|
_log.debug("初始化输出管理器")
|
||||||
self.output_manager = OutputManager(self.config_manager)
|
self.output_manager = OutputManager(self.config_manager)
|
||||||
|
self.output_manager.start_loop()
|
||||||
_log.info("初始化输出管理器完毕")
|
_log.info("初始化输出管理器完毕")
|
||||||
self._open_config_tabs()
|
self._open_config_tabs()
|
||||||
|
|
||||||
|
7
main.py
7
main.py
@ -1,9 +1,12 @@
|
|||||||
import logging
|
import logging
|
||||||
import atexit
|
import atexit
|
||||||
|
from flask import Flask
|
||||||
|
|
||||||
from core import CoreManager
|
from core import CoreManager
|
||||||
|
from core.controller.manager_blueprint import blueprint as manager_blueprint
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
app = Flask(__name__)
|
||||||
|
app.register_blueprint(manager_blueprint)
|
||||||
|
|
||||||
|
|
||||||
def _on_exit():
|
def _on_exit():
|
||||||
@ -15,4 +18,4 @@ atexit.register(_on_exit)
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
c = CoreManager()
|
c = CoreManager()
|
||||||
c.proxy_manager.join()
|
app.run()
|
||||||
|
@ -2,4 +2,5 @@ colorama==0.4.4
|
|||||||
selenium==4.1.0
|
selenium==4.1.0
|
||||||
|
|
||||||
mitmproxy~=8.0.0
|
mitmproxy~=8.0.0
|
||||||
protobuf<3.20
|
protobuf<3.20
|
||||||
|
Flask~=2.0.3
|
Reference in New Issue
Block a user