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