初始化仓库
This commit is contained in:
30
xtools-boot-storage/xtools-boot-storage-base/pom.xml
Normal file
30
xtools-boot-storage/xtools-boot-storage-base/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-storage</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
<artifactId>xtools-boot-storage-base</artifactId>
|
||||
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- xtools-boot begin -->
|
||||
<!-- xtools-boot-core -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-core</artifactId>
|
||||
</dependency>
|
||||
<!-- xtools-boot end -->
|
||||
|
||||
<!-- spring-boot -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
package xtools.boot.storage.base;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import xtools.boot.core.utils.ModuleLoadUtils;
|
||||
import xtools.boot.storage.base.selector.BootStorageBaseImportSelector;
|
||||
|
||||
/**
|
||||
* <p>Title : BootStorageBaseConfiguration</p>
|
||||
* <p>Description : BootStorageBaseConfiguration</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
@Import(BootStorageBaseImportSelector.class)
|
||||
public class BootStorageBaseConfiguration {
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public BootStorageBaseConfiguration() {
|
||||
ModuleLoadUtils.loadSuccess(BootStorageBaseConfiguration.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package xtools.boot.storage.base.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* <p>Title : StorageConfig</p>
|
||||
* <p>Description : StorageConfig</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/3/14 07:40
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "storage")
|
||||
public class StorageConfig {
|
||||
|
||||
/**
|
||||
* 存储类型[file|s3]
|
||||
*/
|
||||
private String type = "file";
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
private FileType file;
|
||||
|
||||
/**
|
||||
* S3类型
|
||||
*/
|
||||
private S3Type s3;
|
||||
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
@Data
|
||||
public static class FileType {
|
||||
|
||||
/**
|
||||
* 文件存储路径
|
||||
*/
|
||||
private String path;
|
||||
}
|
||||
|
||||
/**
|
||||
* S3类型
|
||||
*/
|
||||
@Data
|
||||
public static class S3Type {
|
||||
|
||||
/**
|
||||
* 服务类型[rustfs]
|
||||
*/
|
||||
private String server = "default";
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 密钥ID
|
||||
*/
|
||||
private String accessKeyId;
|
||||
|
||||
/**
|
||||
* 密钥
|
||||
*/
|
||||
private String secretAccessKey;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package xtools.boot.storage.base.selector;
|
||||
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* <p>Title : BootStorageBaseImportSelector</p>
|
||||
* <p>Description : BootStorageBaseImportSelector</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
public class BootStorageBaseImportSelector implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
/**
|
||||
* 根据给定的注释元数据,根据需要注册bean
|
||||
*
|
||||
* @param importingClassMetadata AnnotationMetadata
|
||||
* @param registry BeanDefinitionRegistry
|
||||
*/
|
||||
@Override
|
||||
public void registerBeanDefinitions(@NonNull AnnotationMetadata importingClassMetadata, @NonNull BeanDefinitionRegistry registry) {
|
||||
// 构建扫描对象
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry, true);
|
||||
// 扫描包下路径
|
||||
scanner.scan("xtools.boot.storage.base");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package xtools.boot.storage.base.service;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* <p>Title : StorageService</p>
|
||||
* <p>Description : StorageService</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/3/14 07:20
|
||||
*/
|
||||
public interface StorageService {
|
||||
|
||||
/**
|
||||
* 是否存在文件
|
||||
*
|
||||
* @param bucket 桶
|
||||
* @param fileName 文件名
|
||||
* @return true or false
|
||||
*/
|
||||
boolean exists(
|
||||
@NotNull String bucket,
|
||||
@NotNull String fileName
|
||||
);
|
||||
|
||||
/**
|
||||
* 保存文件
|
||||
*
|
||||
* @param bucket 桶
|
||||
* @param fileName 文件名
|
||||
* @param inputStream 输入流
|
||||
* @param contentLength 文件长度
|
||||
*/
|
||||
void save(
|
||||
@NotNull String bucket,
|
||||
@NotNull String fileName,
|
||||
@NotNull InputStream inputStream,
|
||||
long contentLength
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param bucket 桶
|
||||
* @param fileName 文件名
|
||||
* @param outputStream 输出流
|
||||
*/
|
||||
void get(
|
||||
@NotNull String bucket,
|
||||
@NotNull String fileName,
|
||||
@NotNull OutputStream outputStream
|
||||
);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param bucket 桶
|
||||
* @param fileName 文件名
|
||||
*/
|
||||
void del(
|
||||
@NotNull String bucket,
|
||||
@NotNull String fileName
|
||||
);
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
xtools.boot.storage.base.BootStorageBaseConfiguration
|
||||
@@ -0,0 +1,18 @@
|
||||
# 存储配置
|
||||
storage:
|
||||
# 存储类型[file|s3](并且需要引入对应的jar包)
|
||||
type: ${STORAGE_TYPE:file}
|
||||
# 文件类型
|
||||
file:
|
||||
# 文件存储路径
|
||||
path: ${STORAGE_FILE_PATH:/data/xtools/file}
|
||||
# S3类型
|
||||
s3:
|
||||
# 服务类型(可为空)[rustfs]
|
||||
server: ${STORAGE_S3_SERVER:rustfs}
|
||||
# 地址
|
||||
host: ${STORAGE_S3_HOST:http://127.0.0.1:9000}
|
||||
# 密钥ID
|
||||
accessKeyId: ${STORAGE_S3_ACCESS_KEY_ID:admin}
|
||||
# 密钥
|
||||
secretAccessKey: ${STORAGE_S3_SECRET_ACCESS_KEY:123456}
|
||||
Reference in New Issue
Block a user