mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
合并fetch代码
This commit is contained in:
parent
6a1c09ca42
commit
c64295f432
@ -14,7 +14,7 @@ public interface FileApi {
|
||||
* @return 文件路径
|
||||
*/
|
||||
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 文件路径
|
||||
*/
|
||||
default String createFile(String path, byte[] content) {
|
||||
return createFile(null, path, "application/octet-stream", content);
|
||||
return createFile(null, path, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存文件,并返回文件的访问路径
|
||||
*
|
||||
* @param name 文件名称
|
||||
* @param path 文件路径
|
||||
* @param mimeType 文件类型
|
||||
* @param content 文件内容
|
||||
* @param name 文件名称
|
||||
* @param path 文件路径
|
||||
* @param content 文件内容
|
||||
* @return 文件路径
|
||||
*/
|
||||
String createFile(String name, String path, String mimeType, byte[] content);
|
||||
String createFile(String name, String path, byte[] content);
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ public class FileApiImpl implements FileApi {
|
||||
private FileService fileService;
|
||||
|
||||
@Override
|
||||
public String createFile(String name, String path, String mimeType, byte[] content) {
|
||||
return fileService.createFile(name, path, mimeType, content);
|
||||
public String createFile(String name, String path, byte[] content) {
|
||||
return fileService.createFile(name, path, content);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class FileController {
|
||||
@OperateLog(logArgs = false) // 上传文件,没有记录操作日志的必要
|
||||
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
||||
@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")
|
||||
|
@ -38,16 +38,15 @@ public class FileDO extends BaseDO {
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 路径,即文件名,唯一不可重复
|
||||
* 路径,即文件名
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 访问地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 文件的MIME类型,默认为"application/octet-stream"
|
||||
* 文件的MIME类型,例如"application/octet-stream"
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
|
@ -24,11 +24,10 @@ public interface FileService {
|
||||
*
|
||||
* @param name 文件名称
|
||||
* @param path 文件路径
|
||||
* @param mimeType 文件MIME类型
|
||||
* @param content 文件内容
|
||||
* @return 文件路径
|
||||
*/
|
||||
String createFile(String name, String path, String mimeType,byte[] content);
|
||||
String createFile(String name, String path, byte[] content);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
|
@ -40,11 +40,16 @@ public class FileServiceTest extends BaseDbUnitTest {
|
||||
// mock 数据
|
||||
FileDO dbFile = randomPojo(FileDO.class, o -> { // 等会查询到
|
||||
o.setPath("yunai");
|
||||
o.setType("image/jpg");
|
||||
o.setCreateTime(buildTime(2021, 1, 15));
|
||||
});
|
||||
fileMapper.insert(dbFile);
|
||||
// 测试 path 不匹配
|
||||
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> o.setPath("tudou")));
|
||||
// 测试 type 不匹配
|
||||
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> {
|
||||
o.setType("image/png");
|
||||
}));
|
||||
// 测试 createTime 不匹配
|
||||
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> {
|
||||
o.setCreateTime(buildTime(2020, 1, 15));
|
||||
@ -77,7 +82,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
||||
when(client.getId()).thenReturn(10L);
|
||||
String name = "单测文件名";
|
||||
// 调用
|
||||
String result = fileService.createFile(name, path, "application/octet-stream", content);
|
||||
String result = fileService.createFile(name, path, content);
|
||||
// 断言
|
||||
assertEquals(result, url);
|
||||
// 校验数据
|
||||
@ -85,6 +90,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
||||
assertEquals(10L, file.getConfigId());
|
||||
assertEquals(path, file.getPath());
|
||||
assertEquals(url, file.getUrl());
|
||||
assertEquals("image/jpg", file.getType());
|
||||
assertEquals(content.length, file.getSize());
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,8 @@ export default {
|
||||
queryParams: {
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
path: null
|
||||
path: null,
|
||||
type: null,
|
||||
},
|
||||
// 用户导入参数
|
||||
upload: {
|
||||
|
Loading…
Reference in New Issue
Block a user