|
@@ -97,24 +97,25 @@ public class MyConsumer extends Consumer<Course> {
|
|
|
if (StringUtils.isBlank(str)) {
|
|
|
return str;
|
|
|
}
|
|
|
- StringBuffer sb = new StringBuffer("");
|
|
|
Matcher matcher = imgPat.matcher(str);
|
|
|
-
|
|
|
+ Map<String, String> srcMap = new HashMap<>();
|
|
|
while (matcher.find()) {
|
|
|
String imgSrc = matcher.group(1).trim();
|
|
|
- String suff = imgSrc.substring(imgSrc.lastIndexOf(".") + 1).toLowerCase();
|
|
|
- File img = new File(paperDir + subid + "/" + UUID.randomUUID() + "." + suff);
|
|
|
- FileUtil.saveUrlAs(imgSrc, img.getAbsolutePath());
|
|
|
- String base64 = FileUtil.fileToBase64Src(img);
|
|
|
- matcher.appendReplacement(sb, base64);
|
|
|
+ if (imgSrc.toLowerCase().trim().startsWith("http")) {
|
|
|
+ if (srcMap.get(imgSrc) == null) {
|
|
|
+ String suff = imgSrc.substring(imgSrc.lastIndexOf(".") + 1).toLowerCase();
|
|
|
+ File img = new File(paperDir + subid + "/" + UUID.randomUUID() + "." + suff);
|
|
|
+ FileUtil.saveUrlAs(imgSrc, img.getAbsolutePath());
|
|
|
+ String base64 = FileUtil.fileToBase64Src(img);
|
|
|
+ img.delete();
|
|
|
+ srcMap.put(imgSrc, base64);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(sb.toString())) {
|
|
|
- return str;
|
|
|
- } else {
|
|
|
- matcher.appendTail(sb);
|
|
|
- return sb.toString();
|
|
|
+ for (String imgSrc : srcMap.keySet()) {
|
|
|
+ str = str.replaceAll(imgSrc, srcMap.get(imgSrc));
|
|
|
}
|
|
|
+ return str;
|
|
|
}
|
|
|
|
|
|
private List<QuestionProp> getQuestionProp(Connection connect, List<KdQuestion> qs) {
|