Ver código fonte

修复Word转换图片文件读取权限

LibreOffice 生成的 Word 图片初始权限可能为 640 root:root,补充转换目录和文件的世界可读权限,避免 Web 节点无法加载图片。

Validation:\n- bash local-run/bin/compile-hxcs-deploy-classes.sh\n- git diff --cached --check
非繁 2 semanas atrás
pai
commit
7daec192d9

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

@@ -51,6 +51,7 @@ public class WordImportService extends BaseTransaction {
 			File htmlFile = new File(targetDir, htmlFileName);
 			File htmlFile = new File(targetDir, htmlFileName);
 			String htmlContent = normalizeHtml(htmlFile, targetRelativePath);
 			String htmlContent = normalizeHtml(htmlFile, targetRelativePath);
 			FileUtil.writeFile(htmlContent, htmlFile.getAbsolutePath());
 			FileUtil.writeFile(htmlContent, htmlFile.getAbsolutePath());
+			ensureConvertedFilesReadable(targetDir);
 
 
 			result.put("code", "success");
 			result.put("code", "success");
 			result.put("msg", "转换成功");
 			result.put("msg", "转换成功");
@@ -77,4 +78,18 @@ public class WordImportService extends BaseTransaction {
 		}
 		}
 		return document.select("body").eq(0).html();
 		return document.select("body").eq(0).html();
 	}
 	}
+
+	private void ensureConvertedFilesReadable(File targetDir) {
+		targetDir.setReadable(true, false);
+		targetDir.setExecutable(true, false);
+		File[] files = targetDir.listFiles();
+		if (files == null) {
+			return;
+		}
+		for (File file : files) {
+			if (file.isFile()) {
+				file.setReadable(true, false);
+			}
+		}
+	}
 }
 }