Browse Source

feat(oss):新增oss对象存储模块

dev-minio
dashan 12 months ago
parent
commit
cfa6fc7d56
  1. 2
      .idea/compiler.xml
  2. 1
      .idea/encodings.xml
  3. 56
      ds-commons/ds-config/ds-oss-config/pom.xml
  4. 32
      ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/bean/MinioConfiguration.java
  5. 49
      ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/bean/OssProperties.java
  6. 99
      ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/core/OssTemplate.java
  7. 46
      ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/pojo/OssFile.java
  8. 1
      ds-commons/ds-config/pom.xml
  9. 5
      pom.xml

2
.idea/compiler.xml

@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
<module name="ds-miniapps-service" />
<module name="ds-web-config" />
<module name="ds-miniapps-model" />
<module name="ds-oss-config" />
<module name="ds-gateway" />
<module name="ds-mybatisplus-support" />
<module name="ds-timer-task" />
@ -37,6 +38,7 @@ @@ -37,6 +38,7 @@
<module name="ds-modules" options="-parameters" />
<module name="ds-mybatisplus-config" options="-parameters" />
<module name="ds-mybatisplus-support" options="-parameters" />
<module name="ds-oss-config" options="-parameters" />
<module name="ds-timer-task" options="-parameters" />
<module name="ds-utils" options="-parameters" />
<module name="ds-web-config" options="-parameters" />

1
.idea/encodings.xml

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
<file url="file://$PROJECT_DIR$/ds-commons/ds-basemodel/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/ds-mybatisplus-config/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/ds-mybatisplus-support/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/ds-oss-config/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/ds-web-config/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/src/main/resources" charset="UTF-8" />

56
ds-commons/ds-config/ds-oss-config/pom.xml

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>com.ds</groupId>
<artifactId>ds-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.ds.common.oss</groupId>
<artifactId>ds-oss-config</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
</dependencies>
</project>

32
ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/bean/MinioConfiguration.java

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
package com.ds.common.oss.bean;
import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author ds
* @since 2023/11/27
*/
@Configuration
@EnableConfigurationProperties(OssProperties.class)
@ConditionalOnProperty(value = "oss.name", havingValue = "minio")
public class MinioConfiguration {
private final OssProperties ossProperties;
public MinioConfiguration(OssProperties ossProperties){
this.ossProperties=ossProperties;
}
@Bean
public MinioClient minioClient() {
return MinioClient.builder()
.endpoint(ossProperties.getEndpoint())
.credentials(ossProperties.getAccessKey(), ossProperties.getSecretKey())
.build();
}
}

49
ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/bean/OssProperties.java

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
package com.ds.common.oss.bean;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
/**
* @author ds
* @since 2023/11/27
*/
@Data
@ConfigurationProperties(prefix = OssProperties.PREFIX)
public class OssProperties implements InitializingBean {
/**
* 配置前缀
*/
public static final String PREFIX = "oss";
/**
* 对象存储名称
*/
private String name;
/**
* 对象存储服务的URL
*/
private String endpoint;
/**
* Access key 账户ID
*/
private String accessKey;
/**
* Secret key 密码
*/
private String secretKey;
@Override
public void afterPropertiesSet() {
Assert.hasText(endpoint, "Minio endpoint 为空");
Assert.hasText(accessKey, "Minio accessKey为空");
Assert.hasText(secretKey, "Minio secretKey为空");
}
}

99
ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/core/OssTemplate.java

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
package com.ds.common.oss.core;
import com.ds.common.oss.pojo.OssFile;
import io.minio.messages.Bucket;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.List;
/**
* @author ds
* @since 2023/11/27
*/
public interface OssTemplate {
/**
* 存储桶是否存在
*
* @param bucketName 存储桶名称
* @return boolean
*/
boolean bucketExists(@NotEmpty(message = "桶名称不能为空") String bucketName);
/**
* 创建桶
* @param bucketName 存储桶名称
* @return boolean
*/
boolean makeBucket(String bucketName);
/**
* 删除桶
* @param bucketName 存储桶名称
* @return boolean
*/
boolean removeBucket(String bucketName);
/**
* 获取全部桶
* @return 全部桶列表
*/
List<Bucket> getAllBuckets();
String preview(String fileName);
/**
* 获取文件信息
*
* @param fileName 存储桶文件名称
* @return InputStream
*/
OssFile getOssInfo(@NotEmpty(message = "桶名称不能为空") String bucketName,@NotEmpty(message = "文件名称不能为空") String fileName);
/**
* 上传文件
*
* @param folderName 上传的文件夹名称
* @param fileName 上传文件名
* @param file 上传文件类
* @return BladeFile
*/
OssFile uploadFile(String folderName, String fileName, MultipartFile file);
/**
* 上传文件
*
* @param folderName 上传的文件夹名称
* @param fileName 存储桶对象名称
* @param suffix 文件后缀名
* @param stream 文件流
* @return BladeFile
*/
OssFile uploadFile(String folderName, String fileName, String suffix, InputStream stream);
/**
* 删除文件
*
* @param fileName 存储桶对象名称
*/
boolean removeFile(String fileName);
/**
* 批量删除文件
*
* @param fileNames 存储桶对象名称集合
*/
boolean removeFiles(List<String> fileNames);
/**
* 下载文件
* @param response res
* @param fileName 文件名称
* @param filePath 文件路径
*/
void downloadFile(HttpServletResponse response, String fileName, String filePath);
}

46
ds-commons/ds-config/ds-oss-config/src/main/java/com/ds/common/oss/pojo/OssFile.java

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
package com.ds.common.oss.pojo;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author ds
* @since 2023/11/27
*/
@Data
public class OssFile implements Serializable {
/**
* 文件地址
*/
private String filePath;
/**
* 域名地址
*/
private String domain;
/**
* 文件名
*/
private String name;
/**
* 原始文件名
*/
private String originalName;
/**
* 文件hash值
*/
public String hash;
/**
* 文件大小
*/
private long size;
/**
* 文件上传时间
*/
private LocalDateTime putTime;
/**
* 文件contentType
*/
private String contentType;
}

1
ds-commons/ds-config/pom.xml

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
<module>ds-web-config</module>
<module>ds-mybatisplus-config</module>
<module>ds-mybatisplus-support</module>
<module>ds-oss-config</module>
</modules>
<properties>

5
pom.xml

@ -91,6 +91,11 @@ @@ -91,6 +91,11 @@
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.4</version>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save