|
|
@@ -21,6 +21,7 @@ import io.swagger.annotations.Api;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
|
+import org.springblade.common.enums.CommonEnum;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.oss.model.OssFile;
|
|
|
import org.springblade.core.tenant.annotation.NonDS;
|
|
|
@@ -38,6 +39,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 对象存储端点
|
|
|
@@ -63,6 +67,12 @@ public class OssEndpoint {
|
|
|
|
|
|
private final ISysClient sysClient;
|
|
|
|
|
|
+ private final List<String> CONTENT_TYPE = Arrays.asList("image/jpeg", "image/png", "image/jpg", "image/bmp");
|
|
|
+
|
|
|
+ private final long MAX_IMAGE_SIZE = 204800;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 创建存储桶
|
|
|
*
|
|
|
@@ -158,25 +168,12 @@ public class OssEndpoint {
|
|
|
System.err.println("replace.url:" + replaceUrl);
|
|
|
String contentType = file.getContentType();
|
|
|
BladeFile bladeFile;
|
|
|
- if (contentType != null && (contentType.equals("image/jpeg") || contentType.equals("image/png")
|
|
|
- || contentType.equals("image/jpg")) || contentType.equals("image/bmp")){
|
|
|
- if (file.getSize() > 204800){
|
|
|
- // 使用Thumbnails压缩图片
|
|
|
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
- Thumbnails.of(file.getInputStream())
|
|
|
- .size(350,350)
|
|
|
- .outputQuality(1)
|
|
|
- .toOutputStream(outputStream);
|
|
|
- MultipartFile compressedImage = new MockMultipartFile(
|
|
|
- file.getName(),
|
|
|
- file.getOriginalFilename(),
|
|
|
- file.getContentType(),
|
|
|
- outputStream.toByteArray()
|
|
|
- );
|
|
|
- bladeFile = ossBuilder.template().putFile(compressedImage.getOriginalFilename(), compressedImage.getInputStream());
|
|
|
- }else{
|
|
|
- bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
|
|
|
- }
|
|
|
+ if (this.CONTENT_TYPE.contains(contentType) && file.getSize() > this.MAX_IMAGE_SIZE){
|
|
|
+ // 使用Thumbnails压缩图片
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ Thumbnails.of(file.getInputStream()).size(350,350).outputQuality(1).toOutputStream(outputStream);
|
|
|
+ MultipartFile compressedImage = new MockMultipartFile(file.getName(), file.getOriginalFilename(), file.getContentType(), outputStream.toByteArray());
|
|
|
+ bladeFile = ossBuilder.template().putFile(compressedImage.getOriginalFilename(), compressedImage.getInputStream());
|
|
|
}else{
|
|
|
bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
|
|
|
}
|
|
|
@@ -184,14 +181,10 @@ public class OssEndpoint {
|
|
|
System.err.println("link:" + link);
|
|
|
//String replace = link.replace("http://121.37.83.47:9000/", "https://trade.tubaosoft.com/file/");
|
|
|
String replace = "";
|
|
|
- if (ObjectUtils.isNotNull(status) && "获取数据失败".equals(status)) {
|
|
|
- if (ObjectUtils.isNotNull(replaceUrl)&& "获取数据失败".equals(replaceUrl)){
|
|
|
- replace = link.replace(status, replaceUrl + "/file");
|
|
|
- }else{
|
|
|
- replace = link.replace(status + ":9000/", status + "/file/");
|
|
|
- }
|
|
|
- } else {
|
|
|
- replace = link.replace("http://121.37.83.47:9000/", "http://121.37.83.47/file/");
|
|
|
+ if (Objects.equals(status, CommonEnum.GET_DATA_FAIL.info)) {
|
|
|
+ replace = Objects.equals(replaceUrl, CommonEnum.GET_DATA_FAIL.info) ? link.replace(status, replaceUrl + "/file") : link.replace(status + ":9000/", status + "/file/");
|
|
|
+ }else {
|
|
|
+ replace = link.replace("http://121.37.83.47:9000/", "https://lt.echepei.com/file/");
|
|
|
}
|
|
|
System.err.println("replace:" + replace);
|
|
|
bladeFile.setLink(replace);
|