diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e6cf8ca..a77d0d1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,9 +5,22 @@ + - - + + + + + + + + + + + + + + @@ -20,6 +33,7 @@ + @@ -37,58 +51,59 @@ - { - "keyToString": { - "DefaultHtmlFileTemplate": "HTML File", - "JavaScript 调试.output.html (1).executor": "Run", - "JavaScript 调试.output.html.executor": "Run", - "JavaScript 调试.regex.md_中文.html.executor": "Run", - "JavaScript 调试.regex_中文.html.executor": "Run", - "JavaScript 调试.test.html.executor": "Run", - "JavaScript 调试.test2.html.executor": "Run", - "JavaScript 调试.test2_英文.html.executor": "Run", - "JavaScript 调试.test4-1_中文.html.executor": "Run", - "JavaScript 调试.互联网认证授权机制.html.executor": "Run", - "JavaScript 调试.互联网认证授权机制_英文.html.executor": "Run", - "JavaScript 调试.毕业论文_英文.html.executor": "Run", - "ModuleVcsDetector.initialDetectionPerformed": "true", - "Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run", - "Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run", - "Python 测试.pytest (test_html.py 内).executor": "Run", - "Python.2test2 (1).executor": "Run", - "Python.PDFtranslater (1).executor": "Run", - "Python.PDFtranslater (2).executor": "Run", - "Python.agent.executor": "Debug", - "Python.agent_utils.executor": "Run", - "Python.app (1).executor": "Run", - "Python.app.executor": "Run", - "Python.app2.executor": "Run", - "Python.app_test (1).executor": "Run", - "Python.convert.executor": "Run", - "Python.markdown_splitter.executor": "Debug", - "Python.markdown_utils.executor": "Run", - "Python.test.executor": "Run", - "Python.test1.executor": "Run", - "Python.test2.executor": "Run", - "Python.test3.executor": "Run", - "Python.test4.executor": "Run", - "Python.testhtml.executor": "Run", - "Python.translater.executor": "Run", - "Python.切分测试.executor": "Run", - "RunOnceActivity.ShowReadmeOnStart": "true", - "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager": "true", - "RunOnceActivity.git.unshallow": "true", - "git-widget-placeholder": "main", - "last_opened_file_path": "C:/Users/jxgm/Desktop/FileTranslate/dist/DocuTranslate", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "settings.editor.selected.configurable": "preferences.pluginManager", - "vue.rearranger.settings.migration": "true" + +}]]> @@ -98,11 +113,11 @@ + - @@ -562,7 +577,11 @@ - + + + + + @@ -570,7 +589,7 @@ - + diff --git a/docutranslate/app.py b/docutranslate/app.py index 10e1fb4..cb4db9b 100644 --- a/docutranslate/app.py +++ b/docutranslate/app.py @@ -2,728 +2,26 @@ import asyncio import io import logging import time -import urllib from pathlib import Path from typing import List, Dict, Any, Optional from urllib.parse import quote import uvicorn from fastapi import FastAPI, File, Form, UploadFile, Request, HTTPException -from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse +from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse,FileResponse from fastapi.templating import Jinja2Templates - +from fastapi.staticfiles import StaticFiles from docutranslate import FileTranslater from docutranslate.logger import translater_logger -# --- HTML模板 (JS part needs modification) --- -# language=HTML -HTML_TEMPLATE = """ - - - - - - DocuTranslate - - - - - - - DocuTranslate - - - - - - 文档选择 - - - 点击此处选择文件,或将文件拖拽到这里 - 未选择文件 - - - - - - 目标语言 - - 中文 (Chinese) - 英文 (English) - 日语 (Japanese) - 韩语 (Korean) - 法语 (French) - 德语 (German) - 西班牙语 (Spanish) - 意大利语 (Italian) - 葡萄牙语 (Portuguese) - 俄语 (Russian) - 阿拉伯语 (Arabic) - 印地语 (Hindi) - 荷兰语 (Dutch) - - - - 高级选项 - - 公式识别 - 代码识别 - 修正文本(耗时) - - - - - API 配置 - - - AI 平台 - - 自定义接口 - OpenAI - 智谱AI - DeepSeek - 阿里云百炼 - - DMXAPI - OpenRouter - 火山引擎 - 硅基流动 - - - - API 地址 (Base URL) - - - - - API 密钥 - - - - 模型 ID - - - - 开始翻译 - - - - - 翻译结果 - - 下载 Markdown - 下载 HTML - 下载 PDF - 预览 - - - 运行日志 - - - - - × - HTML 预览 - - - 打印/保存为PDF - 关闭 - - - - - - - -""" - app = FastAPI() +BASE_DIR = Path(__file__).resolve().parent +STATIC_DIR=BASE_DIR/"static" + + +app.mount("/static",StaticFiles(directory=STATIC_DIR), name="static") + # --- 全局配置 --- log_queue: Optional[asyncio.Queue] = None # Will be initialized in startup_event current_state: Dict[str, Any] = { @@ -882,7 +180,7 @@ async def _perform_translation(params: Dict[str, Any], file_contents: bytes, ori # --- API Endpoints --- @app.get("/", response_class=HTMLResponse) async def main_page(request: Request): - return HTMLResponse(content=HTML_TEMPLATE) + return FileResponse(STATIC_DIR/"index.html") @app.post("/translate") diff --git a/pyproject.toml b/pyproject.toml index 89b1df8..928aae0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "docutranslate" -version = "0.2.17" +version = "0.2.18" description = "文件翻译工具" readme = "README.md" requires-python = ">=3.10" @@ -12,3 +12,10 @@ dependencies = [ ] [project.scripts] docutranslate="docutranslate.cli:main" + +[build-system] +requires = ["setuptools>=61.0"] # 或者你需要的 setuptools 版本 +build-backend = "setuptools.build_meta" +backend-path = ["."] +[tool.setuptools.package-data] +docutranslate = ["static/**"] \ No newline at end of file
点击此处选择文件,或将文件拖拽到这里