diff --git a/minio-plus-api/src/main/java/org/liuxp/minioplus/api/StorageService.java b/minio-plus-api/src/main/java/org/liuxp/minioplus/api/StorageService.java index 906b0dc8d..c88a9c936 100644 --- a/minio-plus-api/src/main/java/org/liuxp/minioplus/api/StorageService.java +++ b/minio-plus-api/src/main/java/org/liuxp/minioplus/api/StorageService.java @@ -1,8 +1,11 @@ package org.liuxp.minioplus.api; import cn.hutool.core.lang.Pair; +import org.liuxp.minioplus.api.model.dto.FileCheckDTO; import org.liuxp.minioplus.api.model.dto.FileMetadataInfoDTO; import org.liuxp.minioplus.api.model.dto.FileSaveDTO; +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.io.InputStream; @@ -16,14 +19,70 @@ import java.util.List; public interface StorageService { /** - * 根据文件key查询 + * 上传任务初始化 + * + * @param dto dto + * @param userId 用户编号 + * @return {@link FileCheckResultVo} + */ + FileCheckResultVo init(FileCheckDTO dto, String userId); + + + /** + * 合并已分块的文件 + * + * @param fileKey 文件关键 + * @param partMd5List 文件分块md5列表 + * @param userId 用户编号 + * + * @return {@link CompleteResultVo} + */ + CompleteResultVo complete(String fileKey, List partMd5List,String userId); + + /** + * 上传图片 + * @param fileKey 文件KEY + * @param file 文件 + * @return 是否成功 + */ + Boolean uploadImage(String fileKey, byte[] file); + + /** + * 取得文件下载地址 + * + * @param fileKey 文件KEY + * @param userId 用户编号 + * @return 地址 + */ + String download(String fileKey, String userId); + + /** + * 取得原图地址 + * + * @param fileKey 文件KEY + * @param userId 用户编号 + * @return 地址 + */ + String image(String fileKey, String userId); + + /** + * 取得缩略图地址 + * + * @param fileKey 文件KEY + * @param userId 用户编号 + * @return 地址 + */ + String preview(String fileKey, String userId); + + /** + * 查询元数据信息 * @param key 文件key * @return 文件元数据信息 */ FileMetadataInfoVo one(String key); /** - * 列表数据查询 + * 查询元数据信息 * @param fileMetadataInfo 查询入参 * @return 文件元数据信息集合 */ diff --git a/minio-plus-core/src/main/java/org/liuxp/minioplus/core/service/impl/StorageServiceImpl.java b/minio-plus-core/src/main/java/org/liuxp/minioplus/core/service/impl/StorageServiceImpl.java index 8246b3c6b..02b734d7e 100644 --- a/minio-plus-core/src/main/java/org/liuxp/minioplus/core/service/impl/StorageServiceImpl.java +++ b/minio-plus-core/src/main/java/org/liuxp/minioplus/core/service/impl/StorageServiceImpl.java @@ -5,9 +5,13 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.lang.Pair; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; +import org.liuxp.minioplus.api.model.dto.FileCheckDTO; +import org.liuxp.minioplus.api.model.vo.CompleteResultVo; +import org.liuxp.minioplus.api.model.vo.FileCheckResultVo; import org.liuxp.minioplus.common.config.MinioPlusProperties; import org.liuxp.minioplus.api.model.dto.FileMetadataInfoDTO; import org.liuxp.minioplus.api.model.dto.FileMetadataInfoSaveDTO; @@ -53,6 +57,52 @@ public class StorageServiceImpl implements StorageService { @Resource MinioPlusProperties properties; + @Override + public FileCheckResultVo init(FileCheckDTO dto, String userId) { + FileCheckResultVo resultVo = storageEngineService.init(dto,userId); + + if(resultVo!=null){ + for (FileCheckResultVo.Part part : resultVo.getPartList()) { + part.setUrl(remakeUrl(part.getUrl())); + } + } + + return resultVo; + } + + @Override + public CompleteResultVo complete(String fileKey, List partMd5List, String userId) { + CompleteResultVo completeResultVo = storageEngineService.complete(fileKey,partMd5List,userId); + + if(completeResultVo!=null){ + for (FileCheckResultVo.Part part : completeResultVo.getPartList()) { + part.setUrl(remakeUrl(part.getUrl())); + } + } + + return completeResultVo; + } + + @Override + public Boolean uploadImage(String fileKey, byte[] file) { + return storageEngineService.uploadImage(fileKey,file); + } + + @Override + public String download(String fileKey, String userId) { + return storageEngineService.download(fileKey,userId); + } + + @Override + public String image(String fileKey, String userId) { + return storageEngineService.image(fileKey,userId); + } + + @Override + public String preview(String fileKey, String userId) { + return storageEngineService.preview(fileKey,userId); + } + @Override public FileMetadataInfoVo one(String key) { @@ -174,4 +224,17 @@ public class StorageServiceImpl implements StorageService { return fileMetadataInfoSaveDTO; } + + /** + * 重写文件地址 + * @param url 文件地址 + * @return 重写后的文件地址 + */ + private String remakeUrl(String url){ + + if(StrUtil.isNotBlank(properties.getBrowserUrl())){ + return url.replace(properties.getBackend(), properties.getBrowserUrl()); + } + return url; + } } diff --git a/minio-plus-extension/src/main/java/org/liuxp/minioplus/extension/controller/StorageController.java b/minio-plus-extension/src/main/java/org/liuxp/minioplus/extension/controller/StorageController.java index 99251a9ce..b0a6aa392 100644 --- a/minio-plus-extension/src/main/java/org/liuxp/minioplus/extension/controller/StorageController.java +++ b/minio-plus-extension/src/main/java/org/liuxp/minioplus/extension/controller/StorageController.java @@ -1,24 +1,21 @@ package org.liuxp.minioplus.extension.controller; import cn.hutool.core.io.IoUtil; -import cn.hutool.core.util.StrUtil; import io.swagger.annotations.Api; 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.api.StorageService; 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.liuxp.minioplus.extension.context.Response; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; - import java.io.IOException; import java.io.InputStream; @@ -42,13 +39,7 @@ public class StorageController { * 存储引擎Service接口定义 */ @Resource - private StorageEngineService storageEngineService; - - /** - * 配置文件 - */ - @Resource - MinioPlusProperties properties; + private StorageService storageService; /** * 上传任务初始化 @@ -64,13 +55,7 @@ public class StorageController { // 取得当前登录用户信息 String userId = "mockUser"; - FileCheckResultVo resultVo = storageEngineService.init(fileCheckDTO,userId); - - if(resultVo!=null){ - for (FileCheckResultVo.Part part : resultVo.getPartList()) { - part.setUrl(remakeUrl(part.getUrl())); - } - } + FileCheckResultVo resultVo = storageService.init(fileCheckDTO,userId); return Response.success(resultVo); } @@ -90,13 +75,7 @@ public class StorageController { // 打印调试日志 log.debug("合并文件开始fileKey="+fileKey+",partMd5List="+fileCompleteDTO.getPartMd5List()); - CompleteResultVo completeResultVo = storageEngineService.complete(fileKey,fileCompleteDTO.getPartMd5List(),userId); - - if(completeResultVo!=null){ - for (FileCheckResultVo.Part part : completeResultVo.getPartList()) { - part.setUrl(remakeUrl(part.getUrl())); - } - } + CompleteResultVo completeResultVo = storageService.complete(fileKey,fileCompleteDTO.getPartMd5List(),userId); return Response.success(completeResultVo); } @@ -115,7 +94,7 @@ public class StorageController { InputStream inputStream = null; try { inputStream = request.getInputStream(); - isUpload = storageEngineService.uploadImage(fileKey, IoUtil.readBytes(inputStream)); + isUpload = storageService.uploadImage(fileKey, IoUtil.readBytes(inputStream)); } catch (IOException e) { e.printStackTrace(); }finally { @@ -137,9 +116,7 @@ public class StorageController { // 取得当前登录用户信息 String userId = "mockUser"; // 取得文件读取路径 - String url = storageEngineService.download(fileKey, userId); - // 不存在时返回404 返回重定向地址 - return REDIRECT_PREFIX + remakeUrl(url); + return REDIRECT_PREFIX + storageService.download(fileKey, userId); } /** @@ -154,9 +131,7 @@ public class StorageController { // 取得当前登录用户信息 String userId = "mockUser"; // 取得文件读取路径 - String url = storageEngineService.image(fileKey, userId); - // 返回重定向地址 - return REDIRECT_PREFIX + remakeUrl(url); + return REDIRECT_PREFIX + storageService.image(fileKey, userId); } /** @@ -171,23 +146,7 @@ public class StorageController { // 取得当前登录用户信息 String userId = "mockUser"; // 取得文件读取路径 - String url = storageEngineService.preview(fileKey, userId); - // 返回重定向地址 - return REDIRECT_PREFIX + remakeUrl(url); + return REDIRECT_PREFIX + storageService.preview(fileKey, userId); } - - /** - * 重写文件地址 - * @param url 文件地址 - * @return 重写后的文件地址 - */ - private String remakeUrl(String url){ - - if(StrUtil.isNotBlank(properties.getBrowserUrl())){ - return url.replace(properties.getBackend(), properties.getBrowserUrl()); - } - return url; - } - -} +} \ No newline at end of file