合并fetch代码

This commit is contained in:
jiangqiang 2022-07-09 10:41:06 +08:00
parent 6a1c09ca42
commit c64295f432
7 changed files with 21 additions and 17 deletions

View File

@ -14,7 +14,7 @@ public interface FileApi {
* @return 文件路径 * @return 文件路径
*/ */
default String createFile(byte[] content) { default String createFile(byte[] content) {
return createFile(null, null, "application/octet-stream", content); return createFile(null, null, content);
} }
/** /**
@ -25,18 +25,17 @@ public interface FileApi {
* @return 文件路径 * @return 文件路径
*/ */
default String createFile(String path, byte[] content) { default String createFile(String path, byte[] content) {
return createFile(null, path, "application/octet-stream", content); return createFile(null, path, content);
} }
/** /**
* 保存文件并返回文件的访问路径 * 保存文件并返回文件的访问路径
* *
* @param name 文件名称 * @param name 文件名称
* @param path 文件路径 * @param path 文件路径
* @param mimeType 文件类型 * @param content 文件内容
* @param content 文件内容
* @return 文件路径 * @return 文件路径
*/ */
String createFile(String name, String path, String mimeType, byte[] content); String createFile(String name, String path, byte[] content);
} }

View File

@ -19,8 +19,8 @@ public class FileApiImpl implements FileApi {
private FileService fileService; private FileService fileService;
@Override @Override
public String createFile(String name, String path, String mimeType, byte[] content) { public String createFile(String name, String path, byte[] content) {
return fileService.createFile(name, path, mimeType, content); return fileService.createFile(name, path, content);
} }
} }

View File

@ -47,7 +47,7 @@ public class FileController {
@OperateLog(logArgs = false) // 上传文件没有记录操作日志的必要 @OperateLog(logArgs = false) // 上传文件没有记录操作日志的必要
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file, public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
@RequestParam(value = "path", required = false) String path) throws Exception { @RequestParam(value = "path", required = false) String path) throws Exception {
return success(fileService.createFile(file.getOriginalFilename(), path, file.getContentType(), IoUtil.readBytes(file.getInputStream()))); return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
} }
@DeleteMapping("/delete") @DeleteMapping("/delete")

View File

@ -38,16 +38,15 @@ public class FileDO extends BaseDO {
*/ */
private String name; private String name;
/** /**
* 路径即文件名唯一不可重复 * 路径即文件名
*/ */
private String path; private String path;
/** /**
* 访问地址 * 访问地址
*/ */
private String url; private String url;
/** /**
* 文件的MIME类型默认为"application/octet-stream" * 文件的MIME类型例如"application/octet-stream"
*/ */
private String type; private String type;
/** /**

View File

@ -24,11 +24,10 @@ public interface FileService {
* *
* @param name 文件名称 * @param name 文件名称
* @param path 文件路径 * @param path 文件路径
* @param mimeType 文件MIME类型
* @param content 文件内容 * @param content 文件内容
* @return 文件路径 * @return 文件路径
*/ */
String createFile(String name, String path, String mimeType,byte[] content); String createFile(String name, String path, byte[] content);
/** /**
* 删除文件 * 删除文件

View File

@ -40,11 +40,16 @@ public class FileServiceTest extends BaseDbUnitTest {
// mock 数据 // mock 数据
FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到 FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到
o.setPath("yunai"); o.setPath("yunai");
o.setType("image/jpg");
o.setCreateTime(buildTime(2021, 1, 15)); o.setCreateTime(buildTime(2021, 1, 15));
}); });
fileMapper.insert(dbFile); fileMapper.insert(dbFile);
// 测试 path 不匹配 // 测试 path 不匹配
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setPath("tudou"))); fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setPath("tudou")));
// 测试 type 不匹配
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> {
o.setType("image/png");
}));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> { fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> {
o.setCreateTime(buildTime(2020, 1, 15)); o.setCreateTime(buildTime(2020, 1, 15));
@ -77,7 +82,7 @@ public class FileServiceTest extends BaseDbUnitTest {
when(client.getId()).thenReturn(10L); when(client.getId()).thenReturn(10L);
String name = "单测文件名"; String name = "单测文件名";
// 调用 // 调用
String result = fileService.createFile(name, path, "application/octet-stream", content); String result = fileService.createFile(name, path, content);
// 断言 // 断言
assertEquals(result, url); assertEquals(result, url);
// 校验数据 // 校验数据
@ -85,6 +90,7 @@ public class FileServiceTest extends BaseDbUnitTest {
assertEquals(10L, file.getConfigId()); assertEquals(10L, file.getConfigId());
assertEquals(path, file.getPath()); assertEquals(path, file.getPath());
assertEquals(url, file.getUrl()); assertEquals(url, file.getUrl());
assertEquals("image/jpg", file.getType());
assertEquals(content.length, file.getSize()); assertEquals(content.length, file.getSize());
} }

View File

@ -108,7 +108,8 @@ export default {
queryParams: { queryParams: {
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
path: null path: null,
type: null,
}, },
// //
upload: { upload: {