mirror of
https://github.com/LifeArchiveProject/WeChatDataAnalysis.git
synced 2026-06-18 15:54:08 +08:00
feat: 文件选择器 + 信息解析
This commit is contained in:
@@ -38,6 +38,7 @@ from .request_logging import log_server_errors_middleware
|
||||
from .sns_stage_timing import add_sns_stage_timing_headers
|
||||
from .wcdb_realtime import WCDB_REALTIME, shutdown as _wcdb_shutdown
|
||||
from .routers.biz import router as _biz_router
|
||||
from .routers.system import router as _system_router
|
||||
|
||||
app = FastAPI(
|
||||
title="微信数据库解密工具",
|
||||
@@ -100,6 +101,7 @@ app.include_router(_sns_router)
|
||||
app.include_router(_sns_export_router)
|
||||
app.include_router(_wrapped_router)
|
||||
app.include_router(_biz_router)
|
||||
app.include_router(_system_router)
|
||||
|
||||
|
||||
class _SPAStaticFiles(StaticFiles):
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
import asyncio
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def _open_folder_dialog(title: str, initial_dir: str) -> str:
|
||||
# 延迟导入并放在独立线程运行,避免阻塞 FastAPI 主线程或发生 GUI 线程冲突
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
|
||||
root = tk.Tk()
|
||||
root.withdraw() # 隐藏主窗口
|
||||
root.attributes('-topmost', True) # 确保弹窗在最前
|
||||
|
||||
folder_path = filedialog.askdirectory(
|
||||
parent=root,
|
||||
title=title,
|
||||
initialdir=initial_dir
|
||||
)
|
||||
|
||||
root.destroy()
|
||||
return folder_path
|
||||
|
||||
|
||||
@router.get("/api/system/pick_directory", summary="唤起本地原生目录选择器")
|
||||
async def pick_directory(title: str = "请选择目录", initial_dir: str = ""):
|
||||
loop = asyncio.get_running_loop()
|
||||
with ThreadPoolExecutor() as pool:
|
||||
# 在子线程中执行 GUI 操作
|
||||
folder_path = await loop.run_in_executor(pool, _open_folder_dialog, title, initial_dir)
|
||||
|
||||
return {"path": folder_path}
|
||||
Reference in New Issue
Block a user