|
@@ -802,88 +802,88 @@ public class SysController {
|
|
FileUtil.outputFile(response, new File(sysLogPath), "sys.log");
|
|
FileUtil.outputFile(response, new File(sysLogPath), "sys.log");
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "读取markdown文件")
|
|
|
|
- @RequestMapping(value = "/reader/markdown", method = RequestMethod.POST)
|
|
|
|
- @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
|
|
|
|
- @Aac(auth = false)
|
|
|
|
- public void readerMarkDown(@ApiParam(value = "md文件", required = true) @RequestParam MultipartFile file) throws IOException {
|
|
|
|
- File tempFile = null, finalTempFile = null;
|
|
|
|
- String yqUrl = "https://cdn.nlark.com", mkdir = "markDown";//语雀url
|
|
|
|
- try {
|
|
|
|
- String format = "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
|
- Objects.requireNonNull(format, "请上传文件");
|
|
|
|
-
|
|
|
|
- if (!Objects.equals(format, ".md")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("文件格式只能为.md");
|
|
|
|
- }
|
|
|
|
- String md5 = ServletUtil.getRequestMd5();
|
|
|
|
- Objects.requireNonNull(md5, "md5为空");
|
|
|
|
-
|
|
|
|
- String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
|
- if (!Objects.equals(fileMd5, md5)) {
|
|
|
|
- throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
|
- }
|
|
|
|
-// ByteArrayOutputStream ou = new ByteArrayOutputStream();
|
|
|
|
-// IOUtils.copy(file.getInputStream(), ou);
|
|
|
|
-// String string = new String(ou.toByteArray(), StandardCharsets.UTF_8);
|
|
|
|
-// log.info("string:{}", string);
|
|
|
|
-
|
|
|
|
- tempFile = SystemConstant.getFileTempVar(".md");
|
|
|
|
- file.transferTo(tempFile);
|
|
|
|
- BufferedReader reader = new BufferedReader(new FileReader(tempFile));
|
|
|
|
- String line = null;
|
|
|
|
- StringJoiner stringJoiner = new StringJoiner("\n");
|
|
|
|
- while ((line = reader.readLine()) != null) {
|
|
|
|
- // 处理每一行
|
|
|
|
- if (Objects.nonNull(line) && line.indexOf(yqUrl) != -1) {
|
|
|
|
- String url = StringUtils.substringBetween(line, "(", ")");
|
|
|
|
- String imgFormat = StringUtils.substringAfterLast(url, ".");
|
|
|
|
- Objects.requireNonNull(imgFormat, "图片格式为空");
|
|
|
|
-
|
|
|
|
- File imgUrlTempFile = null;
|
|
|
|
- imgUrlTempFile = SystemConstant.getFileTempVar("." + imgFormat);
|
|
|
|
- try {
|
|
|
|
- HttpUtil.downloadImage(url, imgUrlTempFile.getPath(), imgFormat);
|
|
|
|
- String imageMd5 = DigestUtils.md5Hex(new FileInputStream(imgUrlTempFile));
|
|
|
|
- String path = mkdir + File.separator + FssUtils.buildPath(UploadFileEnum.FILE.getTitle(), SystemConstant.getNanoId() + "." + imgFormat);
|
|
|
|
- fileStoreUtil.ossUpload(path, imgUrlTempFile, imageMd5, UploadFileEnum.FILE.getFssType());
|
|
|
|
- JSONObject json = new JSONObject();
|
|
|
|
- json.put(SystemConstant.PATH, path);
|
|
|
|
- json.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
|
- json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
|
- json.put(SystemConstant.MD5, imageMd5);
|
|
|
|
- String imgUrl = fileUploadService.filePreview(json.toJSONString());
|
|
|
|
- line = line.replaceAll(url, imgUrl);
|
|
|
|
- } finally {
|
|
|
|
- if (Objects.nonNull(imgUrlTempFile)) {
|
|
|
|
- imgUrlTempFile.delete();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- stringJoiner.add(line);
|
|
|
|
- }
|
|
|
|
- log.info("stringJoiner:{}", stringJoiner);
|
|
|
|
- HttpServletResponse response = (HttpServletResponse) ServletUtil.getResponse();
|
|
|
|
- finalTempFile = SystemConstant.getFileTempVar(".md");
|
|
|
|
- String fileName = FilenameUtils.getName(finalTempFile.getPath());
|
|
|
|
- // 使用response对象设置文件名
|
|
|
|
- response.setContentType("text/plain");
|
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
|
-
|
|
|
|
- // 导出文件
|
|
|
|
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
|
|
|
|
- writer.write(stringJoiner.toString());
|
|
|
|
- writer.flush();
|
|
|
|
- writer.close();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
- } finally {
|
|
|
|
- if (Objects.nonNull(tempFile)) {
|
|
|
|
- tempFile.delete();
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(finalTempFile)) {
|
|
|
|
- finalTempFile.delete();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// @ApiOperation(value = "读取markdown文件")
|
|
|
|
+// @RequestMapping(value = "/reader/markdown", method = RequestMethod.POST)
|
|
|
|
+// @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
|
|
|
|
+// @Aac(auth = false)
|
|
|
|
+// public void readerMarkDown(@ApiParam(value = "md文件", required = true) @RequestParam MultipartFile file) throws IOException {
|
|
|
|
+// File tempFile = null, finalTempFile = null;
|
|
|
|
+// String yqUrl = "https://cdn.nlark.com", mkdir = "markDown";//语雀url
|
|
|
|
+// try {
|
|
|
|
+// String format = "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
|
+// Objects.requireNonNull(format, "请上传文件");
|
|
|
|
+//
|
|
|
|
+// if (!Objects.equals(format, ".md")) {
|
|
|
|
+// throw ExceptionResultEnum.ERROR.exception("文件格式只能为.md");
|
|
|
|
+// }
|
|
|
|
+// String md5 = ServletUtil.getRequestMd5();
|
|
|
|
+// Objects.requireNonNull(md5, "md5为空");
|
|
|
|
+//
|
|
|
|
+// String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
|
+// if (!Objects.equals(fileMd5, md5)) {
|
|
|
|
+// throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
|
+// }
|
|
|
|
+//// ByteArrayOutputStream ou = new ByteArrayOutputStream();
|
|
|
|
+//// IOUtils.copy(file.getInputStream(), ou);
|
|
|
|
+//// String string = new String(ou.toByteArray(), StandardCharsets.UTF_8);
|
|
|
|
+//// log.info("string:{}", string);
|
|
|
|
+//
|
|
|
|
+// tempFile = SystemConstant.getFileTempVar(".md");
|
|
|
|
+// file.transferTo(tempFile);
|
|
|
|
+// BufferedReader reader = new BufferedReader(new FileReader(tempFile));
|
|
|
|
+// String line = null;
|
|
|
|
+// StringJoiner stringJoiner = new StringJoiner("\n");
|
|
|
|
+// while ((line = reader.readLine()) != null) {
|
|
|
|
+// // 处理每一行
|
|
|
|
+// if (Objects.nonNull(line) && line.indexOf(yqUrl) != -1) {
|
|
|
|
+// String url = StringUtils.substringBetween(line, "(", ")");
|
|
|
|
+// String imgFormat = StringUtils.substringAfterLast(url, ".");
|
|
|
|
+// Objects.requireNonNull(imgFormat, "图片格式为空");
|
|
|
|
+//
|
|
|
|
+// File imgUrlTempFile = null;
|
|
|
|
+// imgUrlTempFile = SystemConstant.getFileTempVar("." + imgFormat);
|
|
|
|
+// try {
|
|
|
|
+// HttpUtil.downloadImage(url, imgUrlTempFile.getPath(), imgFormat);
|
|
|
|
+// String imageMd5 = DigestUtils.md5Hex(new FileInputStream(imgUrlTempFile));
|
|
|
|
+// String path = mkdir + File.separator + FssUtils.buildPath(UploadFileEnum.FILE.getTitle(), SystemConstant.getNanoId() + "." + imgFormat);
|
|
|
|
+// fileStoreUtil.ossUpload(path, imgUrlTempFile, imageMd5, UploadFileEnum.FILE.getFssType());
|
|
|
|
+// JSONObject json = new JSONObject();
|
|
|
|
+// json.put(SystemConstant.PATH, path);
|
|
|
|
+// json.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
|
+// json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
|
+// json.put(SystemConstant.MD5, imageMd5);
|
|
|
|
+// String imgUrl = fileUploadService.filePreview(json.toJSONString());
|
|
|
|
+// line = line.replaceAll(url, imgUrl);
|
|
|
|
+// } finally {
|
|
|
|
+// if (Objects.nonNull(imgUrlTempFile)) {
|
|
|
|
+// imgUrlTempFile.delete();
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// stringJoiner.add(line);
|
|
|
|
+// }
|
|
|
|
+// log.info("stringJoiner:{}", stringJoiner);
|
|
|
|
+// HttpServletResponse response = (HttpServletResponse) ServletUtil.getResponse();
|
|
|
|
+// finalTempFile = SystemConstant.getFileTempVar(".md");
|
|
|
|
+// String fileName = FilenameUtils.getName(finalTempFile.getPath());
|
|
|
|
+// // 使用response对象设置文件名
|
|
|
|
+// response.setContentType("text/plain");
|
|
|
|
+// response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
|
+//
|
|
|
|
+// // 导出文件
|
|
|
|
+// BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
|
|
|
|
+// writer.write(stringJoiner.toString());
|
|
|
|
+// writer.flush();
|
|
|
|
+// writer.close();
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+// } finally {
|
|
|
|
+// if (Objects.nonNull(tempFile)) {
|
|
|
|
+// tempFile.delete();
|
|
|
|
+// }
|
|
|
|
+// if (Objects.nonNull(finalTempFile)) {
|
|
|
|
+// finalTempFile.delete();
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
}
|
|
}
|