Bläddra i källkod

修正 Word 转换结果写回参数顺序

FileUtil.writeFile 的参数顺序为“内容、文件路径”,WordImportService 原先传反,导致 LibreOffice 已转换成功但写回失败并回退 Mammoth。现已修正,并让本地运行脚本自动发现可执行的 soffice 写入运行副本。

Validation:
- 本地 Word 导入实际成功
- 字体:黑体、宋体
- 字号:24px、21.33px
- 居中、两端对齐、红色、粗体、首行缩进 2em 均保留
- 混合粘贴、15M 图片限制回归通过
非繁 1 månad sedan
förälder
incheckning
bd1c51060c

+ 38 - 0
local-run/bin/sync-webroot-to-runtime.sh

@@ -16,3 +16,41 @@ rsync -a --delete "${PROJECT_ROOT}/WebRoot/" "${WEBAPP_DIR}/"
 echo "已同步 WebRoot -> ${WEBAPP_DIR}"
 
 "${SCRIPT_DIR}/apply-local-runtime-config.sh"
+
+if [[ "$(uname -s)" == "Darwin" ]]; then
+	libreoffice_path="${ZQ_LIBREOFFICE_MAC_PATH:-}"
+	if [[ -z "${libreoffice_path}" ]]; then
+		for candidate in \
+			"/Applications/LibreOffice.app/Contents/MacOS/soffice" \
+			"$(command -v soffice 2>/dev/null || true)" \
+			"$(command -v libreoffice 2>/dev/null || true)"; do
+			if [[ -n "${candidate}" && -x "${candidate}" ]]; then
+				libreoffice_path="${candidate}"
+				break
+			fi
+		done
+	fi
+
+	if [[ -n "${libreoffice_path}" && -x "${libreoffice_path}" ]]; then
+		/usr/bin/python3 - "${WEBAPP_DIR}/WEB-INF/application.xml" "${libreoffice_path}" <<'PY'
+import re
+import sys
+from pathlib import Path
+
+config = Path(sys.argv[1])
+path = sys.argv[2]
+content = config.read_text(encoding="utf-8")
+content, count = re.subn(
+    r"<libreOfficeMacOrMacOSXPath>.*?</libreOfficeMacOrMacOSXPath>",
+    f"<libreOfficeMacOrMacOSXPath>{path}</libreOfficeMacOrMacOSXPath>",
+    content,
+    count=1,
+)
+if count:
+    config.write_text(content, encoding="utf-8")
+PY
+		echo "本地 LibreOffice 路径:${libreoffice_path}"
+	else
+		echo "提醒:未找到可执行的 LibreOffice,Word 导入将回退 Mammoth 基础格式。"
+	fi
+fi

+ 1 - 1
src/space/core/apps/sys/service/WordImportService.java

@@ -50,7 +50,7 @@ public class WordImportService extends BaseTransaction {
 			String htmlFileName = LibreOfficeUtil.convertHtml(sourceFile.getAbsolutePath(), targetDir.getAbsolutePath());
 			File htmlFile = new File(targetDir, htmlFileName);
 			String htmlContent = normalizeHtml(htmlFile, targetRelativePath);
-			FileUtil.writeFile(htmlFile.getAbsolutePath(), htmlContent);
+			FileUtil.writeFile(htmlContent, htmlFile.getAbsolutePath());
 
 			result.put("code", "success");
 			result.put("msg", "转换成功");