Explorar o código

feat(flutter): save 11.4

huangrunheng %!s(int64=3) %!d(string=hai) anos
pai
achega
40b9839b0b

+ 5 - 0
module/config/config_menu.py

@@ -43,6 +43,11 @@ class ConfigMenu:
         """
         """
         return json.dumps(self.menu, ensure_ascii=False, sort_keys=False, default=str)
         return json.dumps(self.menu, ensure_ascii=False, sort_keys=False, default=str)
 
 
+    @cached_property
+    def gui_menu_list(self) -> dict:
+        return self.menu
+
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     try:
     try:
         m = ConfigMenu()
         m = ConfigMenu()

+ 0 - 2
module/server/main_manager.py

@@ -15,8 +15,6 @@ class MainManager(ConfigManager):
 
 
     def __init__(self) -> None:
     def __init__(self) -> None:
         super().__init__()
         super().__init__()
-        self.manager = SyncManager()  # 进程管理器
-        self.manager.start()
 
 
 
 
 
 

+ 1 - 0
module/server/script_process.py

@@ -25,6 +25,7 @@ class ScriptProcess:
                                                 args=(self.state_queue, self.log_pipe_in,),
                                                 args=(self.state_queue, self.log_pipe_in,),
                                                 name=self.config_name,
                                                 name=self.config_name,
                                                 daemon=True)
                                                 daemon=True)
+        # threading.Condition  可以多用户通知
 
 
 
 
 
 

+ 41 - 6
module/server/script_router.py

@@ -1,25 +1,28 @@
 # This Python file uses the following encoding: utf-8
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
-from fastapi import APIRouter
+import asyncio
+from fastapi import APIRouter, HTTPException
+from fastapi.responses import StreamingResponse
+from module.config.config import Config
 
 
 from module.logger import logger
 from module.logger import logger
 from module.server.main_manager import MainManager
 from module.server.main_manager import MainManager
 from module.server.script_process import ScriptProcess
 from module.server.script_process import ScriptProcess
 
 
+
 script_app = APIRouter()
 script_app = APIRouter()
 mm = MainManager()
 mm = MainManager()
 
 
 @script_app.get('/test')
 @script_app.get('/test')
 async def script_test():
 async def script_test():
-    return {'message':'test'}
+    return 'success'
 
 
 @script_app.get('/script_menu')
 @script_app.get('/script_menu')
 async def script_menu():
 async def script_menu():
     if mm.config_cache is None:
     if mm.config_cache is None:
-        logger.warning('未加载配置')
-        return {'message':'未加载配置'}
-    return mm.config_cache.gui_menu
+        mm.config_cache = Config('template')
+    return mm.config_cache.gui_menu_list
 # ----------------------------------   配置文件管理   ----------------------------------
 # ----------------------------------   配置文件管理   ----------------------------------
 @script_app.get('/config_list')
 @script_app.get('/config_list')
 async def config_list():
 async def config_list():
@@ -30,6 +33,10 @@ async def config_copy(file: str, template: str = 'template'):
     mm.copy(file, template)
     mm.copy(file, template)
     return mm.all_script_files()
     return mm.all_script_files()
 
 
+@script_app.delete('/config_new_name')
+async def config_new_name():
+    return mm.generate_script_name()
+
 
 
 # ---------------------------------   脚本实例管理   ----------------------------------
 # ---------------------------------   脚本实例管理   ----------------------------------
 @script_app.get('/{script_name}/start')
 @script_app.get('/{script_name}/start')
@@ -56,10 +63,38 @@ async def script_task(script_name: str, task: str):
 @script_app.put('/{script_name}/{task}/{group}/{argument}/value/{value}')
 @script_app.put('/{script_name}/{task}/{group}/{argument}/value/{value}')
 async def script_task(script_name: str, task: str, group: str, argument: str, value):
 async def script_task(script_name: str, task: str, group: str, argument: str, value):
     if not mm.ensure_config_cache(task):
     if not mm.ensure_config_cache(task):
-        raise Exception(f'[{script_name}] script file does not exist')
+        raise HTTPException(status_code=404, detail=f'[{script_name}] script file does not exist')
     mm.config_cache.set_task_args(task, group, argument, value)
     mm.config_cache.set_task_args(task, group, argument, value)
     return
     return
 
 
+# --------------------------------------  SSE  --------------------------------------
+@script_app.get('/{script_name}/state')
+async def script_task_state(script_name: str):
+    async def state_generate_events():
+        while True:
+            # 生成 SSE 事件数据
+            event_data = "data: Hello, SSE!\n\n"
+            yield event_data
+
+            # 模拟异步操作,可以替换为您的实际处理逻辑
+            await asyncio.sleep(1)
+
+    response = StreamingResponse(state_generate_events(), media_type="text/event-stream")
+    response.headers["Cache-Control"] = "no-cache"
+    return response
+
+@script_app.get('/{script_name}/log')
+async def script_task_log(script_name: str):
+    async def log_generate_events():
+        while True:
+            # 生成 SSE 事件数据
+            event_data = "data: log\n"
+            yield event_data
 
 
+            # 模拟异步操作,可以替换为您的实际处理逻辑
+            await asyncio.sleep(1)
 
 
+    response = StreamingResponse(log_generate_events(), media_type="text/event-stream")
+    response.headers["Cache-Control"] = "no-cache"
+    return response