model 改为 api 模块。

This commit is contained in:
刘小平 2024-06-05 16:42:14 +08:00
parent c62c0808b4
commit 1a250b7cb0
30 changed files with 81 additions and 192 deletions

View File

@ -9,7 +9,8 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-plus-model</artifactId>
<artifactId>minio-plus-api</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -1,34 +1,26 @@
package org.liuxp.minioplus.core.service;
package org.liuxp.minioplus.api;
import cn.hutool.core.lang.Pair;
import org.liuxp.minioplus.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.model.dto.FileSaveDTO;
import org.liuxp.minioplus.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.api.model.dto.FileSaveDTO;
import org.liuxp.minioplus.api.model.vo.FileMetadataInfoVo;
import java.io.InputStream;
import java.util.List;
/**
* 存储组件Service层公共方法
* 本类的方法是给后端业务研发提供的公共方法后端业务研发可以@Resources引用本类使用
* MinIO Plus 接口定义
* @author contact@liuxp.me
* @since 2023/06/26
* @since 2024/06/05
*/
public interface StorageService {
/**
* 根据文件id查询
* @param id 文件ID
* @return 文件元数据信息
*/
FileMetadataInfoVo oneById(Long id);
/**
* 根据文件key查询
* @param key 文件key
* @return 文件元数据信息
*/
FileMetadataInfoVo oneByKey(String key);
FileMetadataInfoVo one(String key);
/**
* 列表数据查询

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.bo;
package org.liuxp.minioplus.api.model.bo;
import lombok.Getter;
import lombok.Setter;

View File

@ -1,9 +1,9 @@
package org.liuxp.minioplus.model.bo;
package org.liuxp.minioplus.api.model.bo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.liuxp.minioplus.model.vo.FileCheckResultVo;
import org.liuxp.minioplus.api.model.vo.FileCheckResultVo;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.dto;
package org.liuxp.minioplus.api.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.dto;
package org.liuxp.minioplus.api.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.dto;
package org.liuxp.minioplus.api.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.dto;
package org.liuxp.minioplus.api.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.dto;
package org.liuxp.minioplus.api.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.dto;
package org.liuxp.minioplus.api.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.vo;
package org.liuxp.minioplus.api.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.vo;
package org.liuxp.minioplus.api.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -1,4 +1,4 @@
package org.liuxp.minioplus.model.vo;
package org.liuxp.minioplus.api.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-plus-application-mysql</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -7,10 +7,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.liuxp.minioplus.application.entity.FileMetadataInfoEntity;
import org.liuxp.minioplus.application.mapper.FileMetadataInfoMapper;
import org.liuxp.minioplus.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoUpdateDTO;
import org.liuxp.minioplus.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoUpdateDTO;
import org.liuxp.minioplus.api.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.core.repository.MetadataRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-plus-common</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -10,35 +10,20 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-plus-core</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- minio -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<exclusions>
<exclusion>
<artifactId>okhttp</artifactId>
<groupId>com.squareup.okhttp3</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>org.liuxp</groupId>
<artifactId>minio-plus-common</artifactId>
</dependency>
<dependency>
<groupId>org.liuxp</groupId>
<artifactId>minio-plus-model</artifactId>
<artifactId>minio-plus-api</artifactId>
</dependency>
<dependency>
<groupId>org.liuxp</groupId>

View File

@ -1,15 +0,0 @@
package org.liuxp.minioplus.core.common.context;
import io.minio.messages.ListPartsResult;
import io.minio.messages.Part;
import java.util.ArrayList;
import java.util.List;
public class ListPartsResultCopy extends ListPartsResult {
public List<Part> partList() {
return new ArrayList<>();
}
}

View File

@ -1,59 +0,0 @@
package org.liuxp.minioplus.core.common.context;
import com.google.common.collect.Multimap;
import io.minio.messages.Part;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 创建分片上传需要的参数
*
* @author contact@liuxp.me
* @date 2023/06/28
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MultipartUploadCreateDTO {
/**
* 桶名字
*/
private String bucketName;
/**
* 区名字
*/
private String region;
/**
* 对象名字
*/
private String objectName;
/**
* 请求头
*/
private Multimap<String, String> headers;
/**
* 查询参数
*/
private Multimap<String, String> extraQueryParams;
/**
* minio的id
*/
private String uploadId;
/**
* 最大块数量
*/
private Integer maxParts;
/**
* 块信息
*/
private Part[] parts;
/**
* 块编号
*/
private Integer partNumberMarker;
}

View File

@ -1,11 +1,11 @@
package org.liuxp.minioplus.core.engine;
import cn.hutool.core.lang.Pair;
import org.liuxp.minioplus.model.dto.FileCheckDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.model.vo.CompleteResultVo;
import org.liuxp.minioplus.model.vo.FileCheckResultVo;
import org.liuxp.minioplus.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.api.model.dto.FileCheckDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.api.model.vo.CompleteResultVo;
import org.liuxp.minioplus.api.model.vo.FileCheckResultVo;
import org.liuxp.minioplus.api.model.vo.FileMetadataInfoVo;
import java.util.List;

View File

@ -6,23 +6,22 @@ import cn.hutool.core.lang.Pair;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.liuxp.minioplus.common.config.MinioPlusProperties;
import org.liuxp.minioplus.common.enums.MinioPlusErrorCode;
import org.liuxp.minioplus.common.enums.StorageBucketEnums;
import org.liuxp.minioplus.common.exception.MinioPlusException;
import org.liuxp.minioplus.common.config.MinioPlusProperties;
import org.liuxp.minioplus.core.common.context.MultipartUploadCreateDTO;
import org.liuxp.minioplus.core.common.utils.MinioPlusCommonUtil;
import org.liuxp.minioplus.core.engine.StorageEngineService;
import org.liuxp.minioplus.core.repository.MetadataRepository;
import org.liuxp.minioplus.model.bo.CreateUploadUrlReqBO;
import org.liuxp.minioplus.model.bo.CreateUploadUrlRespBO;
import org.liuxp.minioplus.model.dto.FileCheckDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoUpdateDTO;
import org.liuxp.minioplus.model.vo.CompleteResultVo;
import org.liuxp.minioplus.model.vo.FileCheckResultVo;
import org.liuxp.minioplus.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.api.model.bo.CreateUploadUrlReqBO;
import org.liuxp.minioplus.api.model.bo.CreateUploadUrlRespBO;
import org.liuxp.minioplus.api.model.dto.FileCheckDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoUpdateDTO;
import org.liuxp.minioplus.api.model.vo.CompleteResultVo;
import org.liuxp.minioplus.api.model.vo.FileCheckResultVo;
import org.liuxp.minioplus.api.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.s3.def.ListParts;
import org.liuxp.minioplus.s3.def.MinioS3Client;
import org.springframework.beans.BeanUtils;
@ -31,7 +30,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* 存储引擎Service接口实现类
@ -52,11 +53,6 @@ public class StorageEngineServiceImpl implements StorageEngineService {
@Resource
MinioS3Client minioS3Client;
/**
* MinIO中上传编号名称
*/
private static final String UPLOAD_ID = "uploadId";
/**
* 上传任务初始化
*
@ -572,19 +568,20 @@ public class StorageEngineServiceImpl implements StorageEngineService {
/**
* 构建响应给前端的分片信息
*
* @param uploadCreateDTO 分片dto
* @param bucketName 桶名称
* @param objectName 对象名称含路径
* @param uploadId 上传任务编号
* @param fileSize 文件大小
* @param start 开始位置
* @param partNumber 块号
* @return {@link FileCheckResultVo.Part}
*/
private FileCheckResultVo.Part buildResultPart(MultipartUploadCreateDTO uploadCreateDTO, String uploadId, Long fileSize, long start, Integer partNumber) {
private FileCheckResultVo.Part buildResultPart(String bucketName,String objectName,String uploadId, Long fileSize, long start, Integer partNumber) {
// 计算起始位置
long end = Math.min(start + properties.getPart().getSize(), fileSize);
String uploadUrl = minioS3Client.getUploadObjectUrl(uploadCreateDTO.getBucketName(), uploadCreateDTO.getObjectName(), uploadId,String.valueOf(partNumber));
String uploadUrl = minioS3Client.getUploadObjectUrl(bucketName, objectName, uploadId,String.valueOf(partNumber));
FileCheckResultVo.Part part = new FileCheckResultVo.Part();
part.setUploadId(uploadCreateDTO.getUploadId());
part.setUploadId(uploadId);
// 上传地址
part.setUrl(uploadUrl);
// 开始位置
@ -757,22 +754,17 @@ public class StorageEngineServiceImpl implements StorageEngineService {
// 断点续传
if (Boolean.TRUE.equals(bo.getIsSequel()) && CollUtil.isNotEmpty(bo.getMissPartNum()) && CharSequenceUtil.isNotBlank(bo.getUploadId())) {
// 断点续传需要使用已创建的任务信息构建分片信息
MultipartUploadCreateDTO uploadCreateDTO = MultipartUploadCreateDTO.builder()
.bucketName(bo.getStorageBucket())
.objectName(MinioPlusCommonUtil.getObjectName(bo.getFileMd5()))
.build();
// 存储桶
bucketName = uploadCreateDTO.getBucketName();
bucketName = bo.getStorageBucket();
// 存储路径
storagePath = uploadCreateDTO.getObjectName();
storagePath = MinioPlusCommonUtil.getObjectName(bo.getFileMd5());
// 文件key
fileKey = bo.getFileKey();
uploadId = bo.getUploadId();
uploadCreateDTO.setUploadId(bo.getUploadId());
// 开始位置
long start = (long) (bo.getMissPartNum().get(0) - 1) * properties.getPart().getSize();
for (int partNumber : bo.getMissPartNum()) {
FileCheckResultVo.Part part = this.buildResultPart(uploadCreateDTO, uploadId, bo.getFileSize(), start, partNumber);
FileCheckResultVo.Part part = this.buildResultPart(bucketName,storagePath, uploadId, bo.getFileSize(), start, partNumber);
// 更改下一次的开始位置
start = start + properties.getPart().getSize();
partList.add(part);
@ -806,15 +798,10 @@ public class StorageEngineServiceImpl implements StorageEngineService {
uploadId = fileKey;
} else {
// 创建分片请求,获取uploadId
MultipartUploadCreateDTO uploadCreateDTO = MultipartUploadCreateDTO.builder()
.bucketName(bucketName)
.objectName(MinioPlusCommonUtil.getObjectName(bo.getFileMd5()))
.build();
uploadId = minioS3Client.createMultipartUpload(bucketName,MinioPlusCommonUtil.getObjectName(bo.getFileMd5()));
uploadCreateDTO.setUploadId(uploadId);
long start = 0;
for (Integer partNumber = 1; partNumber <= chunkNum; partNumber++) {
FileCheckResultVo.Part part = this.buildResultPart(uploadCreateDTO, uploadId, bo.getFileSize(), start, partNumber);
FileCheckResultVo.Part part = this.buildResultPart(bucketName,MinioPlusCommonUtil.getObjectName(bo.getFileMd5()), uploadId, bo.getFileSize(), start, partNumber);
// 更改下一次的开始位置
start = start + properties.getPart().getSize();
partList.add(part);

View File

@ -1,9 +1,9 @@
package org.liuxp.minioplus.core.repository;
import org.liuxp.minioplus.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoUpdateDTO;
import org.liuxp.minioplus.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoUpdateDTO;
import org.liuxp.minioplus.api.model.vo.FileMetadataInfoVo;
import java.util.List;

View File

@ -9,18 +9,18 @@ import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import org.liuxp.minioplus.common.config.MinioPlusProperties;
import org.liuxp.minioplus.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.model.dto.FileSaveDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoDTO;
import org.liuxp.minioplus.api.model.dto.FileMetadataInfoSaveDTO;
import org.liuxp.minioplus.api.model.dto.FileSaveDTO;
import org.liuxp.minioplus.common.enums.MinioPlusErrorCode;
import org.liuxp.minioplus.common.enums.StorageBucketEnums;
import org.liuxp.minioplus.common.exception.MinioPlusException;
import org.liuxp.minioplus.core.common.utils.ContentTypeUtil;
import org.liuxp.minioplus.core.common.utils.MinioPlusCommonUtil;
import org.liuxp.minioplus.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.api.model.vo.FileMetadataInfoVo;
import org.liuxp.minioplus.core.engine.StorageEngineService;
import org.liuxp.minioplus.core.repository.MetadataRepository;
import org.liuxp.minioplus.core.service.StorageService;
import org.liuxp.minioplus.api.StorageService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -54,16 +54,7 @@ public class StorageServiceImpl implements StorageService {
MinioPlusProperties properties;
@Override
public FileMetadataInfoVo oneById(Long id) {
FileMetadataInfoDTO fileMetadataInfo = new FileMetadataInfoDTO();
fileMetadataInfo.setId(id);
return fileMetadataRepository.one(fileMetadataInfo);
}
@Override
public FileMetadataInfoVo oneByKey(String key) {
public FileMetadataInfoVo one(String key) {
FileMetadataInfoDTO fileMetadataInfo = new FileMetadataInfoDTO();
fileMetadataInfo.setFileKey(key);

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-plus-extension</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -7,10 +7,10 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.liuxp.minioplus.common.config.MinioPlusProperties;
import org.liuxp.minioplus.extension.context.Response;
import org.liuxp.minioplus.model.dto.FileCheckDTO;
import org.liuxp.minioplus.model.dto.FileCompleteDTO;
import org.liuxp.minioplus.model.vo.CompleteResultVo;
import org.liuxp.minioplus.model.vo.FileCheckResultVo;
import org.liuxp.minioplus.api.model.dto.FileCheckDTO;
import org.liuxp.minioplus.api.model.dto.FileCompleteDTO;
import org.liuxp.minioplus.api.model.vo.CompleteResultVo;
import org.liuxp.minioplus.api.model.vo.FileCheckResultVo;
import org.liuxp.minioplus.core.engine.StorageEngineService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-plus-all-spring-boot-starter</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-s3-api-custom</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-s3-api-definition</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>minio-s3-api-official</artifactId>
<packaging>jar</packaging>
<dependencies>
<!-- minio -->

View File

@ -35,11 +35,11 @@
</scm>
<modules>
<module>minio-plus-api</module>
<module>minio-plus-application</module>
<module>minio-plus-common</module>
<module>minio-plus-core</module>
<module>minio-plus-extension</module>
<module>minio-plus-model</module>
<module>minio-plus-spring-boot-starter</module>
<module>minio-s3-api</module>
</modules>
@ -153,7 +153,7 @@
</dependency>
<dependency>
<groupId>org.liuxp</groupId>
<artifactId>minio-plus-model</artifactId>
<artifactId>minio-plus-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>