mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
优化文件配置,去掉 region 的配置,通过自动识别
This commit is contained in:
parent
34a7399a65
commit
813069abf4
@ -40,12 +40,6 @@ public class S3FileClientConfig implements FileClientConfig {
|
|||||||
*/
|
*/
|
||||||
@URL(message = "domain 必须是 URL 格式")
|
@URL(message = "domain 必须是 URL 格式")
|
||||||
private String domain;
|
private String domain;
|
||||||
/**
|
|
||||||
* 区域
|
|
||||||
*/
|
|
||||||
// @NotNull(message = "region 不能为空")
|
|
||||||
@Deprecated
|
|
||||||
private String region;
|
|
||||||
/**
|
/**
|
||||||
* 存储 Bucket
|
* 存储 Bucket
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,6 @@ public class S3FileClientTest {
|
|||||||
config.setDomain(null);
|
config.setDomain(null);
|
||||||
// 默认 9000 endpoint
|
// 默认 9000 endpoint
|
||||||
config.setEndpoint("http://127.0.0.1:9000");
|
config.setEndpoint("http://127.0.0.1:9000");
|
||||||
config.setRegion("us-east-1");
|
|
||||||
|
|
||||||
// 执行上传
|
// 执行上传
|
||||||
testExecuteUpload(config);
|
testExecuteUpload(config);
|
||||||
|
@ -15,7 +15,7 @@ public interface FileApi {
|
|||||||
* @param content 文件内容
|
* @param content 文件内容
|
||||||
* @return 文件路径
|
* @return 文件路径
|
||||||
*/
|
*/
|
||||||
default String createFile(byte[] content) {
|
default String createFile(byte[] content) throws Exception {
|
||||||
return createFile(IdUtil.fastUUID(), content);
|
return createFile(IdUtil.fastUUID(), content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +26,6 @@ public interface FileApi {
|
|||||||
* @param content 文件内容
|
* @param content 文件内容
|
||||||
* @return 文件路径
|
* @return 文件路径
|
||||||
*/
|
*/
|
||||||
String createFile(String path, byte[] content);
|
String createFile(String path, byte[] content) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.infra.api.file;
|
package cn.iocoder.yudao.module.infra.api.file;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
||||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@ -20,7 +19,7 @@ public class FileApiImpl implements FileApi {
|
|||||||
private FileService fileService;
|
private FileService fileService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createFile(String path, byte[] content) {
|
public String createFile(String path, byte[] content) throws Exception {
|
||||||
return fileService.createFile(path, content);
|
return fileService.createFile(path, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public class FileConfigController {
|
|||||||
@GetMapping("/test")
|
@GetMapping("/test")
|
||||||
@ApiOperation("测试文件配置是否正确")
|
@ApiOperation("测试文件配置是否正确")
|
||||||
@PreAuthorize("@ss.hasPermission('infra:file-config:query')")
|
@PreAuthorize("@ss.hasPermission('infra:file-config:query')")
|
||||||
public CommonResult<String> testFileConfig(@RequestParam("id") Long id) {
|
public CommonResult<String> testFileConfig(@RequestParam("id") Long id) throws Exception {
|
||||||
String url = fileConfigService.testFileConfig(id);
|
String url = fileConfigService.testFileConfig(id);
|
||||||
return success(url);
|
return success(url);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ public class FileController {
|
|||||||
@ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class)
|
@ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class)
|
||||||
})
|
})
|
||||||
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
||||||
@RequestParam("path") String path) throws IOException {
|
@RequestParam("path") String path) throws Exception {
|
||||||
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
|
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ public class FileController {
|
|||||||
@ApiOperation("删除文件")
|
@ApiOperation("删除文件")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
||||||
@PreAuthorize("@ss.hasPermission('infra:file:delete')")
|
@PreAuthorize("@ss.hasPermission('infra:file:delete')")
|
||||||
public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) {
|
public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) throws Exception {
|
||||||
fileService.deleteFile(id);
|
fileService.deleteFile(id);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
@ -65,7 +64,7 @@ public class FileController {
|
|||||||
})
|
})
|
||||||
public void getFileContent(HttpServletResponse response,
|
public void getFileContent(HttpServletResponse response,
|
||||||
@PathVariable("configId") Long configId,
|
@PathVariable("configId") Long configId,
|
||||||
@PathVariable("path") String path) throws IOException {
|
@PathVariable("path") String path) throws Exception {
|
||||||
byte[] content = fileService.getFileContent(configId, path);
|
byte[] content = fileService.getFileContent(configId, path);
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
||||||
|
@ -82,7 +82,7 @@ public interface FileConfigService {
|
|||||||
* @param id 编号
|
* @param id 编号
|
||||||
* @return 文件 URL
|
* @return 文件 URL
|
||||||
*/
|
*/
|
||||||
String testFileConfig(Long id);
|
String testFileConfig(Long id) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得指定编号的文件客户端
|
* 获得指定编号的文件客户端
|
||||||
|
@ -225,7 +225,7 @@ public class FileConfigServiceImpl implements FileConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String testFileConfig(Long id) {
|
public String testFileConfig(Long id) throws Exception {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
this.validateFileConfigExists(id);
|
this.validateFileConfigExists(id);
|
||||||
// 上传文件
|
// 上传文件
|
||||||
|
@ -26,14 +26,14 @@ public interface FileService {
|
|||||||
* @param content 文件内容
|
* @param content 文件内容
|
||||||
* @return 文件路径
|
* @return 文件路径
|
||||||
*/
|
*/
|
||||||
String createFile(String path, byte[] content);
|
String createFile(String path, byte[] content) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除文件
|
* 删除文件
|
||||||
*
|
*
|
||||||
* @param id 编号
|
* @param id 编号
|
||||||
*/
|
*/
|
||||||
void deleteFile(Long id);
|
void deleteFile(Long id) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得文件内容
|
* 获得文件内容
|
||||||
@ -42,6 +42,6 @@ public interface FileService {
|
|||||||
* @param path 文件路径
|
* @param path 文件路径
|
||||||
* @return 文件内容
|
* @return 文件内容
|
||||||
*/
|
*/
|
||||||
byte[] getFileContent(Long configId, String path);
|
byte[] getFileContent(Long configId, String path) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createFile(String path, byte[] content) {
|
public String createFile(String path, byte[] content) throws Exception {
|
||||||
// 上传到文件存储器
|
// 上传到文件存储器
|
||||||
FileClient client = fileConfigService.getMasterFileClient();
|
FileClient client = fileConfigService.getMasterFileClient();
|
||||||
Assert.notNull(client, "客户端(master) 不能为空");
|
Assert.notNull(client, "客户端(master) 不能为空");
|
||||||
@ -53,7 +53,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFile(Long id) {
|
public void deleteFile(Long id) throws Exception {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
FileDO file = this.validateFileExists(id);
|
FileDO file = this.validateFileExists(id);
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getFileContent(Long configId, String path) {
|
public byte[] getFileContent(Long configId, String path) throws Exception {
|
||||||
FileClient client = fileConfigService.getFileClient(configId);
|
FileClient client = fileConfigService.getFileClient(configId);
|
||||||
Assert.notNull(client, "客户端({}) 不能为空", configId);
|
Assert.notNull(client, "客户端({}) 不能为空", configId);
|
||||||
return client.getContent(path);
|
return client.getContent(path);
|
||||||
|
@ -228,7 +228,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFileConfig() {
|
public void testFileConfig() throws Exception {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
FileConfigDO dbFileConfig = randomFileConfigDO().setMaster(false);
|
FileConfigDO dbFileConfig = randomFileConfigDO().setMaster(false);
|
||||||
fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据
|
fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据
|
||||||
|
@ -70,7 +70,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateFile_success() {
|
public void testCreateFile_success() throws Exception {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
String path = randomString();
|
String path = randomString();
|
||||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||||
@ -95,7 +95,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteFile_success() {
|
public void testDeleteFile_success() throws Exception {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
FileDO dbFile = randomPojo(FileDO.class, o -> o.setConfigId(10L).setPath("tudou.jpg"));
|
FileDO dbFile = randomPojo(FileDO.class, o -> o.setConfigId(10L).setPath("tudou.jpg"));
|
||||||
fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据
|
fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据
|
||||||
@ -123,7 +123,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFileContent() {
|
public void testGetFileContent() throws Exception {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
Long configId = 10L;
|
Long configId = 10L;
|
||||||
String path = "tudou.jpg";
|
String path = "tudou.jpg";
|
||||||
|
@ -16,9 +16,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.*;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
||||||
@ -44,7 +43,7 @@ public class AppUserController {
|
|||||||
@PutMapping("/update-avatar")
|
@PutMapping("/update-avatar")
|
||||||
@ApiOperation("修改用户头像")
|
@ApiOperation("修改用户头像")
|
||||||
@PreAuthenticated
|
@PreAuthenticated
|
||||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
|
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
throw exception(FILE_IS_EMPTY);
|
throw exception(FILE_IS_EMPTY);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public interface MemberUserService {
|
|||||||
* @param inputStream 头像文件
|
* @param inputStream 头像文件
|
||||||
* @return 头像url
|
* @return 头像url
|
||||||
*/
|
*/
|
||||||
String updateUserAvatar(Long userId, InputStream inputStream);
|
String updateUserAvatar(Long userId, InputStream inputStream) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改手机
|
* 修改手机
|
||||||
|
@ -100,7 +100,7 @@ public class MemberUserServiceImpl implements MemberUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String updateUserAvatar(Long userId, InputStream avatarFile) {
|
public String updateUserAvatar(Long userId, InputStream avatarFile) throws Exception {
|
||||||
this.checkUserExists(userId);
|
this.checkUserExists(userId);
|
||||||
// 创建文件
|
// 创建文件
|
||||||
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
||||||
|
@ -74,7 +74,7 @@ public class MemberUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAvatar_success(){
|
public void testUpdateAvatar_success() throws Exception {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
MemberUserDO dbUser = randomUserDO();
|
MemberUserDO dbUser = randomUserDO();
|
||||||
userMapper.insert(dbUser);
|
userMapper.insert(dbUser);
|
||||||
|
@ -29,7 +29,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
@ -99,7 +98,7 @@ public class UserProfileController {
|
|||||||
|
|
||||||
@PutMapping("/update-avatar")
|
@PutMapping("/update-avatar")
|
||||||
@ApiOperation("上传用户个人头像")
|
@ApiOperation("上传用户个人头像")
|
||||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
|
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public interface AdminUserService {
|
|||||||
* @param id 用户 id
|
* @param id 用户 id
|
||||||
* @param avatarFile 头像文件
|
* @param avatarFile 头像文件
|
||||||
*/
|
*/
|
||||||
String updateUserAvatar(Long id, InputStream avatarFile);
|
String updateUserAvatar(Long id, InputStream avatarFile) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改密码
|
* 修改密码
|
||||||
|
@ -118,7 +118,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String updateUserAvatar(Long id, InputStream avatarFile) {
|
public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception {
|
||||||
this.checkUserExists(id);
|
this.checkUserExists(id);
|
||||||
// 存储文件
|
// 存储文件
|
||||||
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
||||||
|
@ -196,7 +196,7 @@ public class UserServiceImplTest extends BaseDbUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateUserAvatar_success() {
|
public void testUpdateUserAvatar_success() throws Exception {
|
||||||
// mock 数据
|
// mock 数据
|
||||||
AdminUserDO dbUser = randomAdminUserDO();
|
AdminUserDO dbUser = randomAdminUserDO();
|
||||||
userMapper.insert(dbUser);
|
userMapper.insert(dbUser);
|
||||||
|
@ -109,9 +109,6 @@
|
|||||||
<el-form-item v-if="form.storage === 20" label="节点地址" prop="config.endpoint">
|
<el-form-item v-if="form.storage === 20" label="节点地址" prop="config.endpoint">
|
||||||
<el-input v-model="form.config.endpoint" placeholder="请输入节点地址" />
|
<el-input v-model="form.config.endpoint" placeholder="请输入节点地址" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item v-if="form.storage === 20" label="区域" prop="config.region">
|
|
||||||
<el-input v-model="form.config.region" placeholder="请输入区域" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item v-if="form.storage === 20" label="存储 bucket" prop="config.bucket">
|
<el-form-item v-if="form.storage === 20" label="存储 bucket" prop="config.bucket">
|
||||||
<el-input v-model="form.config.bucket" placeholder="请输入 bucket" />
|
<el-input v-model="form.config.bucket" placeholder="请输入 bucket" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -190,7 +187,6 @@ export default {
|
|||||||
password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
|
password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
|
||||||
mode: [{ required: true, message: "连接模式不能为空", trigger: "change" }],
|
mode: [{ required: true, message: "连接模式不能为空", trigger: "change" }],
|
||||||
endpoint: [{ required: true, message: "节点地址不能为空", trigger: "blur" }],
|
endpoint: [{ required: true, message: "节点地址不能为空", trigger: "blur" }],
|
||||||
region: [{ required: true, message: "区域名不能为空", trigger: "blur" }],
|
|
||||||
bucket: [{ required: true, message: "存储 bucket 不能为空", trigger: "blur" }],
|
bucket: [{ required: true, message: "存储 bucket 不能为空", trigger: "blur" }],
|
||||||
accessKey: [{ required: true, message: "accessKey 不能为空", trigger: "blur" }],
|
accessKey: [{ required: true, message: "accessKey 不能为空", trigger: "blur" }],
|
||||||
accessSecret: [{ required: true, message: "accessSecret 不能为空", trigger: "blur" }],
|
accessSecret: [{ required: true, message: "accessSecret 不能为空", trigger: "blur" }],
|
||||||
|
Loading…
Reference in New Issue
Block a user