Commit c64295f432999bc3cb76f06931fc50ef7ccc0dfc
1 parent
6a1c09ca
合并fetch代码
Showing
7 changed files
with
21 additions
and
17 deletions
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApi.java
| @@ -14,7 +14,7 @@ public interface FileApi { | @@ -14,7 +14,7 @@ public interface FileApi { | ||
| 14 | * @return 文件路径 | 14 | * @return 文件路径 |
| 15 | */ | 15 | */ |
| 16 | default String createFile(byte[] content) { | 16 | default String createFile(byte[] content) { |
| 17 | - return createFile(null, null, "application/octet-stream", content); | 17 | + return createFile(null, null, content); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| @@ -25,18 +25,17 @@ public interface FileApi { | @@ -25,18 +25,17 @@ public interface FileApi { | ||
| 25 | * @return 文件路径 | 25 | * @return 文件路径 |
| 26 | */ | 26 | */ |
| 27 | default String createFile(String path, byte[] content) { | 27 | default String createFile(String path, byte[] content) { |
| 28 | - return createFile(null, path, "application/octet-stream", content); | 28 | + return createFile(null, path, content); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | /** | 31 | /** |
| 32 | * 保存文件,并返回文件的访问路径 | 32 | * 保存文件,并返回文件的访问路径 |
| 33 | * | 33 | * |
| 34 | - * @param name 文件名称 | ||
| 35 | - * @param path 文件路径 | ||
| 36 | - * @param mimeType 文件类型 | ||
| 37 | - * @param content 文件内容 | 34 | + * @param name 文件名称 |
| 35 | + * @param path 文件路径 | ||
| 36 | + * @param content 文件内容 | ||
| 38 | * @return 文件路径 | 37 | * @return 文件路径 |
| 39 | */ | 38 | */ |
| 40 | - String createFile(String name, String path, String mimeType, byte[] content); | 39 | + String createFile(String name, String path, byte[] content); |
| 41 | 40 | ||
| 42 | } | 41 | } |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApiImpl.java
| @@ -19,8 +19,8 @@ public class FileApiImpl implements FileApi { | @@ -19,8 +19,8 @@ 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, String mimeType, byte[] content) { | ||
| 23 | - return fileService.createFile(name, path, mimeType, content); | 22 | + public String createFile(String name, String path, byte[] content) { |
| 23 | + return fileService.createFile(name, path, content); | ||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | } | 26 | } |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
| @@ -47,7 +47,7 @@ public class FileController { | @@ -47,7 +47,7 @@ public class FileController { | ||
| 47 | @OperateLog(logArgs = false) // 上传文件,没有记录操作日志的必要 | 47 | @OperateLog(logArgs = false) // 上传文件,没有记录操作日志的必要 |
| 48 | public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file, | 48 | public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file, |
| 49 | @RequestParam(value = "path", required = false) String path) throws Exception { | 49 | @RequestParam(value = "path", required = false) String path) throws Exception { |
| 50 | - return success(fileService.createFile(file.getOriginalFilename(), path, file.getContentType(), IoUtil.readBytes(file.getInputStream()))); | 50 | + return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()))); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | @DeleteMapping("/delete") | 53 | @DeleteMapping("/delete") |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/file/FileDO.java
| @@ -38,16 +38,15 @@ public class FileDO extends BaseDO { | @@ -38,16 +38,15 @@ public class FileDO extends BaseDO { | ||
| 38 | */ | 38 | */ |
| 39 | private String name; | 39 | private String name; |
| 40 | /** | 40 | /** |
| 41 | - * 路径,即文件名,唯一不可重复 | 41 | + * 路径,即文件名 |
| 42 | */ | 42 | */ |
| 43 | private String path; | 43 | private String path; |
| 44 | /** | 44 | /** |
| 45 | * 访问地址 | 45 | * 访问地址 |
| 46 | */ | 46 | */ |
| 47 | private String url; | 47 | private String url; |
| 48 | - | ||
| 49 | /** | 48 | /** |
| 50 | - * 文件的MIME类型,默认为"application/octet-stream" | 49 | + * 文件的MIME类型,例如"application/octet-stream" |
| 51 | */ | 50 | */ |
| 52 | private String type; | 51 | private String type; |
| 53 | /** | 52 | /** |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java
| @@ -24,11 +24,10 @@ public interface FileService { | @@ -24,11 +24,10 @@ public interface FileService { | ||
| 24 | * | 24 | * |
| 25 | * @param name 文件名称 | 25 | * @param name 文件名称 |
| 26 | * @param path 文件路径 | 26 | * @param path 文件路径 |
| 27 | - * @param mimeType 文件MIME类型 | ||
| 28 | * @param content 文件内容 | 27 | * @param content 文件内容 |
| 29 | * @return 文件路径 | 28 | * @return 文件路径 |
| 30 | */ | 29 | */ |
| 31 | - String createFile(String name, String path, String mimeType,byte[] content); | 30 | + String createFile(String name, String path, byte[] content); |
| 32 | 31 | ||
| 33 | /** | 32 | /** |
| 34 | * 删除文件 | 33 | * 删除文件 |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
| @@ -40,11 +40,16 @@ public class FileServiceTest extends BaseDbUnitTest { | @@ -40,11 +40,16 @@ public class FileServiceTest extends BaseDbUnitTest { | ||
| 40 | // mock 数据 | 40 | // mock 数据 |
| 41 | FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到 | 41 | FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到 |
| 42 | o.setPath("yunai"); | 42 | o.setPath("yunai"); |
| 43 | + o.setType("image/jpg"); | ||
| 43 | o.setCreateTime(buildTime(2021, 1, 15)); | 44 | o.setCreateTime(buildTime(2021, 1, 15)); |
| 44 | }); | 45 | }); |
| 45 | fileMapper.insert(dbFile); | 46 | fileMapper.insert(dbFile); |
| 46 | // 测试 path 不匹配 | 47 | // 测试 path 不匹配 |
| 47 | fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setPath("tudou"))); | 48 | fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setPath("tudou"))); |
| 49 | + // 测试 type 不匹配 | ||
| 50 | + fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { | ||
| 51 | + o.setType("image/png"); | ||
| 52 | + })); | ||
| 48 | // 测试 createTime 不匹配 | 53 | // 测试 createTime 不匹配 |
| 49 | fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { | 54 | fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { |
| 50 | o.setCreateTime(buildTime(2020, 1, 15)); | 55 | o.setCreateTime(buildTime(2020, 1, 15)); |
| @@ -77,7 +82,7 @@ public class FileServiceTest extends BaseDbUnitTest { | @@ -77,7 +82,7 @@ public class FileServiceTest extends BaseDbUnitTest { | ||
| 77 | when(client.getId()).thenReturn(10L); | 82 | when(client.getId()).thenReturn(10L); |
| 78 | String name = "单测文件名"; | 83 | String name = "单测文件名"; |
| 79 | // 调用 | 84 | // 调用 |
| 80 | - String result = fileService.createFile(name, path, "application/octet-stream", content); | 85 | + String result = fileService.createFile(name, path, content); |
| 81 | // 断言 | 86 | // 断言 |
| 82 | assertEquals(result, url); | 87 | assertEquals(result, url); |
| 83 | // 校验数据 | 88 | // 校验数据 |
| @@ -85,6 +90,7 @@ public class FileServiceTest extends BaseDbUnitTest { | @@ -85,6 +90,7 @@ public class FileServiceTest extends BaseDbUnitTest { | ||
| 85 | assertEquals(10L, file.getConfigId()); | 90 | assertEquals(10L, file.getConfigId()); |
| 86 | assertEquals(path, file.getPath()); | 91 | assertEquals(path, file.getPath()); |
| 87 | assertEquals(url, file.getUrl()); | 92 | assertEquals(url, file.getUrl()); |
| 93 | + assertEquals("image/jpg", file.getType()); | ||
| 88 | assertEquals(content.length, file.getSize()); | 94 | assertEquals(content.length, file.getSize()); |
| 89 | } | 95 | } |
| 90 | 96 |
yudao-ui-admin/src/views/infra/file/index.vue
| @@ -108,7 +108,8 @@ export default { | @@ -108,7 +108,8 @@ export default { | ||
| 108 | queryParams: { | 108 | queryParams: { |
| 109 | pageNo: 1, | 109 | pageNo: 1, |
| 110 | pageSize: 10, | 110 | pageSize: 10, |
| 111 | - path: null | 111 | + path: null, |
| 112 | + type: null, | ||
| 112 | }, | 113 | }, |
| 113 | // 用户导入参数 | 114 | // 用户导入参数 |
| 114 | upload: { | 115 | upload: { |