-
+
diff --git a/docutranslate/app.py b/docutranslate/app.py
index a099724..6d761b6 100644
--- a/docutranslate/app.py
+++ b/docutranslate/app.py
@@ -223,17 +223,19 @@ async def handle_translate(
content={"task_started": False, "message": "另一个翻译任务正在进行中,请稍后再试。"}
)
- if not file or not file.filename:
- return JSONResponse(
- status_code=400,
- content={"task_started": False, "message": "没有选择文件或文件无效。"}
- )
-
- if convert_engin == "mineru" and (not mineru_token or not mineru_token.strip()):
- return JSONResponse(
- status_code=400,
- content={"task_started": False, "message": "使用 Mineru 引擎时必须提供有效的 Mineru Token。"}
- )
+ #可选的格式认证,这部分交给前端来写了
+ # if not file or not file.filename:
+ # return JSONResponse(
+ # status_code=400,
+ # content={"task_started": False, "message": "没有选择文件或文件无效。"}
+ # )
+ # if not file.filename.split(".")[-1] in ["md","txt"]:
+ # #需要填写 Mineru 引擎
+ # if convert_engin == "mineru" and (not mineru_token or not mineru_token.strip()) :
+ # return JSONResponse(
+ # status_code=400,
+ # content={"task_started": False, "message": "使用 Mineru 引擎时必须提供有效的 Mineru Token。"}
+ # )
current_state["is_processing"] = True
original_filename_for_init = file.filename or "uploaded_file"
diff --git a/docutranslate/static/index.html b/docutranslate/static/index.html
index 3c6cdf8..8edfb00 100644
--- a/docutranslate/static/index.html
+++ b/docutranslate/static/index.html
@@ -411,7 +411,7 @@
+ name="custom_prompt_translate" placeholder="翻译提示">
@@ -990,9 +990,9 @@
}
}
- form.addEventListener('submit', async function (event) {
+ submitButton.addEventListener('click', async function (event) {
event.preventDefault();
-
+ console.log(fileInput)
if (isTranslating) {
await cancelTranslation();
return;
@@ -1000,52 +1000,41 @@
[fileDropArea, mineruTokenInput, apikeyInput, modelInput, baseUrlInput].forEach(el => el.classList.remove('input-error'));
fileNameDisplay.classList.remove('input-error-text');
- let firstErrorElement = null;
- let currentStatusMsg = '';
- if (fileInput.files.length === 0) {
- currentStatusMsg += '请选择一个文件进行翻译。';
+ if (fileInput.files.length !== 1) {
+ statusMsg.textContent = '请选择一个文件进行翻译。';
+ statusMsg.className = 'error-message';
fileNameDisplay.textContent = '请选择文件!';
fileNameDisplay.classList.add('input-error-text');
fileDropArea.classList.add('input-error');
fileDropPrompt.classList.remove('hidden');
- if (!firstErrorElement) firstErrorElement = fileDropArea;
+ return
+ }
+ console.log(convertEnginSelect.value === 'mineru' && (!mineruTokenInput.value.trim()) && (!["md", "txt"].includes(fileInput.files[0].name.split('.').pop())))
+ if (convertEnginSelect.value === 'mineru' && !mineruTokenInput.value.trim() && (!["md", "txt"].includes(fileInput.files[0].name.split('.').pop()))) {
+ statusMsg.textContent = '使用 Mineru 引擎时,必须填写 Mineru Token。';
+ statusMsg.className = 'error-message';
+ mineruTokenInput.classList.add('input-error');
+ return
}
- if (convertEnginSelect.value === 'mineru' && !mineruTokenInput.value.trim()) {
- currentStatusMsg += (currentStatusMsg ? ' ' : '') + '使用 Mineru 引擎时,必须填写 Mineru Token。';
- mineruTokenInput.classList.add('input-error');
- if (!firstErrorElement) firstErrorElement = mineruTokenInput;
- }
if (!apikeyInput.value.trim()) {
- currentStatusMsg += (currentStatusMsg ? ' ' : '') + 'API 密钥不能为空。';
+ statusMsg.textContent = 'API 密钥不能为空。';
+ statusMsg.className = 'error-message';
apikeyInput.classList.add('input-error');
- if (!firstErrorElement) firstErrorElement = apikeyInput;
+ return
}
if (!modelInput.value.trim()) {
- currentStatusMsg += (currentStatusMsg ? ' ' : '') + '模型 ID 不能为空。';
+ statusMsg.textContent = '模型 ID 不能为空。';
+ statusMsg.className = 'error-message';
modelInput.classList.add('input-error');
- if (!firstErrorElement) firstErrorElement = modelInput;
+ return
}
if (platformSelect.value === 'custom' && !baseUrlInput.value.trim()) {
- currentStatusMsg += (currentStatusMsg ? ' ' : '') + '自定义接口时,API 地址不能为空。';
- baseUrlInput.classList.add('input-error');
- if (!firstErrorElement) firstErrorElement = baseUrlInput;
- }
-
- if (firstErrorElement) {
- statusMsg.textContent = currentStatusMsg;
+ statusMsg.textContent = '自定义接口时,API 地址不能为空。';
statusMsg.className = 'error-message';
- firstErrorElement.focus();
- setTimeout(() => {
- [fileDropArea, mineruTokenInput, apikeyInput, modelInput, baseUrlInput].forEach(el => el.classList.remove('input-error'));
- fileNameDisplay.classList.remove('input-error-text');
- if (fileNameDisplay.textContent === '请选择文件!' && fileInput.files.length === 0) {
- fileNameDisplay.textContent = '未选择文件';
- fileDropPrompt.classList.remove('hidden');
- }
- }, 3000);
- return;
+ baseUrlInput.classList.add('input-error');
+ return
}
stopPolling();
diff --git a/docutranslate/utils/markdown_splitter.py b/docutranslate/utils/markdown_splitter.py
index 44f27b6..ece4178 100644
--- a/docutranslate/utils/markdown_splitter.py
+++ b/docutranslate/utils/markdown_splitter.py
@@ -239,9 +239,10 @@ def split_markdown_text(markdown_text, max_block_size=5000):
def join_markdown_texts(markdown_texts: list[str]) -> str:
- result = ""
- pre = ""
- for text in markdown_texts:
+ if len(markdown_texts) == 0: return ""
+ result = markdown_texts[0]
+ pre = markdown_texts[0]
+ for text in markdown_texts[1:]:
# 只有表格会收到多余空行的影响
if text.lstrip().startswith("|") and pre.rstrip().endswith("|"):
result = result + "\n" + text