✨ 全局:简化 file 组件,融合到 infra 模块
parent
067ff6cc4d
commit
77d634038c
@ -1,21 +0,0 @@
|
|||||||
package cn.iocoder.yudao.framework.file.config;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientFactory;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientFactoryImpl;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件配置类
|
|
||||||
*
|
|
||||||
* @author 芋道源码
|
|
||||||
*/
|
|
||||||
@AutoConfiguration
|
|
||||||
public class YudaoFileAutoConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public FileClientFactory fileClientFactory() {
|
|
||||||
return new FileClientFactoryImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.db;
|
|
||||||
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 基于 DB 存储的文件客户端的配置类
|
|
||||||
*
|
|
||||||
* @author 芋道源码
|
|
||||||
*/
|
|
||||||
public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
|
|
||||||
|
|
||||||
private DBFileContentFrameworkDAO dao;
|
|
||||||
|
|
||||||
public DBFileClient(Long id, DBFileClientConfig config) {
|
|
||||||
super(id, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doInit() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String upload(byte[] content, String path, String type) {
|
|
||||||
getDao().insert(getId(), path, content);
|
|
||||||
// 拼接返回路径
|
|
||||||
return super.formatFileUrl(config.getDomain(), path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(String path) {
|
|
||||||
getDao().delete(getId(), path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getContent(String path) {
|
|
||||||
return getDao().selectContent(getId(), path);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DBFileContentFrameworkDAO getDao() {
|
|
||||||
// 延迟获取,因为 SpringUtil 初始化太慢
|
|
||||||
if (dao == null) {
|
|
||||||
dao = SpringUtil.getBean(DBFileContentFrameworkDAO.class);
|
|
||||||
}
|
|
||||||
return dao;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.db;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件内容 Framework DAO 接口
|
|
||||||
*
|
|
||||||
* @author 芋道源码
|
|
||||||
*/
|
|
||||||
public interface DBFileContentFrameworkDAO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入文件内容
|
|
||||||
*
|
|
||||||
* @param configId 配置编号
|
|
||||||
* @param path 路径
|
|
||||||
* @param content 内容
|
|
||||||
*/
|
|
||||||
void insert(Long configId, String path, byte[] content);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除文件内容
|
|
||||||
*
|
|
||||||
* @param configId 配置编号
|
|
||||||
* @param path 路径
|
|
||||||
*/
|
|
||||||
void delete(Long configId, String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得文件内容
|
|
||||||
*
|
|
||||||
* @param configId 配置编号
|
|
||||||
* @param path 路径
|
|
||||||
* @return 内容
|
|
||||||
*/
|
|
||||||
byte[] selectContent(Long configId, String path);
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.enums;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClient;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.db.DBFileClient;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.db.DBFileClientConfig;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.ftp.FtpFileClient;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.ftp.FtpFileClientConfig;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClient;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClientConfig;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.s3.S3FileClient;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.s3.S3FileClientConfig;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.sftp.SftpFileClient;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.sftp.SftpFileClientConfig;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件存储器枚举
|
|
||||||
*
|
|
||||||
* @author 芋道源码
|
|
||||||
*/
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public enum FileStorageEnum {
|
|
||||||
|
|
||||||
DB(1, DBFileClientConfig.class, DBFileClient.class),
|
|
||||||
|
|
||||||
LOCAL(10, LocalFileClientConfig.class, LocalFileClient.class),
|
|
||||||
FTP(11, FtpFileClientConfig.class, FtpFileClient.class),
|
|
||||||
SFTP(12, SftpFileClientConfig.class, SftpFileClient.class),
|
|
||||||
|
|
||||||
S3(20, S3FileClientConfig.class, S3FileClient.class),
|
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储器
|
|
||||||
*/
|
|
||||||
private final Integer storage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置类
|
|
||||||
*/
|
|
||||||
private final Class<? extends FileClientConfig> configClass;
|
|
||||||
/**
|
|
||||||
* 客户端类
|
|
||||||
*/
|
|
||||||
private final Class<? extends FileClient> clientClass;
|
|
||||||
|
|
||||||
public static FileStorageEnum getByStorage(Integer storage) {
|
|
||||||
return ArrayUtil.firstMatch(o -> o.getStorage().equals(storage), values());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
cn.iocoder.yudao.framework.file.config.YudaoFileAutoConfiguration
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
@ -1,46 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.infra.dal.mysql.file;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.db.DBFileContentFrameworkDAO;
|
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileContentDO;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public class FileContentDAOImpl implements DBFileContentFrameworkDAO {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private FileContentMapper fileContentMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insert(Long configId, String path, byte[] content) {
|
|
||||||
FileContentDO entity = new FileContentDO().setConfigId(configId)
|
|
||||||
.setPath(path).setContent(content);
|
|
||||||
fileContentMapper.insert(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(Long configId, String path) {
|
|
||||||
fileContentMapper.delete(buildQuery(configId, path));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] selectContent(Long configId, String path) {
|
|
||||||
List<FileContentDO> list = fileContentMapper.selectList(
|
|
||||||
buildQuery(configId, path).select(FileContentDO::getContent).orderByDesc(FileContentDO::getId));
|
|
||||||
return Optional.ofNullable(CollUtil.getFirst(list))
|
|
||||||
.map(FileContentDO::getContent)
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private LambdaQueryWrapper<FileContentDO> buildQuery(Long configId, String path) {
|
|
||||||
return new LambdaQueryWrapper<FileContentDO>()
|
|
||||||
.eq(FileContentDO::getConfigId, configId)
|
|
||||||
.eq(FileContentDO::getPath, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,9 +1,25 @@
|
|||||||
package cn.iocoder.yudao.module.infra.dal.mysql.file;
|
package cn.iocoder.yudao.module.infra.dal.mysql.file;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileContentDO;
|
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileContentDO;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface FileContentMapper extends BaseMapper<FileContentDO> {
|
public interface FileContentMapper extends BaseMapper<FileContentDO> {
|
||||||
|
|
||||||
|
default void deleteByConfigIdAndPath(Long configId, String path) {
|
||||||
|
this.delete(new LambdaQueryWrapper<FileContentDO>()
|
||||||
|
.eq(FileContentDO::getConfigId, configId)
|
||||||
|
.eq(FileContentDO::getPath, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
default List<FileContentDO> selectListByConfigIdAndPath(Long configId, String path) {
|
||||||
|
return selectList(new LambdaQueryWrapper<FileContentDO>()
|
||||||
|
.eq(FileContentDO::getConfigId, configId)
|
||||||
|
.eq(FileContentDO::getPath, path));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
package cn.iocoder.yudao.module.infra.framework.file.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientFactory;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientFactoryImpl;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件配置类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
public class YudaoFileAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public FileClientFactory fileClientFactory() {
|
||||||
|
return new FileClientFactoryImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.s3.FilePresignedUrlRespDTO;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件客户端
|
* 文件客户端
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum;
|
import cn.iocoder.yudao.module.infra.framework.file.core.enums.FileStorageEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.db;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileContentDO;
|
||||||
|
import cn.iocoder.yudao.module.infra.dal.mysql.file.FileContentMapper;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于 DB 存储的文件客户端的配置类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
|
||||||
|
|
||||||
|
private FileContentMapper fileContentMapper;
|
||||||
|
|
||||||
|
public DBFileClient(Long id, DBFileClientConfig config) {
|
||||||
|
super(id, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doInit() {
|
||||||
|
fileContentMapper = SpringUtil.getBean(FileContentMapper.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String upload(byte[] content, String path, String type) {
|
||||||
|
FileContentDO contentDO = new FileContentDO().setConfigId(getId())
|
||||||
|
.setPath(path).setContent(content);
|
||||||
|
fileContentMapper.insert(contentDO);
|
||||||
|
// 拼接返回路径
|
||||||
|
return super.formatFileUrl(config.getDomain(), path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String path) {
|
||||||
|
fileContentMapper.deleteByConfigIdAndPath(getId(), path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getContent(String path) {
|
||||||
|
List<FileContentDO> list = fileContentMapper.selectListByConfigIdAndPath(getId(), path);
|
||||||
|
if (CollUtil.isEmpty(list)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 排序后,拿 id 最大的,即最后上传的
|
||||||
|
list.sort(Comparator.comparing(FileContentDO::getId));
|
||||||
|
return CollUtil.getLast(list).getContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.db;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.db;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
import org.hibernate.validator.constraints.URL;
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.ftp;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.ftp;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
import org.hibernate.validator.constraints.URL;
|
||||||
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.local;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.local;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.local;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.local;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
import org.hibernate.validator.constraints.URL;
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.s3;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.s3;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.s3;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.s3;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
import org.hibernate.validator.constraints.URL;
|
||||||
@ -1,9 +1,9 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.sftp;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.sftp;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.extra.ssh.Sftp;
|
import cn.hutool.extra.ssh.Sftp;
|
||||||
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
||||||
import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.sftp;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.sftp;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
import org.hibernate.validator.constraints.URL;
|
||||||
|
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.infra.framework.file.core.enums;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.db.DBFileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.db.DBFileClientConfig;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.ftp.FtpFileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.ftp.FtpFileClientConfig;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileClientConfig;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.S3FileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.S3FileClientConfig;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.sftp.SftpFileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.sftp.SftpFileClientConfig;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件存储器枚举
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum FileStorageEnum {
|
||||||
|
|
||||||
|
DB(1, DBFileClientConfig.class, DBFileClient.class),
|
||||||
|
|
||||||
|
LOCAL(10, LocalFileClientConfig.class, LocalFileClient.class),
|
||||||
|
FTP(11, FtpFileClientConfig.class, FtpFileClient.class),
|
||||||
|
SFTP(12, SftpFileClientConfig.class, SftpFileClient.class),
|
||||||
|
|
||||||
|
S3(20, S3FileClientConfig.class, S3FileClient.class),
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储器
|
||||||
|
*/
|
||||||
|
private final Integer storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置类
|
||||||
|
*/
|
||||||
|
private final Class<? extends FileClientConfig> configClass;
|
||||||
|
/**
|
||||||
|
* 客户端类
|
||||||
|
*/
|
||||||
|
private final Class<? extends FileClient> clientClass;
|
||||||
|
|
||||||
|
public static FileStorageEnum getByStorage(Integer storage) {
|
||||||
|
return ArrayUtil.firstMatch(o -> o.getStorage().equals(storage), values());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.utils;
|
package cn.iocoder.yudao.module.infra.framework.file.core.utils;
|
||||||
|
|
||||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 0 B |
@ -1,8 +1,10 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.ftp;
|
package cn.iocoder.yudao.module.infra.framework.file.core.ftp;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ResourceUtil;
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.extra.ftp.FtpMode;
|
import cn.hutool.extra.ftp.FtpMode;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.ftp.FtpFileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.ftp.FtpFileClientConfig;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -1,7 +1,9 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.local;
|
package cn.iocoder.yudao.module.infra.framework.file.core.local;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ResourceUtil;
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileClientConfig;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -1,13 +1,14 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.s3;
|
package cn.iocoder.yudao.module.infra.framework.file.core.s3;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ResourceUtil;
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.S3FileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.s3.S3FileClientConfig;
|
||||||
|
import jakarta.validation.Validation;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import jakarta.validation.Validation;
|
|
||||||
|
|
||||||
public class S3FileClientTest {
|
public class S3FileClientTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1,7 +1,9 @@
|
|||||||
package cn.iocoder.yudao.framework.file.core.client.sftp;
|
package cn.iocoder.yudao.module.infra.framework.file.core.sftp;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ResourceUtil;
|
import cn.hutool.core.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.sftp.SftpFileClient;
|
||||||
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.sftp.SftpFileClientConfig;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
Loading…
Reference in New Issue