Version 0.1.1 rise to flask app factory

This commit is contained in:
CakeCN
2025-08-27 19:39:38 +08:00
parent 8dba8688a7
commit 5c0187bc4b
55 changed files with 1708 additions and 613 deletions

View File

@@ -0,0 +1,59 @@
# myapp/services/backboard_service.py
import os
from flask import current_app
from backboardManager import Backboard # 你已有的类
def _to_wsl_path_if_needed(path: str) -> str:
cfg = current_app.config["VSCODE_WEB_PATH"]
if cfg.get("is_wsl") and cfg.get("windows_path") and cfg.get("wsl_path"):
return path.replace("\\", "/").replace(cfg["windows_path"], cfg["wsl_path"])
return path
def realtime_response(config: dict, realtime_action: dict) -> None:
"""
业务:根据 VSCode 上报的动作,更新 Backboard黑板状态。
"""
# 依赖从 app.extensions 取,避免循环导入
username2uuid = current_app.extensions["username2uuid"]
backboard_manager = current_app.extensions["backboard_manager"]
user_id = config["user_id"]
folder_path = config["path"] # 如需 WSL 转换可在生成 config 时处理
useruuid = username2uuid[user_id]
bb = backboard_manager.get_backboard(useruuid)
assert isinstance(bb, Backboard)
# 统一记历史
bb.add_history(realtime_action)
rtype = realtime_action.get("type")
if rtype == "workspaceFolders":
bb.file_tree = realtime_action.get("fileTree")
elif rtype == "activeFile":
file_path = realtime_action.get("filePath")
assert isinstance(file_path, str)
with open(file_path, "r", encoding="utf-8") as f:
bb.active_file_content = f.read()
bb.active_file_path = file_path
elif rtype == "paste":
file_path = realtime_action.get("filePath")
assert isinstance(file_path, str)
bb.pasted_file_path = file_path
bb.pasted_content = realtime_action.get("content")
bb.active_file_path = file_path
with open(file_path, "r", encoding="utf-8") as f:
bb.active_file_content = f.read()
elif rtype == "fileEdit":
file_path = realtime_action.get("filePath")
assert isinstance(file_path, str)
bb.active_file_path = file_path
with open(file_path, "r", encoding="utf-8") as f:
bb.active_file_content = f.read()
# 如需调试输出,可在这里统一记录日志
current_app.logger.debug("vscode config: %s", config)
current_app.logger.debug("vscode action: %s", realtime_action)