Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions freemarker-tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ freemarker工具
| jsonData | String | 模板数据 |
| imageMap | Map<String,String> | k=图片名称,v=图片信息 |
| base64 | Boolean | 图片是否编码<br/><ul><li>false:传入图片url</li><li>true:传入图片base64编码</li></ul> |
| processImgTag | Boolean | 是否将富文本中的`&lt;img&gt;`标签转换为 Word 图片,默认 false |


# 如何制作docx模板
Expand Down
9 changes: 7 additions & 2 deletions freemarker-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.netease.lowcode</groupId>
<artifactId>freemarker-tool</artifactId>
<!-- We currently do not support snapshots. Please use a testing version number like 0.x.x, e.g. 0.1.12 -->
<version>1.2.5</version>
<version>1.3.7</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -99,6 +99,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-webp</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -152,4 +157,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public class CreateDocxRequest {
* 如果为true,表示图片传入的是base64编码
*/
public Boolean base64 = false;

/**
* 是否将富文本中的img标签转换为图片
*/
public Boolean processImgTag = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,46 @@
import java.net.URL;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class FileUtil {

private static final Logger logger = LoggerFactory.getLogger("LCAP_CUSTOMIZE_LOGGER");

private static final OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.followRedirects(true)
.followSslRedirects(true)
.build();

public static InputStream getFileInputStream(String urlStr) throws IOException {
URL url = new URL(getTrueUrl(urlStr));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(3 * 1000);
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36");
return url.openStream();
logger.info("urlStr using OkHttp: {}", urlStr);

// 还是保留你原本的 URL 处理逻辑
String finalUrl = getTrueUrl(urlStr);

Request request = new Request.Builder()
.url(finalUrl)
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36")
.build();

// 执行请求
Response response = client.newCall(request).execute();

if (!response.isSuccessful()) {
// 如果失败(比如 404 或 500),必须关闭响应体并抛出异常
response.close();
throw new IOException("Unexpected code " + response);
}

ResponseBody body = response.body();
if (body == null) {
response.close();
throw new IOException("Response body is null");
}

return body.byteStream();
}

// 新增方法:检测 URL 是否已经编码
Expand Down
Loading
Loading