Commit 9c5befaf9dd0f830705b2aef89ed18bea3e1b570

Authored by YunaiV
1 parent d3fe1876

统一 FileApi 的封装,与 yudao-cloud~

yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApi.java
... ... @@ -13,7 +13,7 @@ public interface FileApi {
13 13 * @param content 文件内容
14 14 * @return 文件路径
15 15 */
16   - default String createFile(byte[] content) throws Exception {
  16 + default String createFile(byte[] content) {
17 17 return createFile(null, null, content);
18 18 }
19 19  
... ... @@ -24,18 +24,18 @@ public interface FileApi {
24 24 * @param content 文件内容
25 25 * @return 文件路径
26 26 */
27   - default String createFile(String path, byte[] content) throws Exception {
  27 + default String createFile(String path, byte[] content) {
28 28 return createFile(null, path, content);
29 29 }
30 30  
31 31 /**
32 32 * 保存文件,并返回文件的访问路径
33 33 *
34   - * @param name 原文件名称
  34 + * @param name 文件名称
35 35 * @param path 文件路径
36 36 * @param content 文件内容
37 37 * @return 文件路径
38 38 */
39   - String createFile(String name, String path, byte[] content) throws Exception;
  39 + String createFile(String name, String path, byte[] content);
40 40  
41 41 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApiImpl.java
... ... @@ -19,7 +19,7 @@ public class FileApiImpl implements FileApi {
19 19 private FileService fileService;
20 20  
21 21 @Override
22   - public String createFile(String name, String path, byte[] content) throws Exception {
  22 + public String createFile(String name, String path, byte[] content) {
23 23 return fileService.createFile(name, path, content);
24 24 }
25 25  
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java
... ... @@ -22,12 +22,12 @@ public interface FileService {
22 22 /**
23 23 * 保存文件,并返回文件的访问路径
24 24 *
25   - * @param name 原文件名称
  25 + * @param name 文件名称
26 26 * @param path 文件路径
27 27 * @param content 文件内容
28 28 * @return 文件路径
29 29 */
30   - String createFile(String name, String path, byte[] content) throws Exception;
  30 + String createFile(String name, String path, byte[] content);
31 31  
32 32 /**
33 33 * 删除文件
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
... ... @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.file.core.client.FileClient;
9 9 import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
10 10 import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
11 11 import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper;
  12 +import lombok.SneakyThrows;
12 13 import org.springframework.stereotype.Service;
13 14  
14 15 import javax.annotation.Resource;
... ... @@ -37,7 +38,8 @@ public class FileServiceImpl implements FileService {
37 38 }
38 39  
39 40 @Override
40   - public String createFile(String name, String path, byte[] content) throws Exception {
  41 + @SneakyThrows
  42 + public String createFile(String name, String path, byte[] content) {
41 43 // 计算默认的 path 名
42 44 String type = FileTypeUtil.getType(new ByteArrayInputStream(content), name);
43 45 if (StrUtil.isEmpty(path)) {
... ...