修复kkfile预览加密文件问题、修改文件下载验证码发送模板
This commit is contained in:
@@ -52,7 +52,7 @@ public class FileController {
|
||||
private FileService fileService;
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获取文件预览地址", description = "根据 fileId 返回文件预览 url(kkfile)")
|
||||
@Operation(summary = "获取文件预览地址", description = "根据 fileId 返回文件预览 url(kkfile),支持加密文件预览,需要传递验证码 code,加密文件预览地址默认5分钟内有效,可在配置文件中添加zt.file.preview-expire-seconds配置")
|
||||
public CommonResult<FileRespVO> getPreviewUrl(@RequestParam("fileId") Long fileId,
|
||||
@RequestParam(value = "code", required = false) String code,
|
||||
HttpServletRequest request) throws Exception {
|
||||
@@ -83,9 +83,18 @@ public class FileController {
|
||||
String token = fileService.generatePreviewToken(fileId, userId);
|
||||
|
||||
String baseUrl = buildPublicBaseUrl(request); // 见下方函数
|
||||
String decryptUrl = baseUrl + "/admin-api/infra/file/preview-decrypt?fileId=" + fileId + "&token=" + token;
|
||||
|
||||
String fullfilename = java.net.URLEncoder
|
||||
.encode(fileDO.getName(), java.nio.charset.StandardCharsets.UTF_8)
|
||||
.replace("+", "%20");
|
||||
|
||||
String decryptUrl = baseUrl + "/admin-api/infra/file/preview-decrypt"
|
||||
+ "?fileId=" + fileId
|
||||
+ "&token=" + token
|
||||
+ "&fullfilename=" + fullfilename;
|
||||
|
||||
fileRespVO.setUrl(decryptUrl);
|
||||
log.info("decryptUrl={}, urlFieldAfterSet={}", decryptUrl, fileRespVO.getUrl());
|
||||
log.info("decryptUrl={}", decryptUrl);
|
||||
}
|
||||
|
||||
return success(fileRespVO);
|
||||
@@ -194,7 +203,7 @@ public class FileController {
|
||||
writeAttachment(response, fileDO.getName(), content);
|
||||
}
|
||||
@GetMapping("/generate-download-code")
|
||||
@Operation(summary = "获取下载验证码")
|
||||
@Operation(summary = "获取下载验证码", description = "默认仅生成验证码,如果需要发短信或e办通知,请传递sendType参数,可选值:SMS / E_OFFICE")
|
||||
public CommonResult<FileRespVO> preDownloadEncrypt(@RequestParam("fileId") Long fileId,
|
||||
@RequestParam(value = "sendType", required = false) String sendType // 可选:SMS / E_OFFICE
|
||||
) {
|
||||
@@ -241,9 +250,10 @@ public class FileController {
|
||||
@GetMapping("/preview-decrypt")
|
||||
@PermitAll
|
||||
@TenantIgnore
|
||||
@Operation(summary = "加密文件预览解密流(供 kkfile 拉取)")
|
||||
@Operation(summary = "加密文件预览解密流", description = "仅供 kkfile 用于拉取解密文件流,调用接口需要传递临时token")
|
||||
public void previewDecrypt(@RequestParam("fileId") Long fileId,
|
||||
@RequestParam("token") String token,
|
||||
@RequestParam(value = "fullfilename", required = false) String fullfilename,
|
||||
HttpServletResponse response) throws Exception {
|
||||
|
||||
boolean ok = fileService.verifyPreviewToken(fileId, token);
|
||||
@@ -259,11 +269,14 @@ public class FileController {
|
||||
}
|
||||
|
||||
// byte[] content = fileService.getDecryptedBytes(fileId);
|
||||
// 返回正确 Content-Type(pdf/docx/xlsx 等)
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
response.setContentType(fileDO.getType());
|
||||
|
||||
String filename = java.net.URLEncoder.encode(fileDO.getName(), java.nio.charset.StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-Disposition", "inline; filename*=UTF-8''" + filename);
|
||||
// 返回 inline + 文件名(对部分 kkfile 版本也有帮助)
|
||||
String filename = fileDO.getName();
|
||||
String encoded = java.net.URLEncoder.encode(filename, java.nio.charset.StandardCharsets.UTF_8).replace("+", "%20");
|
||||
response.setHeader("Content-Disposition", "inline; filename*=UTF-8''" + encoded);
|
||||
|
||||
// cn.hutool.core.io.IoUtil.write(response.getOutputStream(), true, content);
|
||||
fileService.writeDecryptedToStream(fileId, response.getOutputStream());
|
||||
|
||||
@@ -93,14 +93,14 @@ public class FileServiceImpl implements FileService {
|
||||
if(loginUser.getInfo().get(LoginUser.INFO_KEY_PHONE)!=null)
|
||||
smsSendReqDTO.setMobile(loginUser.getInfo().get(LoginUser.INFO_KEY_PHONE));
|
||||
smsSendReqDTO.setUserId(loginUser.getId());
|
||||
smsSendReqDTO.setTemplateCode("test_02");
|
||||
smsSendReqDTO.setTemplateCode("infra_file_download_code"); // 短信通知模板,上生产需要同步创建
|
||||
smsSendReqDTO.setTemplateParams(templateParams);
|
||||
smsSendApi.sendSingleSmsToAdmin(smsSendReqDTO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (VerifyCodeSendType.E_OFFICE.equals(verifyCodeSendType)) {
|
||||
// TODO 预留实现接口
|
||||
// TODO 预留实现e办通知接口
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user