feat: 在线编辑转换文件解密

This commit is contained in:
2024-04-23 11:43:41 +08:00
parent ef4f27ddab
commit 2f3a4044a7
3 changed files with 36 additions and 4 deletions
@@ -70,6 +70,36 @@ public class IntekeyUtils {
}
}
public static InputStream autoDecryptInputStreamFile(InputStream inputStream, String fileName) throws IOException {
if (!ENABLE || inputStream == null) {
return inputStream;
}
MultipartFile multipartFile = convertMultipart(inputStream, fileName);
// 将文件解密
try {
return IntekeyUtils.decryptFile(DECRYPT_URL, DECRYPT_APP_CODE, DECRYPT_SECRET_KEY, null, multipartFile);
} catch (Exception e) {
log.error("文件解密失败,返回原文件");
return inputStream;
}
}
public static MultipartFile convertMultipart(InputStream is, String fileName) throws IOException {
// 假定文件名和内容类型已知
String contentType = "application/octet-stream"; // 或其他类型
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
byte[] byteArray = buffer.toByteArray();
// 使用MockMultipartFile创建MultipartFile
return new MockMultipartFile(fileName, fileName, contentType, byteArray);
}
/**
* 解密文件,返回InputStream,供excel使用
@@ -375,7 +375,8 @@ public class OnlyOfficeController {
doc.getSections().get(0).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
for (; i < Integer.MAX_VALUE; i++) {
if (i == 1) {
doc.getSections().get(1).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
doc.getSections().get(i).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
doc.getSections().get(i).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
}
doc.getSections().get(i).getPageSetup().setOrientation(PageOrientation.Portrait);//纵向
}
@@ -383,8 +384,6 @@ public class OnlyOfficeController {
log.info("设置纵向页面,循环次数为:{}", i + 1);
}
doc.getSections().get(1).getPageSetup().setPageNumberStyle(PageNumberStyle.Roman_Upper);
String downloadDocxFileTempUrl = filePath + "/downloadDocxFileTemp";
File downloadDocxFileTempUrlFile = new File(downloadDocxFileTempUrl);
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.exception.JeroBootException;
import com.jero.common.util.CommonUtils;
import com.jero.common.util.IntekeyUtils;
import com.jero.common.util.MinioUtil;
import com.jero.common.util.oConvertUtils;
import com.jero.modules.laws.common.constant.FieldCommon;
@@ -136,10 +137,12 @@ public class BusProcessModelHisServiceImpl extends ServiceImpl<BusProcessModelHi
String url = fileUrl.replace(minioUrl, "");
InputStream minioFile = MinioUtil.getMinioFile(MinioUtil.getBucketName(), url);
// 需要将文件解密
minioFile = IntekeyUtils.autoDecryptInputStreamFile(minioFile, ossFile.getFileName());
File targetFile = new File(filePath + targetPath);
try (OutputStream outputStream = new FileOutputStream(targetFile)) {
try (OutputStream outputStream = Files.newOutputStream(targetFile.toPath())) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = minioFile.read(buffer)) != -1) {