From 86817db26388483e5d84ed9d5501052aff758f9f Mon Sep 17 00:00:00 2001 From: Cyan Date: Fri, 9 Dec 2022 17:27:39 +0800 Subject: [PATCH 01/30] spring boot -> 2.7.6 minio -> 8.4.6 --- SECURITY.md | 4 ++-- file-toolkit-common-starter/pom.xml | 4 ++-- file-toolkit-hdfs-starter/pom.xml | 4 ++-- file-toolkit-minio-starter/pom.xml | 4 ++-- file-toolkit-minio-utils/pom.xml | 10 ++-------- file-toolkit-service-starter/pom.xml | 4 ++-- file-toolkit-test-web/pom.xml | 16 ++-------------- pom.xml | 17 ++++++++--------- 8 files changed, 22 insertions(+), 41 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index e678037..a6708d2 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,8 +7,8 @@ currently being supported with security updates. | Version | Supported | | ------- | ------------------ | -| Spring boot 2.6.6+ | :white_check_mark: | -| < 2.6.6 | :x: | +| Spring boot 2.7.6+ | :white_check_mark: | +| < 2.7.6 | :x: | | Maven 3.6.0+ | :white_check_mark: | | < 3.6.0 | :x: | | JDK 1.8 | :white_check_mark: | | diff --git a/file-toolkit-common-starter/pom.xml b/file-toolkit-common-starter/pom.xml index c94410b..1cb1f8f 100644 --- a/file-toolkit-common-starter/pom.xml +++ b/file-toolkit-common-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-common-starter - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-common-starter File toolkit common starter project for Spring Boot diff --git a/file-toolkit-hdfs-starter/pom.xml b/file-toolkit-hdfs-starter/pom.xml index 1d06e5f..c1dd773 100644 --- a/file-toolkit-hdfs-starter/pom.xml +++ b/file-toolkit-hdfs-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-hdfs-starter - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-hdfs-starter jar File toolkit hdfs project for Spring Boot diff --git a/file-toolkit-minio-starter/pom.xml b/file-toolkit-minio-starter/pom.xml index b85cdad..31fcfc1 100644 --- a/file-toolkit-minio-starter/pom.xml +++ b/file-toolkit-minio-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-minio-starter - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-minio-starter jar File toolkit minio project for Spring Boot diff --git a/file-toolkit-minio-utils/pom.xml b/file-toolkit-minio-utils/pom.xml index ba11643..ab6eb20 100644 --- a/file-toolkit-minio-utils/pom.xml +++ b/file-toolkit-minio-utils/pom.xml @@ -5,10 +5,10 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-minio-utils - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-minio-utils jar File toolkit minio utils project for Spring Boot @@ -77,12 +77,6 @@ ${minio.version} - - com.squareup.okhttp3 - okhttp - ${minio-okhttp3.version} - - diff --git a/file-toolkit-service-starter/pom.xml b/file-toolkit-service-starter/pom.xml index 3e590eb..0aeeee8 100644 --- a/file-toolkit-service-starter/pom.xml +++ b/file-toolkit-service-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-service-starter - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-service-starter jar File toolkit service project for Spring Boot diff --git a/file-toolkit-test-web/pom.xml b/file-toolkit-test-web/pom.xml index 9c66878..29a9f54 100644 --- a/file-toolkit-test-web/pom.xml +++ b/file-toolkit-test-web/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-test-web - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-test-web jar file toolkit test web project for Spring Boot @@ -27,18 +27,6 @@ io.github.nichetoolkit file-toolkit-minio-starter ${file-toolkit.version} - - - com.squareup.okhttp3 - okhttp - - - - - - com.squareup.okhttp3 - okhttp - ${minio-okhttp3.version} diff --git a/pom.xml b/pom.xml index 5ac174d..86dce50 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.3 + 1.0.4-SNAPSHOT file-toolkit-common-starter @@ -13,7 +13,7 @@ file-toolkit-hdfs-starter file-toolkit-minio-utils file-toolkit-minio-starter - + file-toolkit-test-web file-toolkit-parent @@ -44,7 +44,7 @@ org.springframework.boot spring-boot-starter-parent - 2.6.6 + 2.7.6 @@ -67,9 +67,9 @@ UTF-8 1.8 1.8 - 2.6.6 - 1.0.5 - 1.0.4 + 2.7.6 + 1.0.6-SNAPSHOT + 1.0.5-SNAPSHOT 2.2.1 2.9.1 @@ -78,15 +78,14 @@ 3.3 2.5.3 - 1.0.3 + 1.0.4-SNAPSHOT 2.8.5 0.4.16 4.1.5 2.1.5 - 8.3.7 - 4.8.1 + 8.4.6 From b9cd14795ea2b664d70a34ce4502bc2eaa66a719 Mon Sep 17 00:00:00 2001 From: Cyan Date: Sun, 29 Jan 2023 08:48:18 +0800 Subject: [PATCH 02/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/service/FileChunkService.java | 2 +- .../nichetoolkit/file/service/FileIndexService.java | 2 +- .../file/service/impl/FileIndexServiceImpl.java | 10 +++------- pom.xml | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java index a922d46..b6b5ad1 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileChunkService.java @@ -17,7 +17,7 @@ * @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public interface FileChunkService extends FilterService, RemoveService { +public interface FileChunkService extends FilterService, RemoveService { /** * 通过id查询实体 diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java index 3fe0c02..b31c2a8 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileIndexService.java @@ -12,7 +12,7 @@ * @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public interface FileIndexService extends FilterService, RemoveService { +public interface FileIndexService extends FilterService, RemoveService { /** * 通过id集合查询单个 diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java index a597a6e..a338010 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java @@ -8,6 +8,7 @@ import io.github.nichetoolkit.file.service.FileChunkService; import io.github.nichetoolkit.file.service.FileIndexService; import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.actuator.BiConsumerActuator; import io.github.nichetoolkit.rest.actuator.ConsumerActuator; import io.github.nichetoolkit.rest.util.GeneralUtils; import io.github.nichetoolkit.rice.RiceInfoService; @@ -61,13 +62,8 @@ public String queryWhereSql(FileFilter filter) throws RestException { } @Override - public String deleteWhereSql(FileFilter filter) throws RestException { - return filter.toIdSql().toSql(); - } - - @Override - protected ConsumerActuator updateActuator() { - return this::optional; + protected BiConsumerActuator updateActuator() { + return (tableKey,fileIndex) -> this.optional(fileIndex); } @Override diff --git a/pom.xml b/pom.xml index 86dce50..90aec5e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ file-toolkit-hdfs-starter file-toolkit-minio-utils file-toolkit-minio-starter - file-toolkit-test-web + file-toolkit-parent From 2f3a69207294029148452078a188e7a64ab37f03 Mon Sep 17 00:00:00 2001 From: Cyan Date: Tue, 7 Feb 2023 16:45:25 +0800 Subject: [PATCH 03/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/service/impl/FileIndexServiceImpl.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java index a338010..1776aa3 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java @@ -36,6 +36,16 @@ public class FileIndexServiceImpl extends RiceInfoService Date: Tue, 7 Feb 2023 16:48:14 +0800 Subject: [PATCH 04/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/service/impl/FileIndexServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java index 1776aa3..d17b493 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java @@ -38,7 +38,7 @@ public class FileIndexServiceImpl extends RiceInfoService Date: Mon, 27 Feb 2023 09:59:02 +0800 Subject: [PATCH 05/30] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/nichetoolkit/file/helper/FileServiceHelper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index 00fa310..ccf6880 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -140,6 +140,8 @@ public static void condenseImage(String randomPath, FileIndex fileIndex) throws } Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } else { + imageFileQuality = INSTANCE.serviceProperties.getMinImageQuality(); + imageFileScale = INSTANCE.serviceProperties.getMinImageScale(); Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } } catch (IOException exception) { From 3aedf225db3c1fb3844a395aa6a59c8a07ae9d0d Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 10:39:17 +0800 Subject: [PATCH 06/30] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/helper/FileServiceHelper.java | 89 ----------- .../file/service/FileHandleService.java | 18 +++ .../file/service/FileService.java | 2 +- .../file/service/FileUploadService.java | 20 +++ .../service/impl/FileHandleServiceImpl.java | 138 ++++++++++++++++++ .../file/service/impl/FileServiceImpl.java | 43 ++---- .../service/impl/FileUploadServiceImpl.java | 82 +++++++++++ 7 files changed, 271 insertions(+), 121 deletions(-) create mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java create mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java create mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java create mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index ccf6880..82e7094 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -80,95 +80,6 @@ public static void checkRestPage(RestPage restPage) throws RestException { } } - public static void condenseFile(String randomPath, FileIndex fileIndex) throws RestException { - String filename = fileIndex.getName(); - String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = FileUtils.createFile(filePath); - StreamUtils.write(file, fileIndex.inputStream()); - File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); - buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); - if (fileIndex.getIsMd5()) { - buildMd5(zipFile, fileIndex); - } - } - - public static void autographImage(String randomPath, FileIndex fileIndex) throws RestException { - InputStream inputStream = fileIndex.inputStream(); - BufferedImage bufferedImage = ImageUtils.read(inputStream); - BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); - BufferedImage autographImage = ImageUtils.autograph(binaryImage); - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = new File(filePath); - if (file.exists()) { - FileUtils.delete(filePath); - } - ImageUtils.write(autographImage, file); - byte[] bytes = ImageUtils.bytes(file); - fileIndex.setBytes(bytes); - FileUtils.delete(filePath); - } - - public static void condenseImage(String randomPath, FileIndex fileIndex) throws RestException { - Long imageFileSize; - Double imageFileQuality = 1.0d; - Double imageFileScale = 1.0d; - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath; - File file; - Integer width = fileIndex.getWidth(); - Integer height = fileIndex.getHeight(); - filePath = randomPath.concat(File.separator).concat(filename); - file = new File(filePath); - do { - if (file.exists()) { - FileUtils.delete(filePath); - } - try { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - BufferedImage bufferedImage = ImageHelper.read(file); - int imageWidth = bufferedImage.getWidth(); - int imageHeight = bufferedImage.getHeight(); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { - if (GeneralUtils.isNotEmpty(width)) { - imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); - } else { - imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); - } - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else { - imageFileQuality = INSTANCE.serviceProperties.getMinImageQuality(); - imageFileScale = INSTANCE.serviceProperties.getMinImageScale(); - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } - } catch (IOException exception) { - log.error("the image file has error during condensing: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); - } - imageFileSize = file.length(); - if (imageFileQuality.equals(INSTANCE.serviceProperties.getMinImageQuality())) { - imageFileScale += -0.1d; - } else { - imageFileQuality += -0.1d; - } - } while (imageFileSize > INSTANCE.serviceProperties.getMaxImageSize() - && imageFileQuality > INSTANCE.serviceProperties.getMinImageQuality() - && imageFileScale > INSTANCE.serviceProperties.getMinImageScale()); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); - } else { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); - } - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); - buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); - buildMd5(file, fileIndex); - FileUtils.clearFile(randomPath); - } - public static void buildProperties(String filename, long size, String suffix, FileIndex fileIndex) { fileIndex.addProperty(FileConstants.ORIGINAL_SUFFIX_PROPERTY, fileIndex.getSuffix()); fileIndex.setSuffix(suffix); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java new file mode 100644 index 0000000..cff4d03 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java @@ -0,0 +1,18 @@ +package io.github.nichetoolkit.file.service; + +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.rest.RestException; + +/** + *

FileHandleService

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +public interface FileHandleService { + + void autographImage(String randomPath, FileIndex fileIndex) throws RestException; + + void condenseImage(String randomPath, FileIndex fileIndex) throws RestException; + + void condenseFile(String randomPath, FileIndex fileIndex) throws RestException; +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java index e2c11f3..f3d1c70 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java @@ -127,6 +127,6 @@ public interface FileService { * @return FileIndex * @throws RestException 服务异常 */ - Future chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException; + FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException; } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java new file mode 100644 index 0000000..6f1c2e7 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java @@ -0,0 +1,20 @@ +package io.github.nichetoolkit.file.service; + +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.file.model.FileRequest; +import io.github.nichetoolkit.rest.RestException; +import org.springframework.web.multipart.MultipartFile; + +/** + *

FileUploadService

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +public interface FileUploadService { + + void uploadFileIndex(FileIndex fileIndex) throws RestException; + + void uploadChunk(FileIndex fileIndex) throws RestException; + + void lastChunk(FileIndex fileIndex) throws RestException; +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java new file mode 100644 index 0000000..8b0b769 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -0,0 +1,138 @@ +package io.github.nichetoolkit.file.service.impl; + +import io.github.nichetoolkit.file.configure.FileCommonProperties; +import io.github.nichetoolkit.file.constant.FileConstants; +import io.github.nichetoolkit.file.enums.FileType; +import io.github.nichetoolkit.file.error.FileErrorStatus; +import io.github.nichetoolkit.file.helper.FileServiceHelper; +import io.github.nichetoolkit.file.helper.ImageHelper; +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.file.service.FileHandleService; +import io.github.nichetoolkit.file.util.ImageUtils; +import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.identity.IdentityUtils; +import io.github.nichetoolkit.rest.util.FileUtils; +import io.github.nichetoolkit.rest.util.GeneralUtils; +import io.github.nichetoolkit.rest.util.StreamUtils; +import io.github.nichetoolkit.rest.util.ZipUtils; +import lombok.extern.slf4j.Slf4j; +import net.coobird.thumbnailator.Thumbnails; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +/** + *

FileHandleServiceImpl

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Service +public class FileHandleServiceImpl implements FileHandleService { + + @Autowired + protected FileCommonProperties commonProperties; + @Autowired + private FileCommonProperties serviceProperties; + + @Async + @Override + public void autographImage(String randomPath, FileIndex fileIndex) throws RestException { + InputStream inputStream = fileIndex.inputStream(); + BufferedImage bufferedImage = ImageUtils.read(inputStream); + BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); + BufferedImage autographImage = ImageUtils.autograph(binaryImage); + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = new File(filePath); + if (file.exists()) { + FileUtils.delete(filePath); + } + ImageUtils.write(autographImage, file); + byte[] bytes = ImageUtils.bytes(file); + fileIndex.setBytes(bytes); + FileUtils.delete(filePath); + } + + @Async + @Override + public void condenseImage(String randomPath, FileIndex fileIndex) throws RestException { + Long imageFileSize; + Double imageFileQuality = 1.0d; + Double imageFileScale = 1.0d; + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath; + File file; + Integer width = fileIndex.getWidth(); + Integer height = fileIndex.getHeight(); + filePath = randomPath.concat(File.separator).concat(filename); + file = new File(filePath); + do { + if (file.exists()) { + FileUtils.delete(filePath); + } + try { + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + BufferedImage bufferedImage = ImageHelper.read(file); + int imageWidth = bufferedImage.getWidth(); + int imageHeight = bufferedImage.getHeight(); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { + if (GeneralUtils.isNotEmpty(width)) { + imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); + } else { + imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); + } + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else { + imageFileQuality = serviceProperties.getMinImageQuality(); + imageFileScale = serviceProperties.getMinImageScale(); + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } + } catch (IOException exception) { + log.error("the image file has error during condensing: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); + } + imageFileSize = file.length(); + if (imageFileQuality.equals(serviceProperties.getMinImageQuality())) { + imageFileScale += -0.1d; + } else { + imageFileQuality += -0.1d; + } + } while (imageFileSize > serviceProperties.getMaxImageSize() + && imageFileQuality > serviceProperties.getMinImageQuality() + && imageFileScale > serviceProperties.getMinImageScale()); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); + } else { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); + } + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); + FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); + FileServiceHelper.buildMd5(file, fileIndex); + FileUtils.clearFile(randomPath); + } + + @Async + @Override + public void condenseFile(String randomPath, FileIndex fileIndex) throws RestException { + String filename = fileIndex.getName(); + String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = FileUtils.createFile(filePath); + StreamUtils.write(file, fileIndex.inputStream()); + File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); + FileServiceHelper.buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); + if (fileIndex.getIsMd5()) { + FileServiceHelper.buildMd5(zipFile, fileIndex); + } + } +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index bdfa508..bab0aa8 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -9,10 +9,7 @@ import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.file.service.AsyncFileService; -import io.github.nichetoolkit.file.service.FileChunkService; -import io.github.nichetoolkit.file.service.FileIndexService; -import io.github.nichetoolkit.file.service.FileService; +import io.github.nichetoolkit.file.service.*; import io.github.nichetoolkit.file.video.VideoHttpRequestHandler; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; @@ -62,6 +59,9 @@ public class FileServiceImpl implements FileService { @Autowired protected FileChunkService fileChunkService; + @Autowired + protected FileUploadService fileUploadService; + @Autowired protected AsyncFileService asyncFileService; @@ -304,28 +304,13 @@ public FileIndex upload(FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { throw new RestException(FileErrorStatus.FILE_INDEX_IS_NULL); } - String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); - - if (fileIndex.getIsAutograph() != null && fileIndex.getIsAutograph() && fileIndex.getFileType() == FileType.IMAGE) { - FileServiceHelper.autographImage(randomPath, fileIndex); - } - if (fileIndex.getIsCondense()) { - if (fileIndex.getFileType() == FileType.IMAGE) { - FileServiceHelper.condenseImage(randomPath, fileIndex); - } else { - FileServiceHelper.condenseFile(randomPath, fileIndex); - } - } - String fileId = fileIndex.getId(); if (GeneralUtils.isEmpty(fileIndex.getId())) { - fileId = IdentityUtils.generateString(); + String fileId = IdentityUtils.generateString(); fileIndex.setId(fileId); } - asyncFileService.putById(fileId, fileIndex.inputStream()); - FileUtils.clear(randomPath); + fileUploadService.uploadFileIndex(fileIndex); checkFileIndex(fileIndex); - return fileIndexService.save(fileIndex); + return fileIndex; } @Override @@ -341,27 +326,23 @@ public FileIndex indexUpload(FileIndex fileIndex) throws RestException { } @Override - @Async - public Future chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { + public FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { FileIndex fileChunkIndex = FileServiceHelper.createFileChunk(fileRequest, contentRange); FileIndex fileIndex = FileServiceHelper.createFileChunk(file, fileChunkIndex); - FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); - asyncFileService.putById(uploadChunk.getId(), uploadChunk.inputStream()); - fileIndex.setFileChunk(uploadChunk); + fileUploadService.uploadChunk(fileIndex); if (GeneralUtils.isEmpty(fileIndex.getFileChunks())) { fileIndex.setFileChunks(new ArrayList<>()); } List fileChunks = fileIndex.getFileChunks(); + FileChunk uploadChunk = fileIndex.getFileChunk(); fileChunks.add(uploadChunk); fileIndex.setCurrentIndex(uploadChunk.getChunkIndex()); if ((uploadChunk.getIsLastChunk() || uploadChunk.getChunkIndex().equals(fileIndex.getSliceSize())) && fileIndex.getIsMerge()) { - List sources = fileChunks.stream().map(RestId::getId).collect(Collectors.toList()); fileIndex.setIsFinish(true); - asyncFileService.margeById(fileIndex.getId(), sources); checkFileIndex(fileIndex); - fileIndexService.save(fileIndex); + fileUploadService.lastChunk(fileIndex); } - return AsyncResult.forValue(fileIndex); + return fileIndex; } private void checkFileIndex(FileIndex fileIndex) { diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java new file mode 100644 index 0000000..d6586f9 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java @@ -0,0 +1,82 @@ +package io.github.nichetoolkit.file.service.impl; + +import io.github.nichetoolkit.file.configure.FileCommonProperties; +import io.github.nichetoolkit.file.enums.FileType; +import io.github.nichetoolkit.file.model.FileChunk; +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.file.service.*; +import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.util.FileUtils; +import io.github.nichetoolkit.rest.util.GeneralUtils; +import io.github.nichetoolkit.rice.RestId; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +/** + *

FileUploadServiceImpl

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Service +public class FileUploadServiceImpl implements FileUploadService { + + @Autowired + protected FileCommonProperties commonProperties; + + @Autowired + protected FileIndexService fileIndexService; + + @Autowired + protected FileChunkService fileChunkService; + + @Autowired + protected FileHandleService fileHandleService; + + @Autowired + protected AsyncFileService asyncFileService; + + @Async + @Override + public void uploadFileIndex(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + + if (fileIndex.getIsAutograph() != null && fileIndex.getIsAutograph() && fileIndex.getFileType() == FileType.IMAGE) { + fileHandleService.autographImage(randomPath, fileIndex); + } + if (fileIndex.getIsCondense()) { + if (fileIndex.getFileType() == FileType.IMAGE) { + fileHandleService.condenseImage(randomPath, fileIndex); + } else { + fileHandleService.condenseFile(randomPath, fileIndex); + } + } + String fileId = fileIndex.getId(); + asyncFileService.putById(fileId, fileIndex.inputStream()); + FileUtils.clear(randomPath); + fileIndexService.save(fileIndex); + } + + @Async + @Override + public void uploadChunk(FileIndex fileIndex) throws RestException { + FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); + asyncFileService.putById(uploadChunk.getId(), uploadChunk.inputStream()); + fileIndex.setFileChunk(uploadChunk); + } + + @Async + @Override + public void lastChunk(FileIndex fileIndex) throws RestException { + List sources = fileIndex.getFileChunks().stream().map(RestId::getId).collect(Collectors.toList()); + asyncFileService.margeById(fileIndex.getId(), sources); + fileIndexService.save(fileIndex); + } + +} From 34b05f2bd4a3d181ae2c779a26114927725a225c Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 10:43:10 +0800 Subject: [PATCH 07/30] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/service/impl/FileHandleServiceImpl.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 8b0b769..54e9541 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -92,8 +92,6 @@ public void condenseImage(String randomPath, FileIndex fileIndex) throws RestExc } Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } else { - imageFileQuality = serviceProperties.getMinImageQuality(); - imageFileScale = serviceProperties.getMinImageScale(); Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } } catch (IOException exception) { From 69e0f4f9d555d4427919de7367199d2fc3fd0fa3 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 10:55:24 +0800 Subject: [PATCH 08/30] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/service/FileHandleService.java | 6 +++--- .../file/service/impl/FileHandleServiceImpl.java | 15 ++++++++++++--- .../file/service/impl/FileUploadServiceImpl.java | 10 +++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java index cff4d03..d619792 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileHandleService.java @@ -10,9 +10,9 @@ */ public interface FileHandleService { - void autographImage(String randomPath, FileIndex fileIndex) throws RestException; + void autographImage(FileIndex fileIndex) throws RestException; - void condenseImage(String randomPath, FileIndex fileIndex) throws RestException; + void condenseImage(FileIndex fileIndex) throws RestException; - void condenseFile(String randomPath, FileIndex fileIndex) throws RestException; + void condenseFile(FileIndex fileIndex) throws RestException; } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 54e9541..64e13a2 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -43,7 +43,9 @@ public class FileHandleServiceImpl implements FileHandleService { @Async @Override - public void autographImage(String randomPath, FileIndex fileIndex) throws RestException { + public void autographImage(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); InputStream inputStream = fileIndex.inputStream(); BufferedImage bufferedImage = ImageUtils.read(inputStream); BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); @@ -58,11 +60,14 @@ public void autographImage(String randomPath, FileIndex fileIndex) throws RestEx byte[] bytes = ImageUtils.bytes(file); fileIndex.setBytes(bytes); FileUtils.delete(filePath); + FileUtils.clear(randomPath); } @Async @Override - public void condenseImage(String randomPath, FileIndex fileIndex) throws RestException { + public void condenseImage(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); Long imageFileSize; Double imageFileQuality = 1.0d; Double imageFileScale = 1.0d; @@ -117,11 +122,14 @@ public void condenseImage(String randomPath, FileIndex fileIndex) throws RestExc FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); FileServiceHelper.buildMd5(file, fileIndex); FileUtils.clearFile(randomPath); + FileUtils.clear(randomPath); } @Async @Override - public void condenseFile(String randomPath, FileIndex fileIndex) throws RestException { + public void condenseFile(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); String filename = fileIndex.getName(); String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); @@ -132,5 +140,6 @@ public void condenseFile(String randomPath, FileIndex fileIndex) throws RestExce if (fileIndex.getIsMd5()) { FileServiceHelper.buildMd5(zipFile, fileIndex); } + FileUtils.clear(randomPath); } } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java index d6586f9..4b6fc98 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java @@ -44,22 +44,18 @@ public class FileUploadServiceImpl implements FileUploadService { @Async @Override public void uploadFileIndex(FileIndex fileIndex) throws RestException { - String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); - if (fileIndex.getIsAutograph() != null && fileIndex.getIsAutograph() && fileIndex.getFileType() == FileType.IMAGE) { - fileHandleService.autographImage(randomPath, fileIndex); + fileHandleService.autographImage(fileIndex); } if (fileIndex.getIsCondense()) { if (fileIndex.getFileType() == FileType.IMAGE) { - fileHandleService.condenseImage(randomPath, fileIndex); + fileHandleService.condenseImage(fileIndex); } else { - fileHandleService.condenseFile(randomPath, fileIndex); + fileHandleService.condenseFile(fileIndex); } } String fileId = fileIndex.getId(); asyncFileService.putById(fileId, fileIndex.inputStream()); - FileUtils.clear(randomPath); fileIndexService.save(fileIndex); } From 6b88d23411258f3b836b1bb7ad648e76a62c803c Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 11:24:46 +0800 Subject: [PATCH 09/30] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/model/FileIndex.java | 8 +++--- .../file/helper/FileServiceHelper.java | 26 ++++++++++++------- .../service/impl/FileHandleServiceImpl.java | 15 ++++++----- .../file/service/impl/FileServiceImpl.java | 4 --- .../service/impl/FileUploadServiceImpl.java | 2 -- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index 75a3434..e6f15e3 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -19,9 +19,7 @@ import org.springframework.lang.NonNull; import org.springframework.web.multipart.MultipartFile; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -111,7 +109,7 @@ public class FileIndex extends RiceInfoModel { protected byte[] bytes; @JsonIgnore - protected MultipartFile file; + protected File file; public FileIndex() { } @@ -126,7 +124,7 @@ public InputStream inputStream() { return new ByteArrayInputStream(this.bytes); } else if (GeneralUtils.isNotEmpty(this.file)) { try { - return this.file.getInputStream(); + return new FileInputStream(this.file); } catch (IOException ignored) { } } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index 82e7094..daf31b4 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -17,6 +17,7 @@ import io.github.nichetoolkit.file.util.Md5Utils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.identity.IdentityUtils; import io.github.nichetoolkit.rest.util.*; import io.github.nichetoolkit.rice.RestPage; import io.github.nichetoolkit.rice.helper.PropertyHelper; @@ -47,7 +48,7 @@ public class FileServiceHelper implements InitializingBean { @Autowired - private FileCommonProperties serviceProperties; + private FileCommonProperties commonProperties; @Autowired private FileIndexService fileIndexService; @@ -109,7 +110,7 @@ public static void buildChunkFiles(List fileIndices, FileFilter fileF public static void buildIndexFiles(List fileIndices, FileFilter fileFilter, String randomPath, List fileList) throws RestException { for (FileIndex fileIndex : fileIndices) { - if (fileIndex.getFileSize() > INSTANCE.serviceProperties.getMaxFileSize()) { + if (fileIndex.getFileSize() > INSTANCE.commonProperties.getMaxFileSize()) { log.warn("the file size is too large, id: {}, size: {}", fileIndex.getId(), fileIndex.getFileSize()); throw new FileErrorException(FileErrorStatus.FILE_TOO_LARGE_ERROR); } @@ -240,7 +241,7 @@ public static void buildMd5(byte[] bytes, FileChunk fileChunk) throws RestExcept fileChunk.setChunkMd5(md5); } - public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) throws RestException { + public static FileIndex createFileChunk(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { log.warn("the file index is null!"); throw new FileErrorException(FileErrorStatus.FILE_INDEX_IS_NULL); @@ -272,8 +273,8 @@ public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) } Long chunkSize = fileChunk.getChunkSize(); if (GeneralUtils.isEmpty(chunkSize)) { - chunkSize = file.getSize(); - fileChunk.setChunkSize(file.getSize()); + chunkSize = multipartFile.getSize(); + fileChunk.setChunkSize(multipartFile.getSize()); } Long chunkStart = fileChunk.getChunkStart(); if (chunkStart == null) { @@ -289,7 +290,7 @@ public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) log.error("the param of 'chunkEnd' or 'chunkStart' or 'chunkSize' for file chunk is invalid! "); throw new FileErrorException(FileErrorStatus.FILE_CHUNK_PARAM_INVALID); } - buildMd5(file, fileChunk); + buildMd5(multipartFile, fileChunk); fileChunk.setChunkTime(new Date()); if (fileChunk.getChunkIndex() == 1) { @@ -350,12 +351,19 @@ public static FileIndex createFileChunk(FileRequest fileRequest, String contentR return fileIndex; } - public static FileIndex createFileIndex(MultipartFile file, FileIndex fileIndex) throws RestException { + public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { fileIndex = new FileIndex(); } - String originalFilename = file.getOriginalFilename(); + if (GeneralUtils.isEmpty(fileIndex.getId())) { + String fileId = IdentityUtils.generateString(); + fileIndex.setId(fileId); + } + String originalFilename = multipartFile.getOriginalFilename(); fileIndex.setName(originalFilename); + String tempPath = FileUtils.createPath(INSTANCE.commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + File file = FileUtils.cacheFile(cachePath, multipartFile); fileIndex.setFile(file); String filename = FileUtils.filename(originalFilename); if (GeneralUtils.isEmpty(fileIndex.getFilename())) { @@ -368,7 +376,7 @@ public static FileIndex createFileIndex(MultipartFile file, FileIndex fileIndex) if (GeneralUtils.isEmpty(fileIndex.getSuffix())) { fileIndex.setSuffix(suffix); } - fileIndex.setFileSize(file.getSize()); + fileIndex.setFileSize(multipartFile.getSize()); FileType fileType = parseType(suffix); if (GeneralUtils.isEmpty(fileIndex.getIsSlice())) { fileIndex.setIsSlice(false); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 64e13a2..190951d 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -45,7 +45,8 @@ public class FileHandleServiceImpl implements FileHandleService { @Override public void autographImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); InputStream inputStream = fileIndex.inputStream(); BufferedImage bufferedImage = ImageUtils.read(inputStream); BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); @@ -60,14 +61,15 @@ public void autographImage(FileIndex fileIndex) throws RestException { byte[] bytes = ImageUtils.bytes(file); fileIndex.setBytes(bytes); FileUtils.delete(filePath); - FileUtils.clear(randomPath); + FileUtils.clear(cachePath); } @Async @Override public void condenseImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); Long imageFileSize; Double imageFileQuality = 1.0d; Double imageFileScale = 1.0d; @@ -122,14 +124,15 @@ public void condenseImage(FileIndex fileIndex) throws RestException { FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); FileServiceHelper.buildMd5(file, fileIndex); FileUtils.clearFile(randomPath); - FileUtils.clear(randomPath); + FileUtils.clear(cachePath); } @Async @Override public void condenseFile(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); String filename = fileIndex.getName(); String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); @@ -140,6 +143,6 @@ public void condenseFile(FileIndex fileIndex) throws RestException { if (fileIndex.getIsMd5()) { FileServiceHelper.buildMd5(zipFile, fileIndex); } - FileUtils.clear(randomPath); + FileUtils.clear(cachePath); } } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index bab0aa8..2a34d8e 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -304,10 +304,6 @@ public FileIndex upload(FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { throw new RestException(FileErrorStatus.FILE_INDEX_IS_NULL); } - if (GeneralUtils.isEmpty(fileIndex.getId())) { - String fileId = IdentityUtils.generateString(); - fileIndex.setId(fileId); - } fileUploadService.uploadFileIndex(fileIndex); checkFileIndex(fileIndex); return fileIndex; diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java index 4b6fc98..5d7306f 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java @@ -6,8 +6,6 @@ import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.service.*; import io.github.nichetoolkit.rest.RestException; -import io.github.nichetoolkit.rest.util.FileUtils; -import io.github.nichetoolkit.rest.util.GeneralUtils; import io.github.nichetoolkit.rice.RestId; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; From 142b2afb1ea2ad42c54a0dfdde5ca6ce96b987e8 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 12:01:30 +0800 Subject: [PATCH 10/30] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/service/impl/FileHandleServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 190951d..3b0fc64 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -61,6 +61,7 @@ public void autographImage(FileIndex fileIndex) throws RestException { byte[] bytes = ImageUtils.bytes(file); fileIndex.setBytes(bytes); FileUtils.delete(filePath); + FileUtils.clear(randomPath); FileUtils.clear(cachePath); } @@ -123,7 +124,8 @@ public void condenseImage(FileIndex fileIndex) throws RestException { fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); FileServiceHelper.buildMd5(file, fileIndex); - FileUtils.clearFile(randomPath); + FileUtils.delete(filePath); + FileUtils.clear(randomPath); FileUtils.clear(cachePath); } @@ -143,6 +145,8 @@ public void condenseFile(FileIndex fileIndex) throws RestException { if (fileIndex.getIsMd5()) { FileServiceHelper.buildMd5(zipFile, fileIndex); } + FileUtils.delete(filePath); + FileUtils.clear(randomPath); FileUtils.clear(cachePath); } } From 2a6f103c000a7b1289645b2fbe1cdfe166da15a3 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 13:04:03 +0800 Subject: [PATCH 11/30] fix --- .../service/impl/FileHandleServiceImpl.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 3b0fc64..be3e3b7 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -47,21 +47,25 @@ public void autographImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); - InputStream inputStream = fileIndex.inputStream(); - BufferedImage bufferedImage = ImageUtils.read(inputStream); - BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); - BufferedImage autographImage = ImageUtils.autograph(binaryImage); String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); File file = new File(filePath); if (file.exists()) { FileUtils.delete(filePath); } - ImageUtils.write(autographImage, file); + try(InputStream inputStream = fileIndex.inputStream()) { + BufferedImage bufferedImage = ImageUtils.read(inputStream); + BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); + BufferedImage autographImage = ImageUtils.autograph(binaryImage); + ImageUtils.write(autographImage, file); + } catch (IOException exception) { + log.error("the image file has error during autograph: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); + } byte[] bytes = ImageUtils.bytes(file); fileIndex.setBytes(bytes); FileUtils.delete(filePath); - FileUtils.clear(randomPath); + FileUtils.clearFile(randomPath); FileUtils.clear(cachePath); } @@ -85,22 +89,22 @@ public void condenseImage(FileIndex fileIndex) throws RestException { if (file.exists()) { FileUtils.delete(filePath); } - try { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + try(InputStream inputStream = fileIndex.inputStream()) { + Thumbnails.of(inputStream).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); BufferedImage bufferedImage = ImageHelper.read(file); int imageWidth = bufferedImage.getWidth(); int imageHeight = bufferedImage.getHeight(); if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + Thumbnails.of(inputStream).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { if (GeneralUtils.isNotEmpty(width)) { imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); } else { imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); } - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + Thumbnails.of(inputStream).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } else { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + Thumbnails.of(inputStream).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } } catch (IOException exception) { log.error("the image file has error during condensing: {}", exception.getMessage()); @@ -125,7 +129,7 @@ public void condenseImage(FileIndex fileIndex) throws RestException { FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); FileServiceHelper.buildMd5(file, fileIndex); FileUtils.delete(filePath); - FileUtils.clear(randomPath); + FileUtils.clearFile(randomPath); FileUtils.clear(cachePath); } @@ -139,14 +143,19 @@ public void condenseFile(FileIndex fileIndex) throws RestException { String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); File file = FileUtils.createFile(filePath); - StreamUtils.write(file, fileIndex.inputStream()); + try(InputStream inputStream = fileIndex.inputStream()) { + StreamUtils.write(file, inputStream); + } catch (IOException exception) { + log.error("the file has error during autograph: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.FILE_CONDENSE_ERROR); + } File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); FileServiceHelper.buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); if (fileIndex.getIsMd5()) { FileServiceHelper.buildMd5(zipFile, fileIndex); } FileUtils.delete(filePath); - FileUtils.clear(randomPath); + FileUtils.clearFile(randomPath); FileUtils.clear(cachePath); } } From 212ada102586d8a92a1aa99a07ad757e18c2bfe5 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 13:21:46 +0800 Subject: [PATCH 12/30] fix --- .../java/io/github/nichetoolkit/file/model/FileIndex.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index e6f15e3..8c44918 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -17,6 +17,7 @@ import lombok.EqualsAndHashCode; import okhttp3.Headers; import org.springframework.lang.NonNull; +import org.springframework.util.StreamUtils; import org.springframework.web.multipart.MultipartFile; import java.io.*; @@ -124,7 +125,8 @@ public InputStream inputStream() { return new ByteArrayInputStream(this.bytes); } else if (GeneralUtils.isNotEmpty(this.file)) { try { - return new FileInputStream(this.file); + this.bytes = StreamUtils.copyToByteArray(new FileInputStream(file)); + return new ByteArrayInputStream(this.bytes) ; } catch (IOException ignored) { } } From dd02f97e5603aa6407641cf62f33f7fb658b8680 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 13:48:14 +0800 Subject: [PATCH 13/30] fix --- .../service/impl/FileHandleServiceImpl.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index be3e3b7..580ce28 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -47,21 +47,17 @@ public void autographImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + InputStream inputStream = fileIndex.inputStream(); + BufferedImage bufferedImage = ImageUtils.read(inputStream); + BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); + BufferedImage autographImage = ImageUtils.autograph(binaryImage); String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); File file = new File(filePath); if (file.exists()) { FileUtils.delete(filePath); } - try(InputStream inputStream = fileIndex.inputStream()) { - BufferedImage bufferedImage = ImageUtils.read(inputStream); - BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); - BufferedImage autographImage = ImageUtils.autograph(binaryImage); - ImageUtils.write(autographImage, file); - } catch (IOException exception) { - log.error("the image file has error during autograph: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); - } + ImageUtils.write(autographImage, file); byte[] bytes = ImageUtils.bytes(file); fileIndex.setBytes(bytes); FileUtils.delete(filePath); @@ -143,12 +139,8 @@ public void condenseFile(FileIndex fileIndex) throws RestException { String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); File file = FileUtils.createFile(filePath); - try(InputStream inputStream = fileIndex.inputStream()) { - StreamUtils.write(file, inputStream); - } catch (IOException exception) { - log.error("the file has error during autograph: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.FILE_CONDENSE_ERROR); - } + InputStream inputStream = fileIndex.inputStream(); + StreamUtils.write(file, inputStream); File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); FileServiceHelper.buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); if (fileIndex.getIsMd5()) { From dd7f8fce530a3bafa28eb80a728aa205317991d5 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 14:06:19 +0800 Subject: [PATCH 14/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/service/impl/FileHandleServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 580ce28..22e3fa2 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -85,7 +85,8 @@ public void condenseImage(FileIndex fileIndex) throws RestException { if (file.exists()) { FileUtils.delete(filePath); } - try(InputStream inputStream = fileIndex.inputStream()) { + try{ + InputStream inputStream = fileIndex.inputStream(); Thumbnails.of(inputStream).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); BufferedImage bufferedImage = ImageHelper.read(file); int imageWidth = bufferedImage.getWidth(); From 11c8dfc483b5ec8945ba499fcf90677b0c7e0bab Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 14:12:55 +0800 Subject: [PATCH 15/30] =?UTF-8?q?=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/model/FileIndex.java | 4 +--- .../service/impl/FileHandleServiceImpl.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index 8c44918..e6f15e3 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -17,7 +17,6 @@ import lombok.EqualsAndHashCode; import okhttp3.Headers; import org.springframework.lang.NonNull; -import org.springframework.util.StreamUtils; import org.springframework.web.multipart.MultipartFile; import java.io.*; @@ -125,8 +124,7 @@ public InputStream inputStream() { return new ByteArrayInputStream(this.bytes); } else if (GeneralUtils.isNotEmpty(this.file)) { try { - this.bytes = StreamUtils.copyToByteArray(new FileInputStream(file)); - return new ByteArrayInputStream(this.bytes) ; + return new FileInputStream(this.file); } catch (IOException ignored) { } } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 22e3fa2..3b0fc64 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -61,7 +61,7 @@ public void autographImage(FileIndex fileIndex) throws RestException { byte[] bytes = ImageUtils.bytes(file); fileIndex.setBytes(bytes); FileUtils.delete(filePath); - FileUtils.clearFile(randomPath); + FileUtils.clear(randomPath); FileUtils.clear(cachePath); } @@ -85,23 +85,22 @@ public void condenseImage(FileIndex fileIndex) throws RestException { if (file.exists()) { FileUtils.delete(filePath); } - try{ - InputStream inputStream = fileIndex.inputStream(); - Thumbnails.of(inputStream).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + try { + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); BufferedImage bufferedImage = ImageHelper.read(file); int imageWidth = bufferedImage.getWidth(); int imageHeight = bufferedImage.getHeight(); if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - Thumbnails.of(inputStream).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { if (GeneralUtils.isNotEmpty(width)) { imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); } else { imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); } - Thumbnails.of(inputStream).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } else { - Thumbnails.of(inputStream).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); } } catch (IOException exception) { log.error("the image file has error during condensing: {}", exception.getMessage()); @@ -126,7 +125,7 @@ public void condenseImage(FileIndex fileIndex) throws RestException { FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); FileServiceHelper.buildMd5(file, fileIndex); FileUtils.delete(filePath); - FileUtils.clearFile(randomPath); + FileUtils.clear(randomPath); FileUtils.clear(cachePath); } @@ -140,15 +139,14 @@ public void condenseFile(FileIndex fileIndex) throws RestException { String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); File file = FileUtils.createFile(filePath); - InputStream inputStream = fileIndex.inputStream(); - StreamUtils.write(file, inputStream); + StreamUtils.write(file, fileIndex.inputStream()); File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); FileServiceHelper.buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); if (fileIndex.getIsMd5()) { FileServiceHelper.buildMd5(zipFile, fileIndex); } FileUtils.delete(filePath); - FileUtils.clearFile(randomPath); + FileUtils.clear(randomPath); FileUtils.clear(cachePath); } } From df25040cd68e6716a65859fc1b028687f952f1ae Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 14:27:20 +0800 Subject: [PATCH 16/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/model/FileIndex.java | 8 ------ .../file/helper/FileServiceHelper.java | 28 ++++++++++--------- .../service/impl/FileHandleServiceImpl.java | 12 ++------ 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index e6f15e3..777621e 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -108,9 +108,6 @@ public class FileIndex extends RiceInfoModel { @JsonIgnore protected byte[] bytes; - @JsonIgnore - protected File file; - public FileIndex() { } @@ -122,11 +119,6 @@ public FileIndex(String id) { public InputStream inputStream() { if (GeneralUtils.isNotEmpty(this.bytes)) { return new ByteArrayInputStream(this.bytes); - } else if (GeneralUtils.isNotEmpty(this.file)) { - try { - return new FileInputStream(this.file); - } catch (IOException ignored) { - } } return null; } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index daf31b4..5631175 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -5,7 +5,6 @@ import io.github.nichetoolkit.file.entity.FileIndexEntity; import io.github.nichetoolkit.file.enums.FileType; import io.github.nichetoolkit.file.error.FileErrorStatus; -import io.github.nichetoolkit.file.error.ImageTransferException; import io.github.nichetoolkit.file.filter.FileFilter; import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; @@ -13,16 +12,17 @@ import io.github.nichetoolkit.file.service.AsyncFileService; import io.github.nichetoolkit.file.service.FileChunkService; import io.github.nichetoolkit.file.service.FileIndexService; -import io.github.nichetoolkit.file.util.ImageUtils; import io.github.nichetoolkit.file.util.Md5Utils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; import io.github.nichetoolkit.rest.identity.IdentityUtils; -import io.github.nichetoolkit.rest.util.*; +import io.github.nichetoolkit.rest.util.ContextUtils; +import io.github.nichetoolkit.rest.util.FileUtils; +import io.github.nichetoolkit.rest.util.GeneralUtils; +import io.github.nichetoolkit.rest.util.StreamUtils; import io.github.nichetoolkit.rice.RestPage; import io.github.nichetoolkit.rice.helper.PropertyHelper; import lombok.extern.slf4j.Slf4j; -import net.coobird.thumbnailator.Thumbnails; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -31,10 +31,10 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.PostConstruct; -import javax.naming.NamingEnumeration; -import javax.swing.*; -import java.awt.image.BufferedImage; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; @@ -361,10 +361,12 @@ public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex f } String originalFilename = multipartFile.getOriginalFilename(); fileIndex.setName(originalFilename); - String tempPath = FileUtils.createPath(INSTANCE.commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - File file = FileUtils.cacheFile(cachePath, multipartFile); - fileIndex.setFile(file); + try { + byte[] bytes = StreamUtils.bytes(multipartFile.getInputStream()); + fileIndex.setBytes(bytes); + } catch (IOException ignored) { + } + String filename = FileUtils.filename(originalFilename); if (GeneralUtils.isEmpty(fileIndex.getFilename())) { fileIndex.setFilename(filename); @@ -400,7 +402,7 @@ public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex f fileIndex.setSliceSize(0); } if (fileIndex.getIsMd5()) { - buildMd5(file, fileIndex); + buildMd5(fileIndex.getBytes(), fileIndex); } fileIndex.setCreateTime(new Date()); return fileIndex; diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 3b0fc64..29c64e3 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -45,8 +45,7 @@ public class FileHandleServiceImpl implements FileHandleService { @Override public void autographImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); InputStream inputStream = fileIndex.inputStream(); BufferedImage bufferedImage = ImageUtils.read(inputStream); BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); @@ -62,15 +61,13 @@ public void autographImage(FileIndex fileIndex) throws RestException { fileIndex.setBytes(bytes); FileUtils.delete(filePath); FileUtils.clear(randomPath); - FileUtils.clear(cachePath); } @Async @Override public void condenseImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); Long imageFileSize; Double imageFileQuality = 1.0d; Double imageFileScale = 1.0d; @@ -126,15 +123,13 @@ public void condenseImage(FileIndex fileIndex) throws RestException { FileServiceHelper.buildMd5(file, fileIndex); FileUtils.delete(filePath); FileUtils.clear(randomPath); - FileUtils.clear(cachePath); } @Async @Override public void condenseFile(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); String filename = fileIndex.getName(); String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); @@ -147,6 +142,5 @@ public void condenseFile(FileIndex fileIndex) throws RestException { } FileUtils.delete(filePath); FileUtils.clear(randomPath); - FileUtils.clear(cachePath); } } From b73dd7ccacccac0cb2d307b641a681822daffc8e Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 14:34:42 +0800 Subject: [PATCH 17/30] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/model/FileIndex.java | 8 ++++++ .../file/helper/FileServiceHelper.java | 28 +++++++++---------- .../service/impl/FileHandleServiceImpl.java | 12 ++++++-- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index 777621e..26272eb 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -108,6 +108,9 @@ public class FileIndex extends RiceInfoModel { @JsonIgnore protected byte[] bytes; + @JsonIgnore + protected String file; + public FileIndex() { } @@ -119,6 +122,11 @@ public FileIndex(String id) { public InputStream inputStream() { if (GeneralUtils.isNotEmpty(this.bytes)) { return new ByteArrayInputStream(this.bytes); + } else if (GeneralUtils.isNotEmpty(this.file)) { + try { + return new FileInputStream(new File(this.file)); + } catch (IOException ignored) { + } } return null; } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index 5631175..d018174 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -5,6 +5,7 @@ import io.github.nichetoolkit.file.entity.FileIndexEntity; import io.github.nichetoolkit.file.enums.FileType; import io.github.nichetoolkit.file.error.FileErrorStatus; +import io.github.nichetoolkit.file.error.ImageTransferException; import io.github.nichetoolkit.file.filter.FileFilter; import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; @@ -12,17 +13,16 @@ import io.github.nichetoolkit.file.service.AsyncFileService; import io.github.nichetoolkit.file.service.FileChunkService; import io.github.nichetoolkit.file.service.FileIndexService; +import io.github.nichetoolkit.file.util.ImageUtils; import io.github.nichetoolkit.file.util.Md5Utils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; import io.github.nichetoolkit.rest.identity.IdentityUtils; -import io.github.nichetoolkit.rest.util.ContextUtils; -import io.github.nichetoolkit.rest.util.FileUtils; -import io.github.nichetoolkit.rest.util.GeneralUtils; -import io.github.nichetoolkit.rest.util.StreamUtils; +import io.github.nichetoolkit.rest.util.*; import io.github.nichetoolkit.rice.RestPage; import io.github.nichetoolkit.rice.helper.PropertyHelper; import lombok.extern.slf4j.Slf4j; +import net.coobird.thumbnailator.Thumbnails; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -31,10 +31,10 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.PostConstruct; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; +import javax.naming.NamingEnumeration; +import javax.swing.*; +import java.awt.image.BufferedImage; +import java.io.*; import java.util.*; import java.util.stream.Collectors; @@ -361,12 +361,10 @@ public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex f } String originalFilename = multipartFile.getOriginalFilename(); fileIndex.setName(originalFilename); - try { - byte[] bytes = StreamUtils.bytes(multipartFile.getInputStream()); - fileIndex.setBytes(bytes); - } catch (IOException ignored) { - } - + String tempPath = FileUtils.createPath(INSTANCE.commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + File file = FileUtils.cacheFile(cachePath, multipartFile); + fileIndex.setFile(file.getPath()); String filename = FileUtils.filename(originalFilename); if (GeneralUtils.isEmpty(fileIndex.getFilename())) { fileIndex.setFilename(filename); @@ -402,7 +400,7 @@ public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex f fileIndex.setSliceSize(0); } if (fileIndex.getIsMd5()) { - buildMd5(fileIndex.getBytes(), fileIndex); + buildMd5(file, fileIndex); } fileIndex.setCreateTime(new Date()); return fileIndex; diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 29c64e3..3b0fc64 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -45,7 +45,8 @@ public class FileHandleServiceImpl implements FileHandleService { @Override public void autographImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); InputStream inputStream = fileIndex.inputStream(); BufferedImage bufferedImage = ImageUtils.read(inputStream); BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); @@ -61,13 +62,15 @@ public void autographImage(FileIndex fileIndex) throws RestException { fileIndex.setBytes(bytes); FileUtils.delete(filePath); FileUtils.clear(randomPath); + FileUtils.clear(cachePath); } @Async @Override public void condenseImage(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); Long imageFileSize; Double imageFileQuality = 1.0d; Double imageFileScale = 1.0d; @@ -123,13 +126,15 @@ public void condenseImage(FileIndex fileIndex) throws RestException { FileServiceHelper.buildMd5(file, fileIndex); FileUtils.delete(filePath); FileUtils.clear(randomPath); + FileUtils.clear(cachePath); } @Async @Override public void condenseFile(FileIndex fileIndex) throws RestException { String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); String filename = fileIndex.getName(); String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); String filePath = randomPath.concat(File.separator).concat(filename); @@ -142,5 +147,6 @@ public void condenseFile(FileIndex fileIndex) throws RestException { } FileUtils.delete(filePath); FileUtils.clear(randomPath); + FileUtils.clear(cachePath); } } From ee650d9711dcdf96af1a91097b22ac81ef26e768 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 14:45:33 +0800 Subject: [PATCH 18/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/model/FileIndex.java | 8 +- .../file/helper/FileServiceHelper.java | 116 ++++++++++--- .../file/service/FileService.java | 132 --------------- .../file/service/FileUploadService.java | 20 --- .../service/impl/FileHandleServiceImpl.java | 152 ------------------ .../file/service/impl/FileServiceImpl.java | 44 +++-- .../service/impl/FileUploadServiceImpl.java | 76 --------- 7 files changed, 136 insertions(+), 412 deletions(-) delete mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java delete mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java delete mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java delete mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index 26272eb..75a3434 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -19,7 +19,9 @@ import org.springframework.lang.NonNull; import org.springframework.web.multipart.MultipartFile; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -109,7 +111,7 @@ public class FileIndex extends RiceInfoModel { protected byte[] bytes; @JsonIgnore - protected String file; + protected MultipartFile file; public FileIndex() { } @@ -124,7 +126,7 @@ public InputStream inputStream() { return new ByteArrayInputStream(this.bytes); } else if (GeneralUtils.isNotEmpty(this.file)) { try { - return new FileInputStream(new File(this.file)); + return this.file.getInputStream(); } catch (IOException ignored) { } } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index d018174..4156a70 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -17,7 +17,6 @@ import io.github.nichetoolkit.file.util.Md5Utils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; -import io.github.nichetoolkit.rest.identity.IdentityUtils; import io.github.nichetoolkit.rest.util.*; import io.github.nichetoolkit.rice.RestPage; import io.github.nichetoolkit.rice.helper.PropertyHelper; @@ -48,7 +47,7 @@ public class FileServiceHelper implements InitializingBean { @Autowired - private FileCommonProperties commonProperties; + private FileCommonProperties serviceProperties; @Autowired private FileIndexService fileIndexService; @@ -81,6 +80,94 @@ public static void checkRestPage(RestPage restPage) throws RestException { } } + public static void condenseFile(String randomPath, FileIndex fileIndex) throws RestException { + String filename = fileIndex.getName(); + String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = FileUtils.createFile(filePath); + StreamUtils.write(file, fileIndex.inputStream()); + File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); + buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); + if (fileIndex.getIsMd5()) { + buildMd5(zipFile, fileIndex); + } + } + + public static void autographImage(String randomPath, FileIndex fileIndex) throws RestException { + InputStream inputStream = fileIndex.inputStream(); + BufferedImage bufferedImage = ImageUtils.read(inputStream); + BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); + BufferedImage autographImage = ImageUtils.autograph(binaryImage); + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = new File(filePath); + if (file.exists()) { + FileUtils.delete(filePath); + } + ImageUtils.write(autographImage, file); + byte[] bytes = ImageUtils.bytes(file); + fileIndex.setBytes(bytes); + FileUtils.delete(filePath); + } + + public static void condenseImage(String randomPath, FileIndex fileIndex) throws RestException { + Long imageFileSize; + Double imageFileQuality = 1.0d; + Double imageFileScale = 1.0d; + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath; + File file; + Integer width = fileIndex.getWidth(); + Integer height = fileIndex.getHeight(); + filePath = randomPath.concat(File.separator).concat(filename); + file = new File(filePath); + do { + if (file.exists()) { + FileUtils.delete(filePath); + } + try { + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + BufferedImage bufferedImage = ImageHelper.read(file); + int imageWidth = bufferedImage.getWidth(); + int imageHeight = bufferedImage.getHeight(); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { + if (GeneralUtils.isNotEmpty(width)) { + imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); + } else { + imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); + } + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else { + imageFileQuality = INSTANCE.serviceProperties.getMinImageQuality(); + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } + } catch (IOException exception) { + log.error("the image file has error during condensing: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); + } + imageFileSize = file.length(); + if (imageFileQuality.equals(INSTANCE.serviceProperties.getMinImageQuality())) { + imageFileScale += -0.1d; + } else { + imageFileQuality += -0.1d; + } + } while (imageFileSize > INSTANCE.serviceProperties.getMaxImageSize() + && imageFileQuality > INSTANCE.serviceProperties.getMinImageQuality() + && imageFileScale > INSTANCE.serviceProperties.getMinImageScale()); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); + } else { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); + } + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); + buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); + buildMd5(file, fileIndex); + FileUtils.clearFile(randomPath); + } + public static void buildProperties(String filename, long size, String suffix, FileIndex fileIndex) { fileIndex.addProperty(FileConstants.ORIGINAL_SUFFIX_PROPERTY, fileIndex.getSuffix()); fileIndex.setSuffix(suffix); @@ -110,7 +197,7 @@ public static void buildChunkFiles(List fileIndices, FileFilter fileF public static void buildIndexFiles(List fileIndices, FileFilter fileFilter, String randomPath, List fileList) throws RestException { for (FileIndex fileIndex : fileIndices) { - if (fileIndex.getFileSize() > INSTANCE.commonProperties.getMaxFileSize()) { + if (fileIndex.getFileSize() > INSTANCE.serviceProperties.getMaxFileSize()) { log.warn("the file size is too large, id: {}, size: {}", fileIndex.getId(), fileIndex.getFileSize()); throw new FileErrorException(FileErrorStatus.FILE_TOO_LARGE_ERROR); } @@ -241,7 +328,7 @@ public static void buildMd5(byte[] bytes, FileChunk fileChunk) throws RestExcept fileChunk.setChunkMd5(md5); } - public static FileIndex createFileChunk(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { + public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { log.warn("the file index is null!"); throw new FileErrorException(FileErrorStatus.FILE_INDEX_IS_NULL); @@ -273,8 +360,8 @@ public static FileIndex createFileChunk(MultipartFile multipartFile, FileIndex f } Long chunkSize = fileChunk.getChunkSize(); if (GeneralUtils.isEmpty(chunkSize)) { - chunkSize = multipartFile.getSize(); - fileChunk.setChunkSize(multipartFile.getSize()); + chunkSize = file.getSize(); + fileChunk.setChunkSize(file.getSize()); } Long chunkStart = fileChunk.getChunkStart(); if (chunkStart == null) { @@ -290,7 +377,7 @@ public static FileIndex createFileChunk(MultipartFile multipartFile, FileIndex f log.error("the param of 'chunkEnd' or 'chunkStart' or 'chunkSize' for file chunk is invalid! "); throw new FileErrorException(FileErrorStatus.FILE_CHUNK_PARAM_INVALID); } - buildMd5(multipartFile, fileChunk); + buildMd5(file, fileChunk); fileChunk.setChunkTime(new Date()); if (fileChunk.getChunkIndex() == 1) { @@ -351,20 +438,13 @@ public static FileIndex createFileChunk(FileRequest fileRequest, String contentR return fileIndex; } - public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { + public static FileIndex createFileIndex(MultipartFile file, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { fileIndex = new FileIndex(); } - if (GeneralUtils.isEmpty(fileIndex.getId())) { - String fileId = IdentityUtils.generateString(); - fileIndex.setId(fileId); - } - String originalFilename = multipartFile.getOriginalFilename(); + String originalFilename = file.getOriginalFilename(); fileIndex.setName(originalFilename); - String tempPath = FileUtils.createPath(INSTANCE.commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - File file = FileUtils.cacheFile(cachePath, multipartFile); - fileIndex.setFile(file.getPath()); + fileIndex.setFile(file); String filename = FileUtils.filename(originalFilename); if (GeneralUtils.isEmpty(fileIndex.getFilename())) { fileIndex.setFilename(filename); @@ -376,7 +456,7 @@ public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex f if (GeneralUtils.isEmpty(fileIndex.getSuffix())) { fileIndex.setSuffix(suffix); } - fileIndex.setFileSize(multipartFile.getSize()); + fileIndex.setFileSize(file.getSize()); FileType fileType = parseType(suffix); if (GeneralUtils.isEmpty(fileIndex.getIsSlice())) { fileIndex.setIsSlice(false); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java deleted file mode 100644 index f3d1c70..0000000 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java +++ /dev/null @@ -1,132 +0,0 @@ -package io.github.nichetoolkit.file.service; - -import io.github.nichetoolkit.file.enums.FileType; -import io.github.nichetoolkit.file.filter.FileFilter; -import io.github.nichetoolkit.file.model.FileIndex; -import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.rest.RestException; -import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.util.concurrent.Future; - -/** - *

FileService

- * @author Cyan (snow22314@outlook.com) - * @version v1.0.0 - */ -public interface FileService { - - /** - * 文件移除 - * @param fileFilter 过滤器删除 - * @throws RestException 服务异常 - */ - void remove(FileFilter fileFilter) throws RestException; - - /** - * 文件移除 - * @param fileId 文件id - * @param chunk 是否是分片 - * @param delete 是否真实删除 - * @param rename 是否重命名删除 - * @throws RestException 服务异常 - */ - void remove(String fileId, Boolean chunk, Boolean delete, Boolean rename) throws RestException; - - /** - * 下载文件 - * @param file 文件数据 - * @param filename 文件名称 - * @param contentType contentType - * @param response 返回体 - * @throws RestException 服务异常 - */ - void download(File file, String filename, String contentType, HttpServletRequest request, HttpServletResponse response) throws RestException; - - /** - * 下载文件 - * @param fileIndex 文件id - * @param filename 文件名称 - * @param contentType contentType - * @param response 返回体 - * @throws RestException 服务异常 - */ - void download(FileIndex fileIndex, String filename, String contentType, Boolean preview, FileType fileType, HttpServletRequest request, HttpServletResponse response) throws RestException; - - /** - * @param fileIndex 文件id - * @param filename 文件名称 - * @param preview 是否预览图片 - * @param response 返回体 - * @throws RestException 服务异常 - */ - void download(FileIndex fileIndex, String filename, Boolean preview, FileType fileType, HttpServletRequest request, HttpServletResponse response) throws RestException; - - /** - * 下载多文件 - * @param fileFilter 查询过滤器 - * @param response 返回体 - * @throws RestException 服务异常 - */ - void download(FileFilter fileFilter, HttpServletRequest request, HttpServletResponse response) throws RestException; - - /** - * 下载文件 - * @param fileId 文件id - * @param chunk 是否下载分片文件 - * @param preview 是否预览图片 - * @param original 是否原始命名 - * @param response 返回体 - * @throws RestException 服务异常 - */ - void fileDownload(String fileId, Boolean chunk, Boolean preview, Boolean original, HttpServletRequest request, HttpServletResponse response) throws RestException; - - /** - * 下载图片 - * @param fileId 文件id - * @param preview 是否预览图片 - * @param original 是否原始命名 - * @param response 返回体 - * @throws RestException 服务异常 - */ - void imageDownload(String fileId, Boolean preview, Boolean original, HttpServletRequest request, HttpServletResponse response) throws RestException; - - /** - * 上传文件 - * @param file 文件数据 - * @param fileRequest 文件信息 - * @return FileIndex - * @throws RestException 服务异常 - */ - FileIndex upload(MultipartFile file, FileRequest fileRequest) throws RestException; - - /** - * 上传文件 - * @param fileIndex 文件信息 - * @return FileIndex - * @throws RestException 服务异常 - */ - FileIndex upload(FileIndex fileIndex) throws RestException; - - /** - * 预分片上传文件 - * @param fileIndex 文件信息 - * @return FileIndex - * @throws RestException 服务异常 - */ - FileIndex indexUpload(FileIndex fileIndex) throws RestException; - - /** - * 分片上传 - * @param file 分片文件数据 - * @param contentRange 分片header - * @param fileRequest 文件信息 - * @return FileIndex - * @throws RestException 服务异常 - */ - FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException; - -} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java deleted file mode 100644 index 6f1c2e7..0000000 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileUploadService.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.nichetoolkit.file.service; - -import io.github.nichetoolkit.file.model.FileIndex; -import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.rest.RestException; -import org.springframework.web.multipart.MultipartFile; - -/** - *

FileUploadService

- * @author Cyan (snow22314@outlook.com) - * @version v1.0.0 - */ -public interface FileUploadService { - - void uploadFileIndex(FileIndex fileIndex) throws RestException; - - void uploadChunk(FileIndex fileIndex) throws RestException; - - void lastChunk(FileIndex fileIndex) throws RestException; -} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java deleted file mode 100644 index 3b0fc64..0000000 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ /dev/null @@ -1,152 +0,0 @@ -package io.github.nichetoolkit.file.service.impl; - -import io.github.nichetoolkit.file.configure.FileCommonProperties; -import io.github.nichetoolkit.file.constant.FileConstants; -import io.github.nichetoolkit.file.enums.FileType; -import io.github.nichetoolkit.file.error.FileErrorStatus; -import io.github.nichetoolkit.file.helper.FileServiceHelper; -import io.github.nichetoolkit.file.helper.ImageHelper; -import io.github.nichetoolkit.file.model.FileIndex; -import io.github.nichetoolkit.file.service.FileHandleService; -import io.github.nichetoolkit.file.util.ImageUtils; -import io.github.nichetoolkit.rest.RestException; -import io.github.nichetoolkit.rest.error.natives.FileErrorException; -import io.github.nichetoolkit.rest.identity.IdentityUtils; -import io.github.nichetoolkit.rest.util.FileUtils; -import io.github.nichetoolkit.rest.util.GeneralUtils; -import io.github.nichetoolkit.rest.util.StreamUtils; -import io.github.nichetoolkit.rest.util.ZipUtils; -import lombok.extern.slf4j.Slf4j; -import net.coobird.thumbnailator.Thumbnails; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -/** - *

FileHandleServiceImpl

- * @author Cyan (snow22314@outlook.com) - * @version v1.0.0 - */ -@Slf4j -@Service -public class FileHandleServiceImpl implements FileHandleService { - - @Autowired - protected FileCommonProperties commonProperties; - @Autowired - private FileCommonProperties serviceProperties; - - @Async - @Override - public void autographImage(FileIndex fileIndex) throws RestException { - String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); - InputStream inputStream = fileIndex.inputStream(); - BufferedImage bufferedImage = ImageUtils.read(inputStream); - BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); - BufferedImage autographImage = ImageUtils.autograph(binaryImage); - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = new File(filePath); - if (file.exists()) { - FileUtils.delete(filePath); - } - ImageUtils.write(autographImage, file); - byte[] bytes = ImageUtils.bytes(file); - fileIndex.setBytes(bytes); - FileUtils.delete(filePath); - FileUtils.clear(randomPath); - FileUtils.clear(cachePath); - } - - @Async - @Override - public void condenseImage(FileIndex fileIndex) throws RestException { - String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); - Long imageFileSize; - Double imageFileQuality = 1.0d; - Double imageFileScale = 1.0d; - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath; - File file; - Integer width = fileIndex.getWidth(); - Integer height = fileIndex.getHeight(); - filePath = randomPath.concat(File.separator).concat(filename); - file = new File(filePath); - do { - if (file.exists()) { - FileUtils.delete(filePath); - } - try { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - BufferedImage bufferedImage = ImageHelper.read(file); - int imageWidth = bufferedImage.getWidth(); - int imageHeight = bufferedImage.getHeight(); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { - if (GeneralUtils.isNotEmpty(width)) { - imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); - } else { - imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); - } - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } - } catch (IOException exception) { - log.error("the image file has error during condensing: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); - } - imageFileSize = file.length(); - if (imageFileQuality.equals(serviceProperties.getMinImageQuality())) { - imageFileScale += -0.1d; - } else { - imageFileQuality += -0.1d; - } - } while (imageFileSize > serviceProperties.getMaxImageSize() - && imageFileQuality > serviceProperties.getMinImageQuality() - && imageFileScale > serviceProperties.getMinImageScale()); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); - } else { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); - } - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); - FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); - FileServiceHelper.buildMd5(file, fileIndex); - FileUtils.delete(filePath); - FileUtils.clear(randomPath); - FileUtils.clear(cachePath); - } - - @Async - @Override - public void condenseFile(FileIndex fileIndex) throws RestException { - String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); - String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); - String filename = fileIndex.getName(); - String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = FileUtils.createFile(filePath); - StreamUtils.write(file, fileIndex.inputStream()); - File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); - FileServiceHelper.buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); - if (fileIndex.getIsMd5()) { - FileServiceHelper.buildMd5(zipFile, fileIndex); - } - FileUtils.delete(filePath); - FileUtils.clear(randomPath); - FileUtils.clear(cachePath); - } -} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index 2a34d8e..1a4d747 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -9,7 +9,9 @@ import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.file.service.*; +import io.github.nichetoolkit.file.service.AsyncFileService; +import io.github.nichetoolkit.file.service.FileChunkService; +import io.github.nichetoolkit.file.service.FileIndexService; import io.github.nichetoolkit.file.video.VideoHttpRequestHandler; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; @@ -59,9 +61,6 @@ public class FileServiceImpl implements FileService { @Autowired protected FileChunkService fileChunkService; - @Autowired - protected FileUploadService fileUploadService; - @Autowired protected AsyncFileService asyncFileService; @@ -304,9 +303,28 @@ public FileIndex upload(FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { throw new RestException(FileErrorStatus.FILE_INDEX_IS_NULL); } - fileUploadService.uploadFileIndex(fileIndex); + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); + + if (fileIndex.getIsAutograph() != null && fileIndex.getIsAutograph() && fileIndex.getFileType() == FileType.IMAGE) { + FileServiceHelper.autographImage(randomPath, fileIndex); + } + if (fileIndex.getIsCondense()) { + if (fileIndex.getFileType() == FileType.IMAGE) { + FileServiceHelper.condenseImage(randomPath, fileIndex); + } else { + FileServiceHelper.condenseFile(randomPath, fileIndex); + } + } + String fileId = fileIndex.getId(); + if (GeneralUtils.isEmpty(fileIndex.getId())) { + fileId = IdentityUtils.generateString(); + fileIndex.setId(fileId); + } + asyncFileService.putById(fileId, fileIndex.inputStream()); + FileUtils.clear(randomPath); checkFileIndex(fileIndex); - return fileIndex; + return fileIndexService.save(fileIndex); } @Override @@ -322,23 +340,27 @@ public FileIndex indexUpload(FileIndex fileIndex) throws RestException { } @Override - public FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { + @Async + public Future chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { FileIndex fileChunkIndex = FileServiceHelper.createFileChunk(fileRequest, contentRange); FileIndex fileIndex = FileServiceHelper.createFileChunk(file, fileChunkIndex); - fileUploadService.uploadChunk(fileIndex); + FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); + asyncFileService.putById(uploadChunk.getId(), uploadChunk.inputStream()); + fileIndex.setFileChunk(uploadChunk); if (GeneralUtils.isEmpty(fileIndex.getFileChunks())) { fileIndex.setFileChunks(new ArrayList<>()); } List fileChunks = fileIndex.getFileChunks(); - FileChunk uploadChunk = fileIndex.getFileChunk(); fileChunks.add(uploadChunk); fileIndex.setCurrentIndex(uploadChunk.getChunkIndex()); if ((uploadChunk.getIsLastChunk() || uploadChunk.getChunkIndex().equals(fileIndex.getSliceSize())) && fileIndex.getIsMerge()) { + List sources = fileChunks.stream().map(RestId::getId).collect(Collectors.toList()); fileIndex.setIsFinish(true); + asyncFileService.margeById(fileIndex.getId(), sources); checkFileIndex(fileIndex); - fileUploadService.lastChunk(fileIndex); + fileIndexService.save(fileIndex); } - return fileIndex; + return AsyncResult.forValue(fileIndex); } private void checkFileIndex(FileIndex fileIndex) { diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java deleted file mode 100644 index 5d7306f..0000000 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileUploadServiceImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.github.nichetoolkit.file.service.impl; - -import io.github.nichetoolkit.file.configure.FileCommonProperties; -import io.github.nichetoolkit.file.enums.FileType; -import io.github.nichetoolkit.file.model.FileChunk; -import io.github.nichetoolkit.file.model.FileIndex; -import io.github.nichetoolkit.file.service.*; -import io.github.nichetoolkit.rest.RestException; -import io.github.nichetoolkit.rice.RestId; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.stream.Collectors; - -/** - *

FileUploadServiceImpl

- * @author Cyan (snow22314@outlook.com) - * @version v1.0.0 - */ -@Slf4j -@Service -public class FileUploadServiceImpl implements FileUploadService { - - @Autowired - protected FileCommonProperties commonProperties; - - @Autowired - protected FileIndexService fileIndexService; - - @Autowired - protected FileChunkService fileChunkService; - - @Autowired - protected FileHandleService fileHandleService; - - @Autowired - protected AsyncFileService asyncFileService; - - @Async - @Override - public void uploadFileIndex(FileIndex fileIndex) throws RestException { - if (fileIndex.getIsAutograph() != null && fileIndex.getIsAutograph() && fileIndex.getFileType() == FileType.IMAGE) { - fileHandleService.autographImage(fileIndex); - } - if (fileIndex.getIsCondense()) { - if (fileIndex.getFileType() == FileType.IMAGE) { - fileHandleService.condenseImage(fileIndex); - } else { - fileHandleService.condenseFile(fileIndex); - } - } - String fileId = fileIndex.getId(); - asyncFileService.putById(fileId, fileIndex.inputStream()); - fileIndexService.save(fileIndex); - } - - @Async - @Override - public void uploadChunk(FileIndex fileIndex) throws RestException { - FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); - asyncFileService.putById(uploadChunk.getId(), uploadChunk.inputStream()); - fileIndex.setFileChunk(uploadChunk); - } - - @Async - @Override - public void lastChunk(FileIndex fileIndex) throws RestException { - List sources = fileIndex.getFileChunks().stream().map(RestId::getId).collect(Collectors.toList()); - asyncFileService.margeById(fileIndex.getId(), sources); - fileIndexService.save(fileIndex); - } - -} From 23155492935e6571154c471dda1a16b8dcc61958 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 14:55:48 +0800 Subject: [PATCH 19/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/model/FileIndex.java | 8 +- .../file/helper/FileServiceHelper.java | 114 ++----------- .../file/service/FileService.java | 132 +++++++++++++++ .../service/impl/FileHandleServiceImpl.java | 152 ++++++++++++++++++ .../file/service/impl/FileServiceImpl.java | 31 ++-- 5 files changed, 316 insertions(+), 121 deletions(-) create mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java create mode 100644 file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index 75a3434..e6f15e3 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -19,9 +19,7 @@ import org.springframework.lang.NonNull; import org.springframework.web.multipart.MultipartFile; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -111,7 +109,7 @@ public class FileIndex extends RiceInfoModel { protected byte[] bytes; @JsonIgnore - protected MultipartFile file; + protected File file; public FileIndex() { } @@ -126,7 +124,7 @@ public InputStream inputStream() { return new ByteArrayInputStream(this.bytes); } else if (GeneralUtils.isNotEmpty(this.file)) { try { - return this.file.getInputStream(); + return new FileInputStream(this.file); } catch (IOException ignored) { } } diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index 4156a70..daf31b4 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -17,6 +17,7 @@ import io.github.nichetoolkit.file.util.Md5Utils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.identity.IdentityUtils; import io.github.nichetoolkit.rest.util.*; import io.github.nichetoolkit.rice.RestPage; import io.github.nichetoolkit.rice.helper.PropertyHelper; @@ -47,7 +48,7 @@ public class FileServiceHelper implements InitializingBean { @Autowired - private FileCommonProperties serviceProperties; + private FileCommonProperties commonProperties; @Autowired private FileIndexService fileIndexService; @@ -80,94 +81,6 @@ public static void checkRestPage(RestPage restPage) throws RestException { } } - public static void condenseFile(String randomPath, FileIndex fileIndex) throws RestException { - String filename = fileIndex.getName(); - String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = FileUtils.createFile(filePath); - StreamUtils.write(file, fileIndex.inputStream()); - File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); - buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); - if (fileIndex.getIsMd5()) { - buildMd5(zipFile, fileIndex); - } - } - - public static void autographImage(String randomPath, FileIndex fileIndex) throws RestException { - InputStream inputStream = fileIndex.inputStream(); - BufferedImage bufferedImage = ImageUtils.read(inputStream); - BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); - BufferedImage autographImage = ImageUtils.autograph(binaryImage); - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath = randomPath.concat(File.separator).concat(filename); - File file = new File(filePath); - if (file.exists()) { - FileUtils.delete(filePath); - } - ImageUtils.write(autographImage, file); - byte[] bytes = ImageUtils.bytes(file); - fileIndex.setBytes(bytes); - FileUtils.delete(filePath); - } - - public static void condenseImage(String randomPath, FileIndex fileIndex) throws RestException { - Long imageFileSize; - Double imageFileQuality = 1.0d; - Double imageFileScale = 1.0d; - String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); - String filePath; - File file; - Integer width = fileIndex.getWidth(); - Integer height = fileIndex.getHeight(); - filePath = randomPath.concat(File.separator).concat(filename); - file = new File(filePath); - do { - if (file.exists()) { - FileUtils.delete(filePath); - } - try { - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - BufferedImage bufferedImage = ImageHelper.read(file); - int imageWidth = bufferedImage.getWidth(); - int imageHeight = bufferedImage.getHeight(); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { - if (GeneralUtils.isNotEmpty(width)) { - imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); - } else { - imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); - } - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } else { - imageFileQuality = INSTANCE.serviceProperties.getMinImageQuality(); - Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - } - } catch (IOException exception) { - log.error("the image file has error during condensing: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); - } - imageFileSize = file.length(); - if (imageFileQuality.equals(INSTANCE.serviceProperties.getMinImageQuality())) { - imageFileScale += -0.1d; - } else { - imageFileQuality += -0.1d; - } - } while (imageFileSize > INSTANCE.serviceProperties.getMaxImageSize() - && imageFileQuality > INSTANCE.serviceProperties.getMinImageQuality() - && imageFileScale > INSTANCE.serviceProperties.getMinImageScale()); - if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); - } else { - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); - } - fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); - buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); - buildMd5(file, fileIndex); - FileUtils.clearFile(randomPath); - } - public static void buildProperties(String filename, long size, String suffix, FileIndex fileIndex) { fileIndex.addProperty(FileConstants.ORIGINAL_SUFFIX_PROPERTY, fileIndex.getSuffix()); fileIndex.setSuffix(suffix); @@ -197,7 +110,7 @@ public static void buildChunkFiles(List fileIndices, FileFilter fileF public static void buildIndexFiles(List fileIndices, FileFilter fileFilter, String randomPath, List fileList) throws RestException { for (FileIndex fileIndex : fileIndices) { - if (fileIndex.getFileSize() > INSTANCE.serviceProperties.getMaxFileSize()) { + if (fileIndex.getFileSize() > INSTANCE.commonProperties.getMaxFileSize()) { log.warn("the file size is too large, id: {}, size: {}", fileIndex.getId(), fileIndex.getFileSize()); throw new FileErrorException(FileErrorStatus.FILE_TOO_LARGE_ERROR); } @@ -328,7 +241,7 @@ public static void buildMd5(byte[] bytes, FileChunk fileChunk) throws RestExcept fileChunk.setChunkMd5(md5); } - public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) throws RestException { + public static FileIndex createFileChunk(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { log.warn("the file index is null!"); throw new FileErrorException(FileErrorStatus.FILE_INDEX_IS_NULL); @@ -360,8 +273,8 @@ public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) } Long chunkSize = fileChunk.getChunkSize(); if (GeneralUtils.isEmpty(chunkSize)) { - chunkSize = file.getSize(); - fileChunk.setChunkSize(file.getSize()); + chunkSize = multipartFile.getSize(); + fileChunk.setChunkSize(multipartFile.getSize()); } Long chunkStart = fileChunk.getChunkStart(); if (chunkStart == null) { @@ -377,7 +290,7 @@ public static FileIndex createFileChunk(MultipartFile file, FileIndex fileIndex) log.error("the param of 'chunkEnd' or 'chunkStart' or 'chunkSize' for file chunk is invalid! "); throw new FileErrorException(FileErrorStatus.FILE_CHUNK_PARAM_INVALID); } - buildMd5(file, fileChunk); + buildMd5(multipartFile, fileChunk); fileChunk.setChunkTime(new Date()); if (fileChunk.getChunkIndex() == 1) { @@ -438,12 +351,19 @@ public static FileIndex createFileChunk(FileRequest fileRequest, String contentR return fileIndex; } - public static FileIndex createFileIndex(MultipartFile file, FileIndex fileIndex) throws RestException { + public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { fileIndex = new FileIndex(); } - String originalFilename = file.getOriginalFilename(); + if (GeneralUtils.isEmpty(fileIndex.getId())) { + String fileId = IdentityUtils.generateString(); + fileIndex.setId(fileId); + } + String originalFilename = multipartFile.getOriginalFilename(); fileIndex.setName(originalFilename); + String tempPath = FileUtils.createPath(INSTANCE.commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + File file = FileUtils.cacheFile(cachePath, multipartFile); fileIndex.setFile(file); String filename = FileUtils.filename(originalFilename); if (GeneralUtils.isEmpty(fileIndex.getFilename())) { @@ -456,7 +376,7 @@ public static FileIndex createFileIndex(MultipartFile file, FileIndex fileIndex) if (GeneralUtils.isEmpty(fileIndex.getSuffix())) { fileIndex.setSuffix(suffix); } - fileIndex.setFileSize(file.getSize()); + fileIndex.setFileSize(multipartFile.getSize()); FileType fileType = parseType(suffix); if (GeneralUtils.isEmpty(fileIndex.getIsSlice())) { fileIndex.setIsSlice(false); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java new file mode 100644 index 0000000..f3d1c70 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/FileService.java @@ -0,0 +1,132 @@ +package io.github.nichetoolkit.file.service; + +import io.github.nichetoolkit.file.enums.FileType; +import io.github.nichetoolkit.file.filter.FileFilter; +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.file.model.FileRequest; +import io.github.nichetoolkit.rest.RestException; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.util.concurrent.Future; + +/** + *

FileService

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +public interface FileService { + + /** + * 文件移除 + * @param fileFilter 过滤器删除 + * @throws RestException 服务异常 + */ + void remove(FileFilter fileFilter) throws RestException; + + /** + * 文件移除 + * @param fileId 文件id + * @param chunk 是否是分片 + * @param delete 是否真实删除 + * @param rename 是否重命名删除 + * @throws RestException 服务异常 + */ + void remove(String fileId, Boolean chunk, Boolean delete, Boolean rename) throws RestException; + + /** + * 下载文件 + * @param file 文件数据 + * @param filename 文件名称 + * @param contentType contentType + * @param response 返回体 + * @throws RestException 服务异常 + */ + void download(File file, String filename, String contentType, HttpServletRequest request, HttpServletResponse response) throws RestException; + + /** + * 下载文件 + * @param fileIndex 文件id + * @param filename 文件名称 + * @param contentType contentType + * @param response 返回体 + * @throws RestException 服务异常 + */ + void download(FileIndex fileIndex, String filename, String contentType, Boolean preview, FileType fileType, HttpServletRequest request, HttpServletResponse response) throws RestException; + + /** + * @param fileIndex 文件id + * @param filename 文件名称 + * @param preview 是否预览图片 + * @param response 返回体 + * @throws RestException 服务异常 + */ + void download(FileIndex fileIndex, String filename, Boolean preview, FileType fileType, HttpServletRequest request, HttpServletResponse response) throws RestException; + + /** + * 下载多文件 + * @param fileFilter 查询过滤器 + * @param response 返回体 + * @throws RestException 服务异常 + */ + void download(FileFilter fileFilter, HttpServletRequest request, HttpServletResponse response) throws RestException; + + /** + * 下载文件 + * @param fileId 文件id + * @param chunk 是否下载分片文件 + * @param preview 是否预览图片 + * @param original 是否原始命名 + * @param response 返回体 + * @throws RestException 服务异常 + */ + void fileDownload(String fileId, Boolean chunk, Boolean preview, Boolean original, HttpServletRequest request, HttpServletResponse response) throws RestException; + + /** + * 下载图片 + * @param fileId 文件id + * @param preview 是否预览图片 + * @param original 是否原始命名 + * @param response 返回体 + * @throws RestException 服务异常 + */ + void imageDownload(String fileId, Boolean preview, Boolean original, HttpServletRequest request, HttpServletResponse response) throws RestException; + + /** + * 上传文件 + * @param file 文件数据 + * @param fileRequest 文件信息 + * @return FileIndex + * @throws RestException 服务异常 + */ + FileIndex upload(MultipartFile file, FileRequest fileRequest) throws RestException; + + /** + * 上传文件 + * @param fileIndex 文件信息 + * @return FileIndex + * @throws RestException 服务异常 + */ + FileIndex upload(FileIndex fileIndex) throws RestException; + + /** + * 预分片上传文件 + * @param fileIndex 文件信息 + * @return FileIndex + * @throws RestException 服务异常 + */ + FileIndex indexUpload(FileIndex fileIndex) throws RestException; + + /** + * 分片上传 + * @param file 分片文件数据 + * @param contentRange 分片header + * @param fileRequest 文件信息 + * @return FileIndex + * @throws RestException 服务异常 + */ + FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException; + +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java new file mode 100644 index 0000000..3b0fc64 --- /dev/null +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -0,0 +1,152 @@ +package io.github.nichetoolkit.file.service.impl; + +import io.github.nichetoolkit.file.configure.FileCommonProperties; +import io.github.nichetoolkit.file.constant.FileConstants; +import io.github.nichetoolkit.file.enums.FileType; +import io.github.nichetoolkit.file.error.FileErrorStatus; +import io.github.nichetoolkit.file.helper.FileServiceHelper; +import io.github.nichetoolkit.file.helper.ImageHelper; +import io.github.nichetoolkit.file.model.FileIndex; +import io.github.nichetoolkit.file.service.FileHandleService; +import io.github.nichetoolkit.file.util.ImageUtils; +import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.identity.IdentityUtils; +import io.github.nichetoolkit.rest.util.FileUtils; +import io.github.nichetoolkit.rest.util.GeneralUtils; +import io.github.nichetoolkit.rest.util.StreamUtils; +import io.github.nichetoolkit.rest.util.ZipUtils; +import lombok.extern.slf4j.Slf4j; +import net.coobird.thumbnailator.Thumbnails; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +/** + *

FileHandleServiceImpl

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Service +public class FileHandleServiceImpl implements FileHandleService { + + @Autowired + protected FileCommonProperties commonProperties; + @Autowired + private FileCommonProperties serviceProperties; + + @Async + @Override + public void autographImage(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + InputStream inputStream = fileIndex.inputStream(); + BufferedImage bufferedImage = ImageUtils.read(inputStream); + BufferedImage binaryImage = ImageUtils.binaryImage(bufferedImage); + BufferedImage autographImage = ImageUtils.autograph(binaryImage); + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = new File(filePath); + if (file.exists()) { + FileUtils.delete(filePath); + } + ImageUtils.write(autographImage, file); + byte[] bytes = ImageUtils.bytes(file); + fileIndex.setBytes(bytes); + FileUtils.delete(filePath); + FileUtils.clear(randomPath); + FileUtils.clear(cachePath); + } + + @Async + @Override + public void condenseImage(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + Long imageFileSize; + Double imageFileQuality = 1.0d; + Double imageFileScale = 1.0d; + String filename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.IMAGE_PNG_SUFFIX); + String filePath; + File file; + Integer width = fileIndex.getWidth(); + Integer height = fileIndex.getHeight(); + filePath = randomPath.concat(File.separator).concat(filename); + file = new File(filePath); + do { + if (file.exists()) { + FileUtils.delete(filePath); + } + try { + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + BufferedImage bufferedImage = ImageHelper.read(file); + int imageWidth = bufferedImage.getWidth(); + int imageHeight = bufferedImage.getHeight(); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + Thumbnails.of(fileIndex.inputStream()).size(width, height).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else if (GeneralUtils.isNotEmpty(width) || GeneralUtils.isNotEmpty(height)) { + if (GeneralUtils.isNotEmpty(width)) { + imageFileScale = ((double) width / (double) imageWidth >= 1.0D) ? imageFileScale : ((double) width / (double) imageWidth); + } else { + imageFileScale = ((double) height / (double) imageHeight >= 1.0D) ? imageFileScale : ((double) height / (double) imageHeight); + } + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } else { + Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); + } + } catch (IOException exception) { + log.error("the image file has error during condensing: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.FILE_IMAGE_CONDENSE_ERROR); + } + imageFileSize = file.length(); + if (imageFileQuality.equals(serviceProperties.getMinImageQuality())) { + imageFileScale += -0.1d; + } else { + imageFileQuality += -0.1d; + } + } while (imageFileSize > serviceProperties.getMaxImageSize() + && imageFileQuality > serviceProperties.getMinImageQuality() + && imageFileScale > serviceProperties.getMinImageScale()); + if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_WIDTH_PROPERTY, width); + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_HEIGHT_PROPERTY, height); + } else { + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_SCALE_PROPERTY, imageFileScale); + } + fileIndex.addProperty(FileConstants.IMAGE_CONDENSE_QUALITY_PROPERTY, imageFileQuality); + FileServiceHelper.buildProperties(filename, file.length(), FileConstants.IMAGE_PNG_SUFFIX, fileIndex); + FileServiceHelper.buildMd5(file, fileIndex); + FileUtils.delete(filePath); + FileUtils.clear(randomPath); + FileUtils.clear(cachePath); + } + + @Async + @Override + public void condenseFile(FileIndex fileIndex) throws RestException { + String tempPath = FileUtils.createPath(commonProperties.getTempPath()); + String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); + String randomPath = FileUtils.createPath(cachePath, GeneralUtils.uuid()); + String filename = fileIndex.getName(); + String zipFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(FileConstants.FILE_ZIP_SUFFIX); + String filePath = randomPath.concat(File.separator).concat(filename); + File file = FileUtils.createFile(filePath); + StreamUtils.write(file, fileIndex.inputStream()); + File zipFile = ZipUtils.zipFile(randomPath, zipFilename, file); + FileServiceHelper.buildProperties(zipFilename, zipFile.length(), FileConstants.FILE_ZIP_SUFFIX, fileIndex); + if (fileIndex.getIsMd5()) { + FileServiceHelper.buildMd5(zipFile, fileIndex); + } + FileUtils.delete(filePath); + FileUtils.clear(randomPath); + FileUtils.clear(cachePath); + } +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index 1a4d747..85b2b3a 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -9,9 +9,7 @@ import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.file.service.AsyncFileService; -import io.github.nichetoolkit.file.service.FileChunkService; -import io.github.nichetoolkit.file.service.FileIndexService; +import io.github.nichetoolkit.file.service.*; import io.github.nichetoolkit.file.video.VideoHttpRequestHandler; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; @@ -61,6 +59,9 @@ public class FileServiceImpl implements FileService { @Autowired protected FileChunkService fileChunkService; + @Autowired + protected FileHandleService fileHandleService; + @Autowired protected AsyncFileService asyncFileService; @@ -303,28 +304,21 @@ public FileIndex upload(FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { throw new RestException(FileErrorStatus.FILE_INDEX_IS_NULL); } - String tempPath = FileUtils.createPath(commonProperties.getTempPath()); - String randomPath = FileUtils.createPath(tempPath, GeneralUtils.uuid()); - if (fileIndex.getIsAutograph() != null && fileIndex.getIsAutograph() && fileIndex.getFileType() == FileType.IMAGE) { - FileServiceHelper.autographImage(randomPath, fileIndex); + fileHandleService.autographImage(fileIndex); } if (fileIndex.getIsCondense()) { if (fileIndex.getFileType() == FileType.IMAGE) { - FileServiceHelper.condenseImage(randomPath, fileIndex); + fileHandleService.condenseImage(fileIndex); } else { - FileServiceHelper.condenseFile(randomPath, fileIndex); + fileHandleService.condenseFile(fileIndex); } } String fileId = fileIndex.getId(); - if (GeneralUtils.isEmpty(fileIndex.getId())) { - fileId = IdentityUtils.generateString(); - fileIndex.setId(fileId); - } asyncFileService.putById(fileId, fileIndex.inputStream()); - FileUtils.clear(randomPath); + fileIndexService.save(fileIndex); checkFileIndex(fileIndex); - return fileIndexService.save(fileIndex); + return fileIndex; } @Override @@ -340,8 +334,7 @@ public FileIndex indexUpload(FileIndex fileIndex) throws RestException { } @Override - @Async - public Future chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { + public FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { FileIndex fileChunkIndex = FileServiceHelper.createFileChunk(fileRequest, contentRange); FileIndex fileIndex = FileServiceHelper.createFileChunk(file, fileChunkIndex); FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); @@ -354,13 +347,13 @@ public Future chunkUpload(MultipartFile file, String contentRange, Fi fileChunks.add(uploadChunk); fileIndex.setCurrentIndex(uploadChunk.getChunkIndex()); if ((uploadChunk.getIsLastChunk() || uploadChunk.getChunkIndex().equals(fileIndex.getSliceSize())) && fileIndex.getIsMerge()) { - List sources = fileChunks.stream().map(RestId::getId).collect(Collectors.toList()); fileIndex.setIsFinish(true); + List sources = fileIndex.getFileChunks().stream().map(RestId::getId).collect(Collectors.toList()); asyncFileService.margeById(fileIndex.getId(), sources); checkFileIndex(fileIndex); fileIndexService.save(fileIndex); } - return AsyncResult.forValue(fileIndex); + return fileIndex; } private void checkFileIndex(FileIndex fileIndex) { From ddd20bee4de79e41530250ce1143811dbe0b8c27 Mon Sep 17 00:00:00 2001 From: Cyan Date: Mon, 27 Feb 2023 15:58:15 +0800 Subject: [PATCH 20/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=88=A0=E9=99=A4=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nichetoolkit/file/helper/FileServiceHelper.java | 4 ++-- .../nichetoolkit/file/controller/FileController.java | 8 ++------ .../src/main/resources/application-dev.properties | 4 ++-- .../src/main/resources/application.properties | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index daf31b4..7c0fa4b 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -185,8 +185,8 @@ public static void buildMd5(MultipartFile file, FileIndex fileIndex) throws Rest } public static void buildMd5(File file, FileIndex fileIndex) throws RestException { - try { - buildMd5(new FileInputStream(file), fileIndex); + try(FileInputStream fileInputStream = new FileInputStream(file)) { + buildMd5(fileInputStream, fileIndex); } catch (IOException exception) { log.error("the file read with bytes has error, filename: {}, error: {}", fileIndex.getName(), exception.getMessage()); throw new FileErrorException(FileErrorStatus.FILE_READ_BYTE_ERROR); diff --git a/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java b/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java index 47ac4c4..631f929 100644 --- a/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java +++ b/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java @@ -118,12 +118,8 @@ public ResponseEntity chunkUpload(@NonNull @RequestPart("file") MultipartFile fi FileRequest fileRequest) throws RestException { String originalFilename = file.getOriginalFilename(); log.info("the chunk file will be started uploading at 'chunkUpload', filename: {}", originalFilename); - Future indexFuture = fileService.chunkUpload(file, contentRange, fileRequest); - try { - return RestResult.ok(indexFuture.get()); - } catch (InterruptedException | ExecutionException exception) { - throw new ServiceErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR, exception.getMessage()); - } + FileIndex fileIndex = fileService.chunkUpload(file, contentRange, fileRequest); + return ResponseEntity.ok(fileIndex); } @Deprecated diff --git a/file-toolkit-test-web/src/main/resources/application-dev.properties b/file-toolkit-test-web/src/main/resources/application-dev.properties index af4caad..c238667 100644 --- a/file-toolkit-test-web/src/main/resources/application-dev.properties +++ b/file-toolkit-test-web/src/main/resources/application-dev.properties @@ -1,4 +1,4 @@ -server.port=8081 +server.port=8084 nichetoolkit.rest.intercept.enabled=true nichetoolkit.rest.intercept.log-enabled=true nichetoolkit.rest.intercept.bean-enabled=true @@ -10,7 +10,7 @@ spring.datasource.hikari.driver-class-name=org.postgresql.Driver spring.datasource.hikari.jdbc-url=jdbc:postgresql://localhost:5432/resource?stringtype=unspecified spring.datasource.hikari.username=postgres spring.datasource.hikari.password=2314 -nichetoolkit.file.service.temp-path=G:\\data\\server\\file\\temp +nichetoolkit.file.common.temp-path=E:\\data\\server\\file\\temp nichetoolkit.file.minio.endpoint=http://172.16.107.144:9000 nichetoolkit.file.minio.bucket-name=local nichetoolkit.file.minio.access-key=admin diff --git a/file-toolkit-test-web/src/main/resources/application.properties b/file-toolkit-test-web/src/main/resources/application.properties index b254387..3ef5bfb 100644 --- a/file-toolkit-test-web/src/main/resources/application.properties +++ b/file-toolkit-test-web/src/main/resources/application.properties @@ -34,4 +34,4 @@ spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1 logging.config=classpath:logback-spring.xml -spring.profiles.active=pro \ No newline at end of file +spring.profiles.active=dev \ No newline at end of file From 8e59b6e5b3c254d5e553035d9b6f4258c629e565 Mon Sep 17 00:00:00 2001 From: Cyan Date: Tue, 28 Feb 2023 17:07:43 +0800 Subject: [PATCH 21/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/github/nichetoolkit/file/model/FileIndex.java | 1 - .../github/nichetoolkit/file/service/impl/FileServiceImpl.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java index e6f15e3..aaba571 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/model/FileIndex.java @@ -17,7 +17,6 @@ import lombok.EqualsAndHashCode; import okhttp3.Headers; import org.springframework.lang.NonNull; -import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.util.ArrayList; diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index 85b2b3a..de18c35 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -316,8 +316,8 @@ public FileIndex upload(FileIndex fileIndex) throws RestException { } String fileId = fileIndex.getId(); asyncFileService.putById(fileId, fileIndex.inputStream()); - fileIndexService.save(fileIndex); checkFileIndex(fileIndex); + fileIndexService.save(fileIndex); return fileIndex; } From 522c7183531d28e7426e56a0729fb34ebee853a5 Mon Sep 17 00:00:00 2001 From: Cyan Date: Wed, 1 Mar 2023 11:51:50 +0800 Subject: [PATCH 22/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/nichetoolkit/file/service/impl/FileServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index de18c35..7e12f3d 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -337,6 +337,7 @@ public FileIndex indexUpload(FileIndex fileIndex) throws RestException { public FileIndex chunkUpload(MultipartFile file, String contentRange, FileRequest fileRequest) throws RestException { FileIndex fileChunkIndex = FileServiceHelper.createFileChunk(fileRequest, contentRange); FileIndex fileIndex = FileServiceHelper.createFileChunk(file, fileChunkIndex); + checkFileIndex(fileIndex); FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); asyncFileService.putById(uploadChunk.getId(), uploadChunk.inputStream()); fileIndex.setFileChunk(uploadChunk); From 9b531615d4f90bea90a2151a29916d5587d5bc34 Mon Sep 17 00:00:00 2001 From: Cyan Date: Fri, 3 Mar 2023 16:17:50 +0800 Subject: [PATCH 23/30] logback fix --- .../file/controller/FileController.java | 10 ++ .../main/resources/application-dev.properties | 9 +- .../main/resources/application-pro.properties | 9 +- .../src/main/resources/application.properties | 43 ++++++++- .../src/main/resources/logback-spring.xml | 94 +++++++++++-------- 5 files changed, 117 insertions(+), 48 deletions(-) diff --git a/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java b/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java index 631f929..8b24282 100644 --- a/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java +++ b/file-toolkit-test-web/src/main/java/io/github/nichetoolkit/file/controller/FileController.java @@ -12,8 +12,10 @@ import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.RestResult; import io.github.nichetoolkit.rest.error.natives.ServiceErrorException; +import io.github.nichetoolkit.rest.userlog.stereotype.RestNotelog; import io.github.nichetoolkit.rest.util.FileUtils; import io.github.nichetoolkit.rest.util.JsonUtils; +import io.github.nichetoolkit.rice.stereotype.RestSkip; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -31,6 +33,8 @@ import java.util.concurrent.Future; @Slf4j +@RestSkip +@RestNotelog @RestController @RequestMapping("/file") public class FileController { @@ -41,6 +45,12 @@ public class FileController { @Autowired private FileService fileService; + @GetMapping("/error") + public ResponseEntity error() throws RestException { + Object test = null; + test.toString(); + return RestResult.ok(); + } @GetMapping("/img/download") public void imgDownload(@RequestParam(value = "fileId") String fileId, diff --git a/file-toolkit-test-web/src/main/resources/application-dev.properties b/file-toolkit-test-web/src/main/resources/application-dev.properties index c238667..6a6e4ae 100644 --- a/file-toolkit-test-web/src/main/resources/application-dev.properties +++ b/file-toolkit-test-web/src/main/resources/application-dev.properties @@ -1,11 +1,14 @@ -server.port=8084 +server.port=8080 nichetoolkit.rest.intercept.enabled=true nichetoolkit.rest.intercept.log-enabled=true -nichetoolkit.rest.intercept.bean-enabled=true -nichetoolkit.rest.error.console-log.rest-exception-enabled=true +nichetoolkit.rest.intercept.userlog-enabled=true + +nichetoolkit.rest.error.console-log.rest-exception-enabled=false nichetoolkit.rest.error.console-log.common-exception-enabled=true + nichetoolkit.rest.http.enabled=true nichetoolkit.rest.http.http-type=ok_http_client + spring.datasource.hikari.driver-class-name=org.postgresql.Driver spring.datasource.hikari.jdbc-url=jdbc:postgresql://localhost:5432/resource?stringtype=unspecified spring.datasource.hikari.username=postgres diff --git a/file-toolkit-test-web/src/main/resources/application-pro.properties b/file-toolkit-test-web/src/main/resources/application-pro.properties index eb76985..270f62a 100644 --- a/file-toolkit-test-web/src/main/resources/application-pro.properties +++ b/file-toolkit-test-web/src/main/resources/application-pro.properties @@ -1,16 +1,21 @@ server.port=8081 nichetoolkit.rest.intercept.enabled=false nichetoolkit.rest.intercept.log-enabled=false -nichetoolkit.rest.intercept.bean-enabled=false +nichetoolkit.rest.intercept.userlog-enabled=true + nichetoolkit.rest.error.console-log.rest-exception-enabled=false nichetoolkit.rest.error.console-log.common-exception-enabled=true + nichetoolkit.rest.http.enabled=true nichetoolkit.rest.http.http-type=ok_http_client + spring.datasource.hikari.driver-class-name=org.postgresql.Driver spring.datasource.hikari.jdbc-url=jdbc:postgresql://172.16.107.144:5432/fileserver@1.0.0?stringtype=unspecified spring.datasource.hikari.username=postgres spring.datasource.hikari.password=xinfeng@postgres -nichetoolkit.file.service.temp-path=G:\\data\\server\\file\\temp + +nichetoolkit.file.common.temp-path=G:\\data\\server\\file\\temp + nichetoolkit.file.minio.endpoint=http://172.16.107.144:9000 nichetoolkit.file.minio.bucket-name=local nichetoolkit.file.minio.access-key=admin diff --git a/file-toolkit-test-web/src/main/resources/application.properties b/file-toolkit-test-web/src/main/resources/application.properties index 3ef5bfb..e57f2ee 100644 --- a/file-toolkit-test-web/src/main/resources/application.properties +++ b/file-toolkit-test-web/src/main/resources/application.properties @@ -2,28 +2,59 @@ spring.jmx.enabled=false spring.application.name=file-server spring.jmx.default-domain=file-server server.tomcat.connection-timeout=600s + spring.servlet.multipart.enabled=true spring.servlet.multipart.max-file-size=64000MB spring.servlet.multipart.max-request-size=6400MB -nichetoolkit.rice.bean.name.unique-enabled=true -nichetoolkit.rice.bean.name.nonnull-enabled=false + +nichetoolkit.rice.bean.name.unique-enabled = true +nichetoolkit.rice.bean.name.nonnull-enabled = true +nichetoolkit.rice.bean.key.invade-enabled = false + +nichetoolkit.rice.bean.model.dynamic-table-enabled= false + +nichetoolkit.rest.error.console-log.rest-exception-enabled=false +nichetoolkit.rest.error.console-log.common-exception-enabled=true + spring.jackson.default-property-inclusion=non_null spring.jackson.parser.allow-unquoted-control-chars=true spring.jackson.parser.allow-comments=true spring.jackson.parser.allow-single-quotes=true spring.jackson.deserialization.fail-on-unknown-properties=false spring.jackson.time-zone=GMT+8 + spring.main.allow-circular-references=true + +spring.main.allow-bean-definition-overriding=true + nichetoolkit.rest.identity.enabled=true nichetoolkit.rest.identity.type=config nichetoolkit.rest.identity.config.worker-id=1 nichetoolkit.rest.identity.config.center-id=2 -nichetoolkit.rest.md5.enabled=false -nichetoolkit.rest.md5.cipher=4AFa1sTe45FAst2^aPHV7sVG + +nichetoolkit.rest.http.enabled=true +nichetoolkit.rest.http.http-type=ok_http_client + +nichetoolkit.rest.intercept.enabled=true +nichetoolkit.rest.intercept.log-enabled=true +nichetoolkit.rest.intercept.userlog-enabled=true + +nichetoolkit.rice.login.enabled=true +nichetoolkit.rice.login.token-prefixes=Bearer +nichetoolkit.rice.login.header-tokens=Authorization + +nichetoolkit.rest.logback.enabled=true +nichetoolkit.rest.logback.attributes=t + +nichetoolkit.rest.sha.enabled=false +nichetoolkit.rest.sha.secret=4AFa1sTe45FAst2^aPHV7sVG + nichetoolkit.rest.jwt.enabled=false -nichetoolkit.rest.jwt.secret-key=4AFa1sTe45FAst2^aPHV7sVG +nichetoolkit.rest.jwt.secret=4AFa1sTe45FAst2^aPHV7sVG nichetoolkit.rest.jwt.issuer=io.github.nichetoolkit + nichetoolkit.rest.radix.enabled=false + spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.maximum-pool-size=15 @@ -33,5 +64,7 @@ spring.datasource.hikari.pool-name=DatebookHikariCP spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1 + logging.config=classpath:logback-spring.xml + spring.profiles.active=dev \ No newline at end of file diff --git a/file-toolkit-test-web/src/main/resources/logback-spring.xml b/file-toolkit-test-web/src/main/resources/logback-spring.xml index f24cd50..f4aafe5 100644 --- a/file-toolkit-test-web/src/main/resources/logback-spring.xml +++ b/file-toolkit-test-web/src/main/resources/logback-spring.xml @@ -3,31 +3,50 @@ - + logback - - + + + + - - - + + + - + value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%X{logKey}){magenta} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %rmx%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> - + ${CONSOLE_LOG_PATTERN} @@ -36,7 +55,6 @@ - @@ -45,7 +63,7 @@ ${log.path}/logs.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -71,7 +89,7 @@ ${log.path}/log_debug.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -98,7 +116,7 @@ ${log.path}/log_info.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -125,7 +143,7 @@ ${log.path}/log_warn.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -152,7 +170,7 @@ ${log.path}/log_error.log - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} %X{logKey} %X{requestKey} [%thread] %-5level %logger{50} - %rmx%n UTF-8 @@ -200,26 +218,26 @@ - - - - - - - + + + + + + + - - - - - - - + + + + + + + @@ -227,13 +245,13 @@ - - - - - - + + + + + + - + \ No newline at end of file From 6b4fd342226268487c72fd8c96e36b7c61d51222 Mon Sep 17 00:00:00 2001 From: Cyan Date: Sat, 4 Mar 2023 19:19:36 +0800 Subject: [PATCH 24/30] spring boot 2.7.7 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5a750b2..7ffa639 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.6 + 2.7.7 @@ -113,7 +113,7 @@ UTF-8 1.8 1.8 - 2.7.6 + 2.7.7 1.0.6-SNAPSHOT 1.0.5-SNAPSHOT From d0b4849a95c9e8d779f7139c4c6180907c79d763 Mon Sep 17 00:00:00 2001 From: Cyan Date: Tue, 14 Mar 2023 11:22:07 +0800 Subject: [PATCH 25/30] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/handle/FileStoreService.java | 6 +- .../file/helper/FileHandleHelper.java | 51 ++++ ...mageHelper.java => ImageHandleHelper.java} | 2 +- .../nichetoolkit/file/util/ImageUtils.java | 25 +- file-toolkit-gauss-starter/pom.xml | 224 ++++++++++++++++ .../sql/file-toolkit-gauss@1.0.2.sql | 0 .../configure/FileGaussAutoConfigure.java | 22 ++ .../file/mapper/FileChunkMapper.xml | 238 +++++++++++++++++ .../file/mapper/FileIndexMapper.xml | 242 ++++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + file-toolkit-hdfs-starter/pom.xml | 2 +- file-toolkit-minio-starter/pom.xml | 2 +- .../FileMinioStarterAutoConfigure.java | 3 - ...FileService.java => FileStoreService.java} | 6 +- file-toolkit-postgres-starter/pom.xml | 224 ++++++++++++++++ .../sql/file-toolkit-postgres@1.0.2.sql | 135 ++++++++++ .../configure/FilePostgresAutoConfigure.java | 22 ++ .../file/mapper/FileChunkMapper.xml | 0 .../file/mapper/FileIndexMapper.xml | 0 .../main/resources/META-INF/spring.factories | 1 + file-toolkit-service-starter/pom.xml | 6 - .../sql/file-toolkit@1.0.2.sql | 135 ++++++++++ .../configure/FileServiceAsyncConfigure.java | 3 +- .../file/helper/FileServiceHelper.java | 29 +-- .../service/impl/FileChunkServiceImpl.java | 2 +- .../service/impl/FileHandleServiceImpl.java | 8 +- .../service/impl/FileIndexServiceImpl.java | 2 +- .../file/service/impl/FileServiceImpl.java | 31 +-- file-toolkit-test-web/pom.xml | 12 + .../main/resources/application-dev.properties | 3 +- .../src/main/resources/application.properties | 2 +- pom.xml | 4 +- 32 files changed, 1359 insertions(+), 84 deletions(-) rename file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/AsyncFileService.java => file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/handle/FileStoreService.java (88%) create mode 100644 file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java rename file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/{ImageHelper.java => ImageHandleHelper.java} (99%) create mode 100644 file-toolkit-gauss-starter/pom.xml rename file-toolkit-service-starter/sql/file-toolkit-postgres@1.0.2.sql => file-toolkit-gauss-starter/sql/file-toolkit-gauss@1.0.2.sql (100%) create mode 100644 file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/configure/FileGaussAutoConfigure.java create mode 100644 file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml create mode 100644 file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml create mode 100644 file-toolkit-gauss-starter/src/main/resources/META-INF/spring.factories rename file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/{impl/MinioFileService.java => FileStoreService.java} (88%) create mode 100644 file-toolkit-postgres-starter/pom.xml create mode 100644 file-toolkit-postgres-starter/sql/file-toolkit-postgres@1.0.2.sql create mode 100644 file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/configure/FilePostgresAutoConfigure.java rename {file-toolkit-service-starter => file-toolkit-postgres-starter}/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml (100%) rename {file-toolkit-service-starter => file-toolkit-postgres-starter}/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml (100%) create mode 100644 file-toolkit-postgres-starter/src/main/resources/META-INF/spring.factories create mode 100644 file-toolkit-service-starter/sql/file-toolkit@1.0.2.sql diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/AsyncFileService.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/handle/FileStoreService.java similarity index 88% rename from file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/AsyncFileService.java rename to file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/handle/FileStoreService.java index 0ffc7b6..f2fec9a 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/AsyncFileService.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/handle/FileStoreService.java @@ -1,4 +1,4 @@ -package io.github.nichetoolkit.file.service; +package io.github.nichetoolkit.file.handle; import io.github.nichetoolkit.rest.RestException; import org.springframework.scheduling.annotation.Async; @@ -8,11 +8,11 @@ import java.util.List; /** - *

AsyncFileService

+ *

FileStoreService

* @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public abstract class AsyncFileService { +public abstract class FileStoreService { @Async abstract public void removeAll(List fileIdList) throws RestException; diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java new file mode 100644 index 0000000..22df1f5 --- /dev/null +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java @@ -0,0 +1,51 @@ +package io.github.nichetoolkit.file.helper; + +import io.github.nichetoolkit.file.error.FileErrorStatus; +import io.github.nichetoolkit.file.handle.FileStoreService; +import io.github.nichetoolkit.rest.RestException; +import io.github.nichetoolkit.rest.error.natives.FileErrorException; +import io.github.nichetoolkit.rest.util.StreamUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.io.IOException; +import java.io.InputStream; + +/** + *

FileHandleHelper

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Component +public class FileHandleHelper implements InitializingBean { + + @Resource(type = FileStoreService.class) + private FileStoreService fileStoreService; + + private static FileHandleHelper INSTANCE = null; + + public static FileHandleHelper getInstance() { + return INSTANCE; + } + + @Override + public void afterPropertiesSet() throws Exception { + INSTANCE = this; + } + + public static FileStoreService fileStoreService() { + return INSTANCE.fileStoreService; + } + + public static void writeFile(String objectName, String itemFilePath) throws RestException { + try (InputStream inputStream = INSTANCE.fileStoreService.getById(objectName)) { + StreamUtils.write(itemFilePath, inputStream); + } catch (IOException exception) { + log.error("the file service download has error: {}", exception.getMessage()); + throw new FileErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR); + } + } +} diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHelper.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHandleHelper.java similarity index 99% rename from file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHelper.java rename to file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHandleHelper.java index fb81785..058bff0 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHelper.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/ImageHandleHelper.java @@ -14,7 +14,7 @@ * @author Cyan (snow22314@outlook.com) * @version v1.0.0 */ -public class ImageHelper { +public class ImageHandleHelper { public static void write(BufferedImage bufferedImage, OutputStream outputStream) throws ImageWriteException { try { diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java index 52ebf0e..f804eff 100644 --- a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java +++ b/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/util/ImageUtils.java @@ -4,13 +4,12 @@ import io.github.nichetoolkit.file.error.ImageReadException; import io.github.nichetoolkit.file.error.ImageTransferException; import io.github.nichetoolkit.file.error.ImageWriteException; -import io.github.nichetoolkit.file.helper.ImageHelper; +import io.github.nichetoolkit.file.helper.ImageHandleHelper; import io.github.nichetoolkit.rest.util.GeneralUtils; import io.github.nichetoolkit.rest.util.StreamUtils; import lombok.extern.slf4j.Slf4j; import net.coobird.thumbnailator.Thumbnails; -import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; @@ -31,7 +30,7 @@ public class ImageUtils { public static void write(BufferedImage bufferedImage, OutputStream outputStream) { try { - ImageHelper.write(bufferedImage, outputStream); + ImageHandleHelper.write(bufferedImage, outputStream); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as outputStream!", exception); exception.printStackTrace(); @@ -40,7 +39,7 @@ public static void write(BufferedImage bufferedImage, OutputStream outputStream) public static void write(BufferedImage bufferedImage, String imagePath) { try { - ImageHelper.write(bufferedImage, imagePath); + ImageHandleHelper.write(bufferedImage, imagePath); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as file!", exception); exception.printStackTrace(); @@ -49,7 +48,7 @@ public static void write(BufferedImage bufferedImage, String imagePath) { public static void write(BufferedImage bufferedImage, File file) { try { - ImageHelper.write(bufferedImage, "png", file); + ImageHandleHelper.write(bufferedImage, "png", file); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as file!", exception); exception.printStackTrace(); @@ -59,7 +58,7 @@ public static void write(BufferedImage bufferedImage, File file) { public static void write(BufferedImage bufferedImage, String formatName, OutputStream outputStream) { try { - ImageHelper.write(bufferedImage, formatName, outputStream); + ImageHandleHelper.write(bufferedImage, formatName, outputStream); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as outputStream!", exception); exception.printStackTrace(); @@ -68,7 +67,7 @@ public static void write(BufferedImage bufferedImage, String formatName, OutputS public static void write(BufferedImage bufferedImage, String formatName, String imagePath) { try { - ImageHelper.write(bufferedImage, formatName, new File(imagePath)); + ImageHandleHelper.write(bufferedImage, formatName, new File(imagePath)); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to write as file!", exception); exception.printStackTrace(); @@ -77,7 +76,7 @@ public static void write(BufferedImage bufferedImage, String formatName, String public static void write(BufferedImage bufferedImage, String formatName, File file) { try { - ImageHelper.write(bufferedImage, formatName, file); + ImageHandleHelper.write(bufferedImage, formatName, file); } catch (ImageWriteException exception) { log.error("An error occurred during bufferedImage to read as file!", exception); exception.printStackTrace(); @@ -86,7 +85,7 @@ public static void write(BufferedImage bufferedImage, String formatName, File fi public static BufferedImage read(InputStream inputStream) { try { - return ImageHelper.read(inputStream); + return ImageHandleHelper.read(inputStream); } catch (ImageReadException exception) { log.error("An error occurred during inputStream to read as BufferedImage!", exception); exception.printStackTrace(); @@ -96,7 +95,7 @@ public static BufferedImage read(InputStream inputStream) { public static BufferedImage read(String imagePath) { try { - return ImageHelper.read(imagePath); + return ImageHandleHelper.read(imagePath); } catch (ImageReadException exception) { log.error("An error occurred during file to read as BufferedImage!", exception); exception.printStackTrace(); @@ -107,7 +106,7 @@ public static BufferedImage read(String imagePath) { public static BufferedImage read(File file) { try { - return ImageHelper.read(file); + return ImageHandleHelper.read(file); } catch (ImageReadException exception) { log.error("An error occurred during file to write as BufferedImage!", exception); exception.printStackTrace(); @@ -117,7 +116,7 @@ public static BufferedImage read(File file) { public static InputStream inputStream(BufferedImage bufferedImage) { try { - return ImageHelper.inputStream(bufferedImage); + return ImageHandleHelper.inputStream(bufferedImage); } catch (ImageTransferException exception) { log.error("An error occurred during bufferedImage to transfer as inputStream!", exception); exception.printStackTrace(); @@ -127,7 +126,7 @@ public static InputStream inputStream(BufferedImage bufferedImage) { public static byte[] bytes(BufferedImage bufferedImage) { try { - return ImageHelper.bytes(bufferedImage); + return ImageHandleHelper.bytes(bufferedImage); } catch (ImageTransferException exception) { log.error("An error occurred during bufferedImage to transfer as inputStream!", exception); exception.printStackTrace(); diff --git a/file-toolkit-gauss-starter/pom.xml b/file-toolkit-gauss-starter/pom.xml new file mode 100644 index 0000000..0cf85f6 --- /dev/null +++ b/file-toolkit-gauss-starter/pom.xml @@ -0,0 +1,224 @@ + + + 4.0.0 + + io.github.nichetoolkit + file-toolkit-parent + 1.0.4-SNAPSHOT + + + file-toolkit-gauss-starter + 1.0.4-SNAPSHOT + file-toolkit-gauss-starter + jar + File toolkit service project for Spring Boot + https://github.com/NicheToolkit/file-toolkit/tree/master/file-toolkit-gauss-starter + + + 1.8 + UTF-8 + UTF-8 + + + + + The Apache License (Apache-2.0) + https://github.com/NicheToolkit/file-toolkit/blob/master/LICENSE + + + + + + Cyan + snow22314@outlook.com + + + + + scm:git:git@github.com:NicheToolkit/file-toolkit.git + scm:git:git@github.com:NicheToolkit/file-toolkit.git + git@github.com:NicheToolkit/file-toolkit.git + + + + + sonatype-nexus-snapshot + https://s01.oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-deploy + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + io.github.nichetoolkit + file-toolkit-service-starter + ${file-toolkit.version} + + + + tk.mybatis + mapper + ${tk-mybatis-mapper.version} + + + + tk.mybatis + mapper-spring-boot-starter + ${tk-mybatis-starter.version} + + + + + + + + sonatype-nexus-central + sonatype maven centrals + https://oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-release + sonatype maven releases + https://s01.oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-snapshot + sonatype maven snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + false + daily + + + true + always + + + + + + + ${project.artifactId} + + + false + src/main/resources + + + src/main/java + + **/*.xml + + false + + + + + org.apache.maven.plugins + maven-source-plugin + ${source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc-plugin.version} + + true + UTF-8 + UTF-8 + UTF-8 + + + + attach-javadocs + + jar + + package + + -Xdoclint:none + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-plugin.version} + true + + sonatype-nexus-central + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-release-plugin + ${release-plugin.version} + + v@{project.version} + true + true + sonatype-nexus-release + deploy + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + utf-8 + + + + + + diff --git a/file-toolkit-service-starter/sql/file-toolkit-postgres@1.0.2.sql b/file-toolkit-gauss-starter/sql/file-toolkit-gauss@1.0.2.sql similarity index 100% rename from file-toolkit-service-starter/sql/file-toolkit-postgres@1.0.2.sql rename to file-toolkit-gauss-starter/sql/file-toolkit-gauss@1.0.2.sql diff --git a/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/configure/FileGaussAutoConfigure.java b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/configure/FileGaussAutoConfigure.java new file mode 100644 index 0000000..10c19ca --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/configure/FileGaussAutoConfigure.java @@ -0,0 +1,22 @@ +package io.github.nichetoolkit.file.configure; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import tk.mybatis.spring.annotation.MapperScan; + +/** + *

FileServiceAutoConfigure

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Configuration +@ComponentScan(basePackages = {"io.github.nichetoolkit.file"}) +@MapperScan(basePackages = {"io.github.nichetoolkit.file.mapper"}) +public class FileGaussAutoConfigure { + + public FileGaussAutoConfigure() { + log.debug("================= file-gauss-auto-config initiated ! ==================="); + } +} diff --git a/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml new file mode 100644 index 0000000..4973bbc --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + id, file_index_id, chunk_index, chunk_size, chunk_start, chunk_end, chunk_md5, is_last_chunk, chunk_time, + start_time, end_time, operate + + + + c.id, c.file_index_id, c.chunk_index, c.chunk_size, c.chunk_start, c.chunk_end, c.chunk_md5, c.is_last_chunk, + c.chunk_time, c.start_time, c.end_time, c.operate + + + + INSERT INTO file_chunk ( + + ) + VALUES ( + #{entity.id}, + #{entity.fileId}, + #{entity.chunkIndex}, + #{entity.chunkSize}, + #{entity.chunkStart}, + #{entity.chunkEnd}, + #{entity.chunkMd5}, + #{entity.isLastChunk}, + now(), + #{entity.startTime}, + #{entity.endTime}, + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) ON DUPLICATE KEY UPDATE + file_index_id = CASE WHEN EXCLUDED.file_index_id IS NOT NULL THEN EXCLUDED.file_index_id ELSE + file_chunk.file_index_id END, + chunk_index = CASE WHEN EXCLUDED.chunk_index IS NOT NULL THEN EXCLUDED.chunk_index ELSE + file_chunk.chunk_index END, + chunk_size = CASE WHEN EXCLUDED.chunk_size IS NOT NULL THEN EXCLUDED.chunk_size ELSE file_chunk.chunk_size + END, + chunk_start = CASE WHEN EXCLUDED.chunk_start IS NOT NULL THEN EXCLUDED.chunk_start ELSE + file_chunk.chunk_start END, + chunk_end = CASE WHEN EXCLUDED.chunk_end IS NOT NULL THEN EXCLUDED.chunk_end ELSE file_chunk.chunk_end END, + chunk_md5 = CASE WHEN EXCLUDED.chunk_md5 IS NOT NULL THEN EXCLUDED.chunk_md5 ELSE file_chunk.chunk_md5 END, + is_last_chunk = CASE WHEN EXCLUDED.is_last_chunk IS NOT NULL THEN EXCLUDED.is_last_chunk ELSE + file_chunk.is_last_chunk END, + chunk_time = now(), + start_time = CASE WHEN EXCLUDED.start_time IS NOT NULL THEN EXCLUDED.start_time ELSE file_chunk.start_time + END, + end_time = CASE WHEN EXCLUDED.end_time IS NOT NULL THEN EXCLUDED.end_time ELSE file_chunk.end_time END + + + + INSERT INTO file_chunk ( + + ) + VALUES + + ( + #{entity.id}, + #{entity.fileId}, + #{entity.chunkIndex}, + #{entity.chunkSize}, + #{entity.chunkStart}, + #{entity.chunkEnd}, + #{entity.chunkMd5}, + #{entity.isLastChunk}, + now(), + #{entity.startTime}, + #{entity.endTime}, + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) + + ON DUPLICATE KEY UPDATE + file_index_id = CASE WHEN EXCLUDED.file_index_id IS NOT NULL THEN EXCLUDED.file_index_id ELSE + file_chunk.file_index_id END, + chunk_index = CASE WHEN EXCLUDED.chunk_index IS NOT NULL THEN EXCLUDED.chunk_index ELSE + file_chunk.chunk_index END, + chunk_size = CASE WHEN EXCLUDED.chunk_size IS NOT NULL THEN EXCLUDED.chunk_size ELSE file_chunk.chunk_size + END, + chunk_start = CASE WHEN EXCLUDED.chunk_start IS NOT NULL THEN EXCLUDED.chunk_start ELSE + file_chunk.chunk_start END, + chunk_end = CASE WHEN EXCLUDED.chunk_end IS NOT NULL THEN EXCLUDED.chunk_end ELSE file_chunk.chunk_end END, + chunk_md5 = CASE WHEN EXCLUDED.chunk_md5 IS NOT NULL THEN EXCLUDED.chunk_md5 ELSE file_chunk.chunk_md5 END, + is_last_chunk = CASE WHEN EXCLUDED.is_last_chunk IS NOT NULL THEN EXCLUDED.is_last_chunk ELSE + file_chunk.is_last_chunk END, + chunk_time = now(), + start_time = CASE WHEN EXCLUDED.start_time IS NOT NULL THEN EXCLUDED.start_time ELSE file_chunk.start_time + END, + end_time = CASE WHEN EXCLUDED.end_time IS NOT NULL THEN EXCLUDED.end_time ELSE file_chunk.end_time END + + + + UPDATE file_chunk + SET operate = ${operate} + WHERE id IN + + #{id} + + + + + UPDATE file_chunk + SET operate = ${operate} + WHERE id = #{id} + + + + UPDATE file_chunk + SET operate = 32 + WHERE id IN + + #{id} + + + + + UPDATE file_chunk + SET operate = 32 + WHERE id = #{id} + + + + DELETE FROM file_chunk + WHERE id IN + + #{id} + + + + + DELETE FROM file_chunk + WHERE id = #{id} + + + + + + + + + + DELETE FROM file_chunk + WHERE 1=1 + + ${whereSql} + + + + + + + + + + + + + diff --git a/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml new file mode 100644 index 0000000..d495ff2 --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, user_id, original_filename, filename, alias, suffix, file_md5, + file_size, file_type, is_finish, is_condense, is_slice, slice_size, is_merge, etag, version_id, headers, + properties, create_time, update_time, operate + + + + INSERT INTO file_index ( + + ) + VALUES ( + #{entity.id}, + #{entity.userId}, + #{entity.originalFilename}, + #{entity.filename}, + #{entity.alias}, + #{entity.suffix}, + #{entity.fileMd5}, + #{entity.fileSize}, + #{entity.fileType}, + #{entity.isFinish}, + #{entity.isCondense}, + #{entity.isSlice}, + #{entity.sliceSize}, + #{entity.isMerge}, + #{entity.etag}, + #{entity.versionId}, + #{entity.headers}, + #{entity.properties}, + now(), + now(), + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) ON DUPLICATE KEY UPDATE + user_id = CASE WHEN EXCLUDED.user_id IS NOT NULL THEN EXCLUDED.user_id ELSE file_index.user_id END, + original_filename = CASE WHEN EXCLUDED.original_filename IS NOT NULL THEN EXCLUDED.original_filename ELSE + file_index.original_filename END, + filename = CASE WHEN EXCLUDED.filename IS NOT NULL THEN EXCLUDED.filename ELSE file_index.filename END, + alias = CASE WHEN EXCLUDED.alias IS NOT NULL THEN EXCLUDED.alias ELSE file_index.alias END, + suffix = CASE WHEN EXCLUDED.suffix IS NOT NULL THEN EXCLUDED.suffix ELSE file_index.suffix END, + file_md5 = CASE WHEN EXCLUDED.file_md5 IS NOT NULL THEN EXCLUDED.file_md5 ELSE file_index.file_md5 END, + file_size = CASE WHEN EXCLUDED.file_size IS NOT NULL THEN EXCLUDED.file_size ELSE file_index.file_size END, + file_type = CASE WHEN EXCLUDED.file_type IS NOT NULL THEN EXCLUDED.file_type ELSE file_index.file_type END, + is_finish = CASE WHEN EXCLUDED.is_finish IS NOT NULL THEN EXCLUDED.is_finish ELSE file_index.is_finish END, + is_condense = CASE WHEN EXCLUDED.is_condense IS NOT NULL THEN EXCLUDED.is_condense ELSE + file_index.is_condense END, + is_slice = CASE WHEN EXCLUDED.is_slice IS NOT NULL THEN EXCLUDED.is_slice ELSE file_index.is_slice END, + slice_size = CASE WHEN EXCLUDED.slice_size IS NOT NULL THEN EXCLUDED.slice_size ELSE file_index.slice_size + END, + is_merge = CASE WHEN EXCLUDED.is_merge IS NOT NULL THEN EXCLUDED.is_merge ELSE file_index.is_merge END, + etag = CASE WHEN EXCLUDED.etag IS NOT NULL THEN EXCLUDED.etag ELSE file_index.etag END, + version_id = CASE WHEN EXCLUDED.version_id IS NOT NULL THEN EXCLUDED.version_id ELSE file_index.version_id + END, + headers = CASE WHEN EXCLUDED.headers IS NOT NULL THEN EXCLUDED.headers ELSE file_index.headers END, + properties = CASE WHEN EXCLUDED.properties IS NOT NULL THEN EXCLUDED.properties ELSE file_index.properties + END, + update_time = now() + + + + INSERT INTO file_index ( + + ) + VALUES + + ( + #{entity.id}, + #{entity.userId}, + #{entity.originalFilename}, + #{entity.filename}, + #{entity.alias}, + #{entity.suffix}, + #{entity.fileMd5}, + #{entity.fileSize}, + #{entity.fileType}, + #{entity.isFinish}, + #{entity.isCondense}, + #{entity.isSlice}, + #{entity.sliceSize}, + #{entity.isMerge}, + #{entity.etag}, + #{entity.versionId}, + #{entity.headers}, + #{entity.properties}, + now(), + now(), + CASE WHEN #{entity.operate}::INT4 IS NULL THEN 1 ELSE #{entity.operate} END + ) + + ON DUPLICATE KEY UPDATE + user_id = CASE WHEN EXCLUDED.user_id IS NOT NULL THEN EXCLUDED.user_id ELSE file_index.user_id END, + original_filename = CASE WHEN EXCLUDED.original_filename IS NOT NULL THEN EXCLUDED.original_filename ELSE + file_index.original_filename END, + filename = CASE WHEN EXCLUDED.filename IS NOT NULL THEN EXCLUDED.filename ELSE file_index.filename END, + alias = CASE WHEN EXCLUDED.alias IS NOT NULL THEN EXCLUDED.alias ELSE file_index.alias END, + suffix = CASE WHEN EXCLUDED.suffix IS NOT NULL THEN EXCLUDED.suffix ELSE file_index.suffix END, + file_md5 = CASE WHEN EXCLUDED.file_md5 IS NOT NULL THEN EXCLUDED.file_md5 ELSE file_index.file_md5 END, + file_size = CASE WHEN EXCLUDED.file_size IS NOT NULL THEN EXCLUDED.file_size ELSE file_index.file_size END, + file_type = CASE WHEN EXCLUDED.file_type IS NOT NULL THEN EXCLUDED.file_type ELSE file_index.file_type END, + is_finish = CASE WHEN EXCLUDED.is_finish IS NOT NULL THEN EXCLUDED.is_finish ELSE file_index.is_finish END, + is_condense = CASE WHEN EXCLUDED.is_condense IS NOT NULL THEN EXCLUDED.is_condense ELSE + file_index.is_condense END, + is_slice = CASE WHEN EXCLUDED.is_slice IS NOT NULL THEN EXCLUDED.is_slice ELSE file_index.is_slice END, + slice_size = CASE WHEN EXCLUDED.slice_size IS NOT NULL THEN EXCLUDED.slice_size ELSE file_index.slice_size + END, + is_merge = CASE WHEN EXCLUDED.is_merge IS NOT NULL THEN EXCLUDED.is_merge ELSE file_index.is_merge END, + etag = CASE WHEN EXCLUDED.etag IS NOT NULL THEN EXCLUDED.etag ELSE file_index.etag END, + version_id = CASE WHEN EXCLUDED.version_id IS NOT NULL THEN EXCLUDED.version_id ELSE file_index.version_id + END, + headers = CASE WHEN EXCLUDED.headers IS NOT NULL THEN EXCLUDED.headers ELSE file_index.headers END, + properties = CASE WHEN EXCLUDED.properties IS NOT NULL THEN EXCLUDED.properties ELSE file_index.properties + END, + update_time = now() + + + + UPDATE file_index + SET operate = ${operate} + WHERE id IN + + #{id} + + + + + UPDATE file_index + SET operate = ${operate} + WHERE id = #{id} + + + + UPDATE file_index + SET operate = 32 + WHERE id IN + + #{id} + + + + + UPDATE file_index + SET operate = 32 + WHERE id = #{id} + + + + DELETE FROM file_index + WHERE id IN + + #{id} + + + + + DELETE + FROM file_index + WHERE id = #{id} + + + + + + + + + + DELETE FROM file_index + WHERE 1=1 + + ${whereSql} + + + + + + + UPDATE file_index + SET is_finish = true, + slice_size = ${sliceSize} + WHERE id = ${id} + AND operate NOT IN (16,32) + AND is_slice = true + + + diff --git a/file-toolkit-gauss-starter/src/main/resources/META-INF/spring.factories b/file-toolkit-gauss-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..e0a2f16 --- /dev/null +++ b/file-toolkit-gauss-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.github.nichetoolkit.file.configure.FileGaussAutoConfigure \ No newline at end of file diff --git a/file-toolkit-hdfs-starter/pom.xml b/file-toolkit-hdfs-starter/pom.xml index c1b7729..c99d1d3 100644 --- a/file-toolkit-hdfs-starter/pom.xml +++ b/file-toolkit-hdfs-starter/pom.xml @@ -56,7 +56,7 @@ io.github.nichetoolkit - file-toolkit-service-starter + file-toolkit-postgres-starter ${file-toolkit.version} diff --git a/file-toolkit-minio-starter/pom.xml b/file-toolkit-minio-starter/pom.xml index 2b75615..364dece 100644 --- a/file-toolkit-minio-starter/pom.xml +++ b/file-toolkit-minio-starter/pom.xml @@ -62,7 +62,7 @@ io.github.nichetoolkit - file-toolkit-service-starter + file-toolkit-common-starter ${file-toolkit.version} diff --git a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java index 6dd848b..37f0a17 100644 --- a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java +++ b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/configure/FileMinioStarterAutoConfigure.java @@ -7,7 +7,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import tk.mybatis.spring.annotation.MapperScan; /** *

FileMinioStarterAutoConfigure

@@ -16,8 +15,6 @@ */ @Slf4j @Configuration -@org.mybatis.spring.annotation.MapperScan("io.github.nichetoolkit.file.mapper") -@MapperScan("io.github.nichetoolkit.file.mapper") @ComponentScan(basePackages = {"io.github.nichetoolkit.file"}) public class FileMinioStarterAutoConfigure { public FileMinioStarterAutoConfigure() { diff --git a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/impl/MinioFileService.java b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/FileStoreService.java similarity index 88% rename from file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/impl/MinioFileService.java rename to file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/FileStoreService.java index ed31971..8470b6d 100644 --- a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/impl/MinioFileService.java +++ b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/FileStoreService.java @@ -1,7 +1,7 @@ -package io.github.nichetoolkit.file.service.impl; +package io.github.nichetoolkit.file.service; import io.github.nichetoolkit.file.minio.MinioUtils; -import io.github.nichetoolkit.file.service.AsyncFileService; +import io.github.nichetoolkit.file.handle.FileHandleService; import io.github.nichetoolkit.rest.RestException; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -16,7 +16,7 @@ * @version v1.0.0 */ @Service -public class MinioFileService extends AsyncFileService { +public class MinioFileService extends FileHandleService { @Override @Async public void removeAll(List fileIdList) throws RestException { diff --git a/file-toolkit-postgres-starter/pom.xml b/file-toolkit-postgres-starter/pom.xml new file mode 100644 index 0000000..1d85195 --- /dev/null +++ b/file-toolkit-postgres-starter/pom.xml @@ -0,0 +1,224 @@ + + + 4.0.0 + + io.github.nichetoolkit + file-toolkit-parent + 1.0.4-SNAPSHOT + + + file-toolkit-postgres-starter + 1.0.4-SNAPSHOT + file-toolkit-postgres-starter + jar + File toolkit postgres project for Spring Boot + https://github.com/NicheToolkit/file-toolkit/tree/master/file-toolkit-postgres-starter + + + 1.8 + UTF-8 + UTF-8 + + + + + The Apache License (Apache-2.0) + https://github.com/NicheToolkit/file-toolkit/blob/master/LICENSE + + + + + + Cyan + snow22314@outlook.com + + + + + scm:git:git@github.com:NicheToolkit/file-toolkit.git + scm:git:git@github.com:NicheToolkit/file-toolkit.git + git@github.com:NicheToolkit/file-toolkit.git + + + + + sonatype-nexus-snapshot + https://s01.oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-deploy + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + io.github.nichetoolkit + file-toolkit-service-starter + ${file-toolkit.version} + + + + tk.mybatis + mapper + ${tk-mybatis-mapper.version} + + + + tk.mybatis + mapper-spring-boot-starter + ${tk-mybatis-starter.version} + + + + + + + + sonatype-nexus-central + sonatype maven centrals + https://oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-release + sonatype maven releases + https://s01.oss.sonatype.org/content/repositories/releases/ + + true + always + + + false + daily + + + + + sonatype-nexus-snapshot + sonatype maven snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + false + daily + + + true + always + + + + + + + ${project.artifactId} + + + false + src/main/resources + + + src/main/java + + **/*.xml + + false + + + + + org.apache.maven.plugins + maven-source-plugin + ${source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc-plugin.version} + + true + UTF-8 + UTF-8 + UTF-8 + + + + attach-javadocs + + jar + + package + + -Xdoclint:none + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-plugin.version} + true + + sonatype-nexus-central + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-release-plugin + ${release-plugin.version} + + v@{project.version} + true + true + sonatype-nexus-release + deploy + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + utf-8 + + + + + + diff --git a/file-toolkit-postgres-starter/sql/file-toolkit-postgres@1.0.2.sql b/file-toolkit-postgres-starter/sql/file-toolkit-postgres@1.0.2.sql new file mode 100644 index 0000000..6f03a56 --- /dev/null +++ b/file-toolkit-postgres-starter/sql/file-toolkit-postgres@1.0.2.sql @@ -0,0 +1,135 @@ +-- ---------------------------- +-- Table structure for file +-- ---------------------------- +DROP TABLE IF EXISTS "public"."file_index"; +CREATE TABLE "public"."file_index" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "user_id" VARCHAR(64) COLLATE "pg_catalog"."default", + "original_filename" VARCHAR(512) COLLATE "pg_catalog"."default", + "filename" VARCHAR(256) COLLATE "pg_catalog"."default", + "alias" VARCHAR(256) COLLATE "pg_catalog"."default", + "suffix" VARCHAR(32) COLLATE "pg_catalog"."default", + "file_md5" VARCHAR(2048) COLLATE "pg_catalog"."default", + "file_size" INT8, + "file_type" INT2, + "is_finish" BOOLEAN DEFAULT TRUE, + "is_condense" BOOLEAN DEFAULT FALSE, + "is_slice" BOOLEAN DEFAULT FALSE, + "slice_size" INT4, + "is_merge" BOOLEAN DEFAULT TRUE, + "etag" VARCHAR(512) COLLATE "pg_catalog"."default", + "version_id" VARCHAR(512) COLLATE "pg_catalog"."default", + "headers" jsonb, + "properties" jsonb, + "update_time" TIMESTAMPTZ, + "create_time" TIMESTAMPTZ, + "operate" INT4 +); +COMMENT ON COLUMN "public"."file_index"."id" IS '文件id'; +COMMENT ON COLUMN "public"."file_index"."user_id" IS '文件存储用户id'; +COMMENT ON COLUMN "public"."file_index"."original_filename" IS '文件源名称'; +COMMENT ON COLUMN "public"."file_index"."filename" IS '文件名称'; +COMMENT ON COLUMN "public"."file_index"."alias" IS '文件别名'; +COMMENT ON COLUMN "public"."file_index"."suffix" IS '文件扩展名'; +COMMENT ON COLUMN "public"."file_index"."file_md5" IS '文件md5校验'; +COMMENT ON COLUMN "public"."file_index"."file_size" IS '文件大小'; +COMMENT ON COLUMN "public"."file_index"."file_type" IS '文件类型'; +COMMENT ON COLUMN "public"."file_index"."is_finish" IS '文件分片上传完成状态'; +COMMENT ON COLUMN "public"."file_index"."is_condense" IS '文件压缩状态,暂时只对图片生效'; +COMMENT ON COLUMN "public"."file_index"."is_slice" IS '文件分片状态'; +COMMENT ON COLUMN "public"."file_index"."slice_size" IS '文件分片总数'; +COMMENT ON COLUMN "public"."file_index"."is_merge" IS '文件分片是否合并'; +COMMENT ON COLUMN "public"."file_index"."etag" IS '文件minio存储hash校验'; +COMMENT ON COLUMN "public"."file_index"."version_id" IS '文件minio存储版本'; +COMMENT ON COLUMN "public"."file_index"."headers" IS '文件minio存储请求头'; +COMMENT ON COLUMN "public"."file_index"."properties" IS '文件附属属性'; +COMMENT ON COLUMN "public"."file_index"."update_time" IS '文件更新时间'; +COMMENT ON COLUMN "public"."file_index"."create_time" IS '文件创建时间'; +COMMENT ON COLUMN "public"."file_index"."operate" IS '文件操作'; + +-- ---------------------------- +-- Primary Key structure for table file +-- ---------------------------- +ALTER TABLE "public"."file_index" + ADD CONSTRAINT "PK_FILE_INDEX_ID" PRIMARY KEY ("id"); + +CREATE INDEX "IDX_FILE_INDEX_USER_ID" ON "public"."file_index" USING btree ( + "user_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILENAME" ON "public"."file_index" USING btree ( + "filename" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILE_TYPE" ON "public"."file_index" USING btree ( + "file_type" "pg_catalog"."int2_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_FINISH" ON "public"."file_index" USING btree ( + "is_finish" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_CONDENSE" ON "public"."file_index" USING btree ( + "is_condense" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_SLICE" ON "public"."file_index" USING btree ( + "is_slice" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_MERGE" ON "public"."file_index" USING btree ( + "is_merge" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_OPERATE" ON "public"."file_index" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +DROP TABLE IF EXISTS "public"."file_chunk"; +CREATE TABLE "public"."file_chunk" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "file_index_id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "chunk_index" INT4 NOT NULL, + "chunk_size" INT8, + "chunk_start" INT8, + "chunk_end" INT8, + "chunk_md5" VARCHAR(1024) COLLATE "pg_catalog"."default", + "is_last_chunk" BOOLEAN DEFAULT FALSE, + "chunk_time" TIMESTAMPTZ, + "start_time" TIMESTAMPTZ, + "end_time" TIMESTAMPTZ, + "operate" INT4 +); + +COMMENT ON COLUMN "public"."file_chunk"."id" IS '文件分片id'; +COMMENT ON COLUMN "public"."file_chunk"."file_index_id" IS '文件id'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_index" IS '分片编号'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_size" IS '分片长度'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_start" IS '分片起始位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_end" IS '分片结束位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_md5" IS '分片md5校验'; +COMMENT ON COLUMN "public"."file_chunk"."is_last_chunk" IS '是否最后一片数据 1:否,2:是'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_time" IS '分片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."start_time" IS '第一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."end_time" IS '最后一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."operate" IS '文件操作'; + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "PK_FILE_CHUNK_ID" PRIMARY KEY ("id"); + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "UK_FILE_CHUNK_FILE_INDEX_ID_CHUNK_INDEX" UNIQUE ("file_index_id", "chunk_index"); + +CREATE INDEX "IDX_FILE_CHUNK_FILE_INDEX_ID" ON "public"."file_chunk" USING btree ( + "file_index_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_CHUNK_INDEX" ON "public"."file_chunk" USING btree ( + "chunk_index" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_OPERATE" ON "public"."file_chunk" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); \ No newline at end of file diff --git a/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/configure/FilePostgresAutoConfigure.java b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/configure/FilePostgresAutoConfigure.java new file mode 100644 index 0000000..c37e0b1 --- /dev/null +++ b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/configure/FilePostgresAutoConfigure.java @@ -0,0 +1,22 @@ +package io.github.nichetoolkit.file.configure; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import tk.mybatis.spring.annotation.MapperScan; + +/** + *

FilePostgresAutoConfigure

+ * @author Cyan (snow22314@outlook.com) + * @version v1.0.0 + */ +@Slf4j +@Configuration +@ComponentScan(basePackages = {"io.github.nichetoolkit.file"}) +@MapperScan(basePackages = {"io.github.nichetoolkit.file.mapper"}) +public class FilePostgresAutoConfigure { + + public FilePostgresAutoConfigure() { + log.debug("================= file-postgres-auto-config initiated ! ==================="); + } +} diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml similarity index 100% rename from file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml rename to file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileChunkMapper.xml diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml b/file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml similarity index 100% rename from file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml rename to file-toolkit-postgres-starter/src/main/java/io/github/nichetoolkit/file/mapper/FileIndexMapper.xml diff --git a/file-toolkit-postgres-starter/src/main/resources/META-INF/spring.factories b/file-toolkit-postgres-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..88fc3b0 --- /dev/null +++ b/file-toolkit-postgres-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.github.nichetoolkit.file.configure.FilePostgresAutoConfigure \ No newline at end of file diff --git a/file-toolkit-service-starter/pom.xml b/file-toolkit-service-starter/pom.xml index 18c1e2b..c4b40e1 100644 --- a/file-toolkit-service-starter/pom.xml +++ b/file-toolkit-service-starter/pom.xml @@ -84,12 +84,6 @@ ${tk-mybatis-mapper.version} - - tk.mybatis - mapper-spring-boot-starter - ${tk-mybatis-starter.version} - - diff --git a/file-toolkit-service-starter/sql/file-toolkit@1.0.2.sql b/file-toolkit-service-starter/sql/file-toolkit@1.0.2.sql new file mode 100644 index 0000000..6f03a56 --- /dev/null +++ b/file-toolkit-service-starter/sql/file-toolkit@1.0.2.sql @@ -0,0 +1,135 @@ +-- ---------------------------- +-- Table structure for file +-- ---------------------------- +DROP TABLE IF EXISTS "public"."file_index"; +CREATE TABLE "public"."file_index" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "user_id" VARCHAR(64) COLLATE "pg_catalog"."default", + "original_filename" VARCHAR(512) COLLATE "pg_catalog"."default", + "filename" VARCHAR(256) COLLATE "pg_catalog"."default", + "alias" VARCHAR(256) COLLATE "pg_catalog"."default", + "suffix" VARCHAR(32) COLLATE "pg_catalog"."default", + "file_md5" VARCHAR(2048) COLLATE "pg_catalog"."default", + "file_size" INT8, + "file_type" INT2, + "is_finish" BOOLEAN DEFAULT TRUE, + "is_condense" BOOLEAN DEFAULT FALSE, + "is_slice" BOOLEAN DEFAULT FALSE, + "slice_size" INT4, + "is_merge" BOOLEAN DEFAULT TRUE, + "etag" VARCHAR(512) COLLATE "pg_catalog"."default", + "version_id" VARCHAR(512) COLLATE "pg_catalog"."default", + "headers" jsonb, + "properties" jsonb, + "update_time" TIMESTAMPTZ, + "create_time" TIMESTAMPTZ, + "operate" INT4 +); +COMMENT ON COLUMN "public"."file_index"."id" IS '文件id'; +COMMENT ON COLUMN "public"."file_index"."user_id" IS '文件存储用户id'; +COMMENT ON COLUMN "public"."file_index"."original_filename" IS '文件源名称'; +COMMENT ON COLUMN "public"."file_index"."filename" IS '文件名称'; +COMMENT ON COLUMN "public"."file_index"."alias" IS '文件别名'; +COMMENT ON COLUMN "public"."file_index"."suffix" IS '文件扩展名'; +COMMENT ON COLUMN "public"."file_index"."file_md5" IS '文件md5校验'; +COMMENT ON COLUMN "public"."file_index"."file_size" IS '文件大小'; +COMMENT ON COLUMN "public"."file_index"."file_type" IS '文件类型'; +COMMENT ON COLUMN "public"."file_index"."is_finish" IS '文件分片上传完成状态'; +COMMENT ON COLUMN "public"."file_index"."is_condense" IS '文件压缩状态,暂时只对图片生效'; +COMMENT ON COLUMN "public"."file_index"."is_slice" IS '文件分片状态'; +COMMENT ON COLUMN "public"."file_index"."slice_size" IS '文件分片总数'; +COMMENT ON COLUMN "public"."file_index"."is_merge" IS '文件分片是否合并'; +COMMENT ON COLUMN "public"."file_index"."etag" IS '文件minio存储hash校验'; +COMMENT ON COLUMN "public"."file_index"."version_id" IS '文件minio存储版本'; +COMMENT ON COLUMN "public"."file_index"."headers" IS '文件minio存储请求头'; +COMMENT ON COLUMN "public"."file_index"."properties" IS '文件附属属性'; +COMMENT ON COLUMN "public"."file_index"."update_time" IS '文件更新时间'; +COMMENT ON COLUMN "public"."file_index"."create_time" IS '文件创建时间'; +COMMENT ON COLUMN "public"."file_index"."operate" IS '文件操作'; + +-- ---------------------------- +-- Primary Key structure for table file +-- ---------------------------- +ALTER TABLE "public"."file_index" + ADD CONSTRAINT "PK_FILE_INDEX_ID" PRIMARY KEY ("id"); + +CREATE INDEX "IDX_FILE_INDEX_USER_ID" ON "public"."file_index" USING btree ( + "user_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILENAME" ON "public"."file_index" USING btree ( + "filename" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_FILE_TYPE" ON "public"."file_index" USING btree ( + "file_type" "pg_catalog"."int2_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_FINISH" ON "public"."file_index" USING btree ( + "is_finish" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_CONDENSE" ON "public"."file_index" USING btree ( + "is_condense" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_SLICE" ON "public"."file_index" USING btree ( + "is_slice" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_IS_MERGE" ON "public"."file_index" USING btree ( + "is_merge" "pg_catalog"."bool_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_INDEX_OPERATE" ON "public"."file_index" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +DROP TABLE IF EXISTS "public"."file_chunk"; +CREATE TABLE "public"."file_chunk" +( + "id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "file_index_id" VARCHAR(64) COLLATE "pg_catalog"."default" NOT NULL, + "chunk_index" INT4 NOT NULL, + "chunk_size" INT8, + "chunk_start" INT8, + "chunk_end" INT8, + "chunk_md5" VARCHAR(1024) COLLATE "pg_catalog"."default", + "is_last_chunk" BOOLEAN DEFAULT FALSE, + "chunk_time" TIMESTAMPTZ, + "start_time" TIMESTAMPTZ, + "end_time" TIMESTAMPTZ, + "operate" INT4 +); + +COMMENT ON COLUMN "public"."file_chunk"."id" IS '文件分片id'; +COMMENT ON COLUMN "public"."file_chunk"."file_index_id" IS '文件id'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_index" IS '分片编号'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_size" IS '分片长度'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_start" IS '分片起始位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_end" IS '分片结束位置'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_md5" IS '分片md5校验'; +COMMENT ON COLUMN "public"."file_chunk"."is_last_chunk" IS '是否最后一片数据 1:否,2:是'; +COMMENT ON COLUMN "public"."file_chunk"."chunk_time" IS '分片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."start_time" IS '第一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."end_time" IS '最后一片上传时间'; +COMMENT ON COLUMN "public"."file_chunk"."operate" IS '文件操作'; + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "PK_FILE_CHUNK_ID" PRIMARY KEY ("id"); + +ALTER TABLE "public"."file_chunk" + ADD CONSTRAINT "UK_FILE_CHUNK_FILE_INDEX_ID_CHUNK_INDEX" UNIQUE ("file_index_id", "chunk_index"); + +CREATE INDEX "IDX_FILE_CHUNK_FILE_INDEX_ID" ON "public"."file_chunk" USING btree ( + "file_index_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_CHUNK_INDEX" ON "public"."file_chunk" USING btree ( + "chunk_index" "pg_catalog"."int4_ops" ASC NULLS LAST +); + +CREATE INDEX "IDX_FILE_CHUNK_OPERATE" ON "public"."file_chunk" USING btree ( + "operate" "pg_catalog"."int4_ops" ASC NULLS LAST +); \ No newline at end of file diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java index 0af1cde..c091d52 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/configure/FileServiceAsyncConfigure.java @@ -1,5 +1,6 @@ package io.github.nichetoolkit.file.configure; +import io.github.nichetoolkit.rest.logback.RestThreadPoolTaskExecutor; import lombok.extern.slf4j.Slf4j; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.scheduling.annotation.AsyncConfigurer; @@ -29,7 +30,7 @@ public class FileServiceAsyncConfigure implements AsyncConfigurer { */ @Override public Executor getAsyncExecutor() { - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + RestThreadPoolTaskExecutor executor = new RestThreadPoolTaskExecutor(); executor.setDaemon(true); executor.setCorePoolSize(10); executor.setMaxPoolSize(100); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index 7c0fa4b..0b2dc58 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -5,15 +5,12 @@ import io.github.nichetoolkit.file.entity.FileIndexEntity; import io.github.nichetoolkit.file.enums.FileType; import io.github.nichetoolkit.file.error.FileErrorStatus; -import io.github.nichetoolkit.file.error.ImageTransferException; import io.github.nichetoolkit.file.filter.FileFilter; import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.file.service.AsyncFileService; import io.github.nichetoolkit.file.service.FileChunkService; import io.github.nichetoolkit.file.service.FileIndexService; -import io.github.nichetoolkit.file.util.ImageUtils; import io.github.nichetoolkit.file.util.Md5Utils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; @@ -22,7 +19,6 @@ import io.github.nichetoolkit.rice.RestPage; import io.github.nichetoolkit.rice.helper.PropertyHelper; import lombok.extern.slf4j.Slf4j; -import net.coobird.thumbnailator.Thumbnails; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -30,10 +26,6 @@ import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; -import javax.annotation.PostConstruct; -import javax.naming.NamingEnumeration; -import javax.swing.*; -import java.awt.image.BufferedImage; import java.io.*; import java.util.*; import java.util.stream.Collectors; @@ -56,8 +48,6 @@ public class FileServiceHelper implements InitializingBean { @Autowired private FileChunkService fileChunkService; - private AsyncFileService asyncFileService; - private static FileServiceHelper INSTANCE = null; public static FileServiceHelper getInstance() { @@ -69,11 +59,6 @@ public void afterPropertiesSet() throws Exception { INSTANCE = this; } - @PostConstruct - public void InitFileSupperService() { - asyncFileService = ContextUtils.getBean(AsyncFileService.class); - } - public static void checkRestPage(RestPage restPage) throws RestException { if (GeneralUtils.isEmpty(restPage) || GeneralUtils.isEmpty(restPage.getItems())) { log.warn("the file service query result is empty!"); @@ -101,7 +86,7 @@ public static void buildChunkFiles(List fileIndices, FileFilter fileF itemFilename = fileIndex.getFilename().concat("_").concat(String.valueOf(fileChunk.getChunkIndex())).concat(FileConstants.SUFFIX_REGEX).concat(fileIndex.getSuffix()); } String itemFilePath = randomPath.concat(File.separator).concat(itemFilename); - writeFile(fileChunk.getId(), itemFilePath); + FileHandleHelper.writeFile(fileChunk.getId(), itemFilePath); fileList.add(new File(itemFilePath)); } } @@ -119,21 +104,11 @@ public static void buildIndexFiles(List fileIndices, FileFilter fileF itemFilename = fileIndex.getFilename().concat(FileConstants.SUFFIX_REGEX).concat(fileIndex.getSuffix()); } String itemFilePath = randomPath.concat(File.separator).concat(itemFilename); - writeFile(fileIndex.getId(), itemFilePath); + FileHandleHelper.writeFile(fileIndex.getId(), itemFilePath); fileList.add(new File(itemFilePath)); } } - public static void writeFile(String objectName, String itemFilePath) throws RestException { - try (InputStream getObjectResponse = INSTANCE.asyncFileService.getById(objectName)) { - StreamUtils.write(itemFilePath, getObjectResponse); - } catch (IOException exception) { - log.error("the file service download has error: {}", exception.getMessage()); - throw new FileErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR); - } - } - - public static FileIndex createFileIndex(FileIndex fileIndex) throws RestException { if (GeneralUtils.isEmpty(fileIndex)) { log.warn("the file index is null!"); diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java index e4e9da8..991de72 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileChunkServiceImpl.java @@ -1,4 +1,4 @@ -package io.github.nichetoolkit.file.service.impl; +package io.github.nichetoolkit.file.service; import io.github.nichetoolkit.file.entity.FileChunkEntity; import io.github.nichetoolkit.file.filter.FileFilter; diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java index 3b0fc64..c4c99aa 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileHandleServiceImpl.java @@ -1,17 +1,15 @@ -package io.github.nichetoolkit.file.service.impl; +package io.github.nichetoolkit.file.service; import io.github.nichetoolkit.file.configure.FileCommonProperties; import io.github.nichetoolkit.file.constant.FileConstants; -import io.github.nichetoolkit.file.enums.FileType; import io.github.nichetoolkit.file.error.FileErrorStatus; import io.github.nichetoolkit.file.helper.FileServiceHelper; -import io.github.nichetoolkit.file.helper.ImageHelper; +import io.github.nichetoolkit.file.helper.ImageHandleHelper; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.service.FileHandleService; import io.github.nichetoolkit.file.util.ImageUtils; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; -import io.github.nichetoolkit.rest.identity.IdentityUtils; import io.github.nichetoolkit.rest.util.FileUtils; import io.github.nichetoolkit.rest.util.GeneralUtils; import io.github.nichetoolkit.rest.util.StreamUtils; @@ -87,7 +85,7 @@ public void condenseImage(FileIndex fileIndex) throws RestException { } try { Thumbnails.of(fileIndex.inputStream()).scale(imageFileScale).outputFormat(FileConstants.IMAGE_PNG_SUFFIX).outputQuality(imageFileQuality).toFile(filePath); - BufferedImage bufferedImage = ImageHelper.read(file); + BufferedImage bufferedImage = ImageHandleHelper.read(file); int imageWidth = bufferedImage.getWidth(); int imageHeight = bufferedImage.getHeight(); if (GeneralUtils.isNotEmpty(width) && GeneralUtils.isNotEmpty(height)) { diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java index d17b493..6be4054 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileIndexServiceImpl.java @@ -1,4 +1,4 @@ -package io.github.nichetoolkit.file.service.impl; +package io.github.nichetoolkit.file.service; import io.github.nichetoolkit.file.entity.FileIndexEntity; import io.github.nichetoolkit.file.filter.FileFilter; diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java index 7e12f3d..a765b91 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/service/impl/FileServiceImpl.java @@ -5,26 +5,28 @@ import io.github.nichetoolkit.file.enums.FileType; import io.github.nichetoolkit.file.error.FileErrorStatus; import io.github.nichetoolkit.file.filter.FileFilter; +import io.github.nichetoolkit.file.handle.FileStoreService; import io.github.nichetoolkit.file.helper.FileServiceHelper; import io.github.nichetoolkit.file.model.FileChunk; import io.github.nichetoolkit.file.model.FileIndex; import io.github.nichetoolkit.file.model.FileRequest; -import io.github.nichetoolkit.file.service.*; +import io.github.nichetoolkit.file.service.FileChunkService; +import io.github.nichetoolkit.file.service.FileHandleService; +import io.github.nichetoolkit.file.service.FileIndexService; +import io.github.nichetoolkit.file.service.FileService; import io.github.nichetoolkit.file.video.VideoHttpRequestHandler; import io.github.nichetoolkit.rest.RestException; import io.github.nichetoolkit.rest.error.natives.FileErrorException; -import io.github.nichetoolkit.rest.identity.IdentityUtils; import io.github.nichetoolkit.rest.util.*; import io.github.nichetoolkit.rice.RestId; import io.github.nichetoolkit.rice.RestPage; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -38,7 +40,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.Future; import java.util.stream.Collectors; /** @@ -62,10 +63,10 @@ public class FileServiceImpl implements FileService { @Autowired protected FileHandleService fileHandleService; - @Autowired - protected AsyncFileService asyncFileService; + @Resource + protected FileStoreService fileStoreService; - @Autowired + @Resource protected VideoHttpRequestHandler videoHttpRequestHandler; @Override @@ -81,7 +82,7 @@ public void remove(FileFilter fileFilter) throws RestException { } List fileIdList = restPage.getItems().stream().map(RestId::getId).distinct().collect(Collectors.toList()); if (GeneralUtils.isNotEmpty(fileIdList)) { - asyncFileService.removeAll(fileIdList); + fileStoreService.removeAll(fileIdList); if (fileFilter.isChunk()) { if (fileFilter.isDelete()) { fileChunkService.deleteAll(fileIdList); @@ -125,9 +126,9 @@ public void remove(String fileId, Boolean chunk, Boolean delete, Boolean rename) } if (isExist) { if (rename) { - asyncFileService.renameById(fileId, fileId.concat("_del")); + fileStoreService.renameById(fileId, fileId.concat("_del")); } - asyncFileService.removeById(fileId); + fileStoreService.removeById(fileId); } } @@ -160,7 +161,7 @@ public void download(FileIndex fileIndex, String filename, String contentType, B throw new FileErrorException(FileErrorStatus.SERVICE_DOWNLOAD_ERROR); } } else { - try (InputStream inputStream = asyncFileService.getById(fileIndex.getId()); + try (InputStream inputStream = fileStoreService.getById(fileIndex.getId()); ServletOutputStream outputStream = response.getOutputStream()) { response.addHeader(FileConstants.CONTENT_DISPOSITION_HEADER, FileConstants.ATTACHMENT_FILENAME_VALUE + URLEncoder.encode(filename, StandardCharsets.UTF_8.name())); StreamUtils.write(outputStream, inputStream); @@ -315,7 +316,7 @@ public FileIndex upload(FileIndex fileIndex) throws RestException { } } String fileId = fileIndex.getId(); - asyncFileService.putById(fileId, fileIndex.inputStream()); + fileStoreService.putById(fileId, fileIndex.inputStream()); checkFileIndex(fileIndex); fileIndexService.save(fileIndex); return fileIndex; @@ -339,7 +340,7 @@ public FileIndex chunkUpload(MultipartFile file, String contentRange, FileReques FileIndex fileIndex = FileServiceHelper.createFileChunk(file, fileChunkIndex); checkFileIndex(fileIndex); FileChunk uploadChunk = fileChunkService.save(fileIndex.getFileChunk()); - asyncFileService.putById(uploadChunk.getId(), uploadChunk.inputStream()); + fileStoreService.putById(uploadChunk.getId(), uploadChunk.inputStream()); fileIndex.setFileChunk(uploadChunk); if (GeneralUtils.isEmpty(fileIndex.getFileChunks())) { fileIndex.setFileChunks(new ArrayList<>()); @@ -350,7 +351,7 @@ public FileIndex chunkUpload(MultipartFile file, String contentRange, FileReques if ((uploadChunk.getIsLastChunk() || uploadChunk.getChunkIndex().equals(fileIndex.getSliceSize())) && fileIndex.getIsMerge()) { fileIndex.setIsFinish(true); List sources = fileIndex.getFileChunks().stream().map(RestId::getId).collect(Collectors.toList()); - asyncFileService.margeById(fileIndex.getId(), sources); + fileStoreService.margeById(fileIndex.getId(), sources); checkFileIndex(fileIndex); fileIndexService.save(fileIndex); } diff --git a/file-toolkit-test-web/pom.xml b/file-toolkit-test-web/pom.xml index 2b2ff7e..3e53c49 100644 --- a/file-toolkit-test-web/pom.xml +++ b/file-toolkit-test-web/pom.xml @@ -29,6 +29,18 @@ ${file-toolkit.version} + + io.github.nichetoolkit + file-toolkit-service-starter + ${file-toolkit.version} + + + + io.github.nichetoolkit + file-toolkit-postgres-starter + ${file-toolkit.version} + + com.zaxxer HikariCP diff --git a/file-toolkit-test-web/src/main/resources/application-dev.properties b/file-toolkit-test-web/src/main/resources/application-dev.properties index 6a6e4ae..33ceb8a 100644 --- a/file-toolkit-test-web/src/main/resources/application-dev.properties +++ b/file-toolkit-test-web/src/main/resources/application-dev.properties @@ -1,4 +1,4 @@ -server.port=8080 +server.port=8081 nichetoolkit.rest.intercept.enabled=true nichetoolkit.rest.intercept.log-enabled=true nichetoolkit.rest.intercept.userlog-enabled=true @@ -13,6 +13,7 @@ spring.datasource.hikari.driver-class-name=org.postgresql.Driver spring.datasource.hikari.jdbc-url=jdbc:postgresql://localhost:5432/resource?stringtype=unspecified spring.datasource.hikari.username=postgres spring.datasource.hikari.password=2314 + nichetoolkit.file.common.temp-path=E:\\data\\server\\file\\temp nichetoolkit.file.minio.endpoint=http://172.16.107.144:9000 nichetoolkit.file.minio.bucket-name=local diff --git a/file-toolkit-test-web/src/main/resources/application.properties b/file-toolkit-test-web/src/main/resources/application.properties index e57f2ee..3dc0956 100644 --- a/file-toolkit-test-web/src/main/resources/application.properties +++ b/file-toolkit-test-web/src/main/resources/application.properties @@ -67,4 +67,4 @@ spring.datasource.hikari.connection-test-query=SELECT 1 logging.config=classpath:logback-spring.xml -spring.profiles.active=dev \ No newline at end of file +spring.profiles.active=pro \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7ffa639..d3e486e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,10 +10,12 @@ file-toolkit-common-starter file-toolkit-service-starter + file-toolkit-postgres-starter + file-toolkit-gauss-starter file-toolkit-hdfs-starter file-toolkit-minio-utils file-toolkit-minio-starter - + file-toolkit-test-web file-toolkit-parent From eea91df375f5b6e1f45d759f4fe006e4d4c9e5c7 Mon Sep 17 00:00:00 2001 From: Cyan Date: Tue, 14 Mar 2023 11:24:44 +0800 Subject: [PATCH 26/30] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/{FileStoreService.java => MinioFileService.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/{FileStoreService.java => MinioFileService.java} (91%) diff --git a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/FileStoreService.java b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/MinioFileService.java similarity index 91% rename from file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/FileStoreService.java rename to file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/MinioFileService.java index 8470b6d..6aec1a0 100644 --- a/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/FileStoreService.java +++ b/file-toolkit-minio-starter/src/main/java/io/github/nichetoolkit/file/service/MinioFileService.java @@ -1,7 +1,7 @@ package io.github.nichetoolkit.file.service; +import io.github.nichetoolkit.file.handle.FileStoreService; import io.github.nichetoolkit.file.minio.MinioUtils; -import io.github.nichetoolkit.file.handle.FileHandleService; import io.github.nichetoolkit.rest.RestException; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -16,7 +16,7 @@ * @version v1.0.0 */ @Service -public class MinioFileService extends FileHandleService { +public class MinioFileService extends FileStoreService { @Override @Async public void removeAll(List fileIdList) throws RestException { From 8c5274cf448edd3f914d4e502211dd040f16814c Mon Sep 17 00:00:00 2001 From: Cyan Date: Tue, 14 Mar 2023 11:34:45 +0800 Subject: [PATCH 27/30] fix web --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d3e486e..90fc59a 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ file-toolkit-hdfs-starter file-toolkit-minio-utils file-toolkit-minio-starter - file-toolkit-test-web + file-toolkit-parent From 659103ddbe6e5062a82ea8674410e228f4130e7c Mon Sep 17 00:00:00 2001 From: Cyan Date: Tue, 14 Mar 2023 14:04:12 +0800 Subject: [PATCH 28/30] fix --- .../java/io/github/nichetoolkit/file/helper/FileHandleHelper.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {file-toolkit-common-starter => file-toolkit-service-starter}/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java (100%) diff --git a/file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java similarity index 100% rename from file-toolkit-common-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java rename to file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileHandleHelper.java From 5cee9e9b9d95e413d7d28937838081af0ba6f08d Mon Sep 17 00:00:00 2001 From: Cyan Date: Fri, 12 May 2023 18:24:54 +0800 Subject: [PATCH 29/30] fix --- .../io/github/nichetoolkit/file/helper/FileServiceHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java index 0b2dc58..b34209f 100644 --- a/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java +++ b/file-toolkit-service-starter/src/main/java/io/github/nichetoolkit/file/helper/FileServiceHelper.java @@ -335,6 +335,9 @@ public static FileIndex createFileIndex(MultipartFile multipartFile, FileIndex f fileIndex.setId(fileId); } String originalFilename = multipartFile.getOriginalFilename(); + if (GeneralUtils.isNotEmpty(originalFilename)) { + originalFilename=originalFilename.trim().toLowerCase(); + } fileIndex.setName(originalFilename); String tempPath = FileUtils.createPath(INSTANCE.commonProperties.getTempPath()); String cachePath = FileUtils.createPath(tempPath, fileIndex.getId()); From 102d56fd47ad9627c33c097524ee9ad7f2b82e7a Mon Sep 17 00:00:00 2001 From: Cyan Date: Tue, 23 Apr 2024 18:15:45 +0800 Subject: [PATCH 30/30] version 1.0.4 --- README.md | 33 ++++----------------------- SECURITY.md | 8 +++---- file-toolkit-common-starter/pom.xml | 4 ++-- file-toolkit-gauss-starter/pom.xml | 4 ++-- file-toolkit-hdfs-starter/pom.xml | 4 ++-- file-toolkit-minio-starter/pom.xml | 4 ++-- file-toolkit-minio-utils/pom.xml | 4 ++-- file-toolkit-postgres-starter/pom.xml | 4 ++-- file-toolkit-service-starter/pom.xml | 4 ++-- file-toolkit-test-web/pom.xml | 4 ++-- pom.xml | 8 +++---- 11 files changed, 29 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 55925b7..5bdf809 100644 --- a/README.md +++ b/README.md @@ -8,29 +8,6 @@    依赖[rice-toolkit](https://github.com/NicheToolkit/rice-toolkit/rice-toolkit-starter)组件下的基于[postgresql](https://www.postgresql.org/)数据库环境下的简单业务通用服务开发组件. -## Release介绍 - -- [File-Toolkit@1.0.3](https://github.com/NicheToolkit/file-toolkit/tree/master/release/1.0.3.md) - -### v1.0.3 Release - -1、修复`minio`依赖`okhttp3`版本为`4.8.1`。 - -2、升级`spring boot`版本至`2.6.6`版本。 - -3、优化文件上传异步处理,加快文件上传接口响应。 - -4、拆分`MinioUtils`工具至单独模块`file-toolkit-minio-utils`。 - -5、拆分文件模型定义相关`FileChunk`、`FileIndex`至单独模块`file-toolkit-common-starter`。 - -# [file-toolkit-test-web](https://github.com/NicheToolkit/file-toolkit/tree/master/file-toolkit-test-web) - -[logback-spring.xml](https://github.com/NicheToolkit/file-toolkit/blob/master/file-toolkit-test-web/src/main/resources/logback-spring.xml) -默认日志配置文件调整,新增`LOGS_FILE`所有日志的到`./logs.log`文件的输出,方便同一个`Tomcat`服务器下部署多个`War`包时,查看单个服务的日志混乱的问题。 - -**Full Changelog**: https://github.com/NicheToolkit/file-toolkit/compare/v1.0.2...v1.0.3 - ## Maven Central - [Maven Central Repository](https://search.maven.org/search?q=io.github.nichetoolkit) @@ -38,7 +15,7 @@ - [Sonatype Central Repository](https://central.sonatype.dev/search?q=io.github.nichetoolkit) ## 依赖环境 - > [Spring Boot](https://spring.io/projects/spring-boot) 2.6.6.RELEASE\ + > [Spring Boot](https://spring.io/projects/spring-boot) 2.7.7.RELEASE\ > [Maven](https://maven.apache.org/) 3.6.0+\ > [JDK](https://www.oracle.com/java/technologies/downloads/#java8) 1.8\ > [PostgreSQL](https://www.postgresql.org/) 10.0+ @@ -49,7 +26,7 @@ io.github.nichetoolkit file-toolkit-common-starter - 1.0.3 + 1.0.4 ``` @@ -59,7 +36,7 @@ io.github.nichetoolkit file-toolkit-service-starter - 1.0.3 + 1.0.4 ``` @@ -69,7 +46,7 @@ io.github.nichetoolkit file-toolkit-minio-starter - 1.0.3 + 1.0.4 ``` @@ -79,7 +56,7 @@ io.github.nichetoolkit file-toolkit-minio-utils - 1.0.3 + 1.0.4 ``` diff --git a/SECURITY.md b/SECURITY.md index a6708d2..207fb6e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,13 +7,13 @@ currently being supported with security updates. | Version | Supported | | ------- | ------------------ | -| Spring boot 2.7.6+ | :white_check_mark: | -| < 2.7.6 | :x: | +| Spring boot 2.7.7+ | :white_check_mark: | +| < 2.7.7 | :x: | | Maven 3.6.0+ | :white_check_mark: | | < 3.6.0 | :x: | | JDK 1.8 | :white_check_mark: | | -| Rice-Toolkit 1.0.4+ | :white_check_mark: | -| < 1.0.4 | :x: +| Rice-Toolkit 1.0.5+ | :white_check_mark: | +| < 1.0.5 | :x: ## Reporting a Vulnerability Use this section to tell people how to report a vulnerability. diff --git a/file-toolkit-common-starter/pom.xml b/file-toolkit-common-starter/pom.xml index 43af4ab..b5779ff 100644 --- a/file-toolkit-common-starter/pom.xml +++ b/file-toolkit-common-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-common-starter - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-common-starter File toolkit common starter project for Spring Boot diff --git a/file-toolkit-gauss-starter/pom.xml b/file-toolkit-gauss-starter/pom.xml index 0cf85f6..c9652d0 100644 --- a/file-toolkit-gauss-starter/pom.xml +++ b/file-toolkit-gauss-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-gauss-starter - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-gauss-starter jar File toolkit service project for Spring Boot diff --git a/file-toolkit-hdfs-starter/pom.xml b/file-toolkit-hdfs-starter/pom.xml index c99d1d3..d0b8208 100644 --- a/file-toolkit-hdfs-starter/pom.xml +++ b/file-toolkit-hdfs-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-hdfs-starter - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-hdfs-starter jar File toolkit hdfs project for Spring Boot diff --git a/file-toolkit-minio-starter/pom.xml b/file-toolkit-minio-starter/pom.xml index 364dece..6e8e682 100644 --- a/file-toolkit-minio-starter/pom.xml +++ b/file-toolkit-minio-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-minio-starter - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-minio-starter jar File toolkit minio project for Spring Boot diff --git a/file-toolkit-minio-utils/pom.xml b/file-toolkit-minio-utils/pom.xml index d8f40c2..57a016a 100644 --- a/file-toolkit-minio-utils/pom.xml +++ b/file-toolkit-minio-utils/pom.xml @@ -5,10 +5,10 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-minio-utils - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-minio-utils jar File toolkit minio utils project for Spring Boot diff --git a/file-toolkit-postgres-starter/pom.xml b/file-toolkit-postgres-starter/pom.xml index 1d85195..a35e628 100644 --- a/file-toolkit-postgres-starter/pom.xml +++ b/file-toolkit-postgres-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-postgres-starter - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-postgres-starter jar File toolkit postgres project for Spring Boot diff --git a/file-toolkit-service-starter/pom.xml b/file-toolkit-service-starter/pom.xml index c4b40e1..3777a34 100644 --- a/file-toolkit-service-starter/pom.xml +++ b/file-toolkit-service-starter/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-service-starter - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-service-starter jar File toolkit service project for Spring Boot diff --git a/file-toolkit-test-web/pom.xml b/file-toolkit-test-web/pom.xml index 3e53c49..819d87f 100644 --- a/file-toolkit-test-web/pom.xml +++ b/file-toolkit-test-web/pom.xml @@ -5,11 +5,11 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-test-web - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-test-web jar file toolkit test web project for Spring Boot diff --git a/pom.xml b/pom.xml index 90fc59a..4693b7c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.github.nichetoolkit file-toolkit-parent - 1.0.4-SNAPSHOT + 1.0.4 file-toolkit-common-starter @@ -116,8 +116,8 @@ 1.8 1.8 2.7.7 - 1.0.6-SNAPSHOT - 1.0.5-SNAPSHOT + 1.0.6 + 1.0.5 2.2.1 2.9.1 @@ -126,7 +126,7 @@ 3.3 2.5.3 - 1.0.4-SNAPSHOT + 1.0.4 2.8.5 0.4.16