|
|
@@ -38,18 +38,6 @@ public class ImageFileProcessor {
|
|
|
this.putObjectService = putObjectService;
|
|
|
}
|
|
|
|
|
|
- public UploadFileRet processCover(ObjectResult objectResult) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public UploadFileRet processAvatar(ObjectResult objectResult) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public UploadFileRet processPhoto(ObjectResult objectResult) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
public UploadFileRet process(ObjectResult objectResult) {
|
|
|
String originalObjectId = objectResult.getObjectId();
|
|
|
boolean duplicate = objectResult.isDuplicate();
|
|
|
@@ -57,80 +45,92 @@ public class ImageFileProcessor {
|
|
|
String dupObjectId = objectResult.getDupObjectId();
|
|
|
ImageFile imageFile = mediaRepository.findImageFile(dupObjectId);
|
|
|
|
|
|
- String jpegUrl = imageFile.getJpegUrl();
|
|
|
- String jpegObjectName = objectNameService.getObjectNameFromUrl(jpegUrl);
|
|
|
+ String jpegObjectName = objectNameService.getObjectNameFromUrl(imageFile.getJpegUrl());
|
|
|
ObjectResult objectResult2 = putObjectService.copyObject(jpegObjectName, ".jpeg");
|
|
|
String jpegObjectId = objectResult2.getObjectId();
|
|
|
- String jpegUrl1 = objectNameService.getObjectUrl(objectResult2.getObjectName());
|
|
|
+ String jpegUrl = objectNameService.getObjectUrl(objectResult2.getObjectName());
|
|
|
|
|
|
- String webpUrl = imageFile.getWebpUrl();
|
|
|
- String webpObjectName = objectNameService.getObjectNameFromUrl(webpUrl);
|
|
|
+ String webpObjectName = objectNameService.getObjectNameFromUrl(imageFile.getWebpUrl());
|
|
|
ObjectResult objectResult3 = putObjectService.copyObject(webpObjectName, ".webp");
|
|
|
String webpObjectId = objectResult3.getObjectId();
|
|
|
- String webpUrl1 = objectNameService.getObjectUrl(objectResult3.getObjectName());
|
|
|
+ String webpUrl = objectNameService.getObjectUrl(objectResult3.getObjectName());
|
|
|
|
|
|
int width = imageFile.getWidth();
|
|
|
int height = imageFile.getHeight();
|
|
|
boolean horizontal = imageFile.getHorizontal();
|
|
|
|
|
|
- ImageFile imageFile1 = new ImageFile(originalObjectId, width, height, horizontal, jpegUrl1, webpUrl1);
|
|
|
+ ImageFile imageFile1 = new ImageFile(originalObjectId, width, height, horizontal,
|
|
|
+ jpegObjectId, jpegUrl, webpObjectId, webpUrl);
|
|
|
mediaRepository.saveImageFile(imageFile1);
|
|
|
- return new UploadFileRet(objectResult2.getObjectId(), jpegUrl1);
|
|
|
+ return new UploadFileRet(jpegObjectId, jpegUrl);
|
|
|
}
|
|
|
|
|
|
String originalObjectName = objectResult.getObjectName();
|
|
|
String absolutePath = objectResult.getAbsolutePath();
|
|
|
try {
|
|
|
ObjectResult objectResult1;
|
|
|
+ String jpegObjectId;
|
|
|
String jpegUrl;
|
|
|
+ String webpObjectId;
|
|
|
String webpUrl;
|
|
|
String format = ImageOps.getFormat(new File(absolutePath));
|
|
|
if (imageFormats.contains(format)) {
|
|
|
- objectResult1 = putObjectService.copyObject(originalObjectName, "."+format);
|
|
|
+ String jpegObjectName = objectResult.getObjectName();
|
|
|
+ objectResult1 = putObjectService.copyObject(jpegObjectName, "."+format);
|
|
|
+ jpegObjectId = objectResult1.getObjectId();
|
|
|
jpegUrl = objectNameService.getObjectUrl(objectResult1.getObjectName());
|
|
|
} else {
|
|
|
- jpegUrl = getJpegUrl(originalObjectName, absolutePath);
|
|
|
+ ObjectResult objectResult2 = getJpegObject(originalObjectName, absolutePath);
|
|
|
+ jpegObjectId = objectResult2.getObjectId();
|
|
|
+ jpegUrl = objectNameService.getObjectUrl(objectResult2.getObjectName());
|
|
|
}
|
|
|
|
|
|
- if (format.equalsIgnoreCase("webp")) {
|
|
|
- objectResult1 = putObjectService.copyObject(originalObjectName, "."+format);
|
|
|
- webpUrl = objectNameService.getObjectUrl(objectResult1.getObjectName());
|
|
|
+ if (format.equals("webp")) {
|
|
|
+ String webpObjectName = objectResult.getObjectName();
|
|
|
+ ObjectResult objectResult3 = putObjectService.copyObject(webpObjectName, ".webp");
|
|
|
+ webpObjectId = objectResult3.getObjectId();
|
|
|
+ webpUrl = objectNameService.getObjectUrl(objectResult3.getObjectName());
|
|
|
} else {
|
|
|
- webpUrl = getWebpUrl(originalObjectName, absolutePath);
|
|
|
+ ObjectResult objectResult3 = getWebpObject(originalObjectName, absolutePath);
|
|
|
+ webpObjectId = objectResult3.getObjectId();
|
|
|
+ webpUrl = objectNameService.getObjectUrl(objectResult3.getObjectName());
|
|
|
}
|
|
|
|
|
|
ImageOps.Size size = ImageOps.info(new File(absolutePath));
|
|
|
- boolean horizontal = size.getWidth() > size.getHeight();
|
|
|
- ImageFile imageFile =
|
|
|
- new ImageFile(originalObjectId, size.getWidth(), size.getHeight(), horizontal, jpegUrl, webpUrl);
|
|
|
+ int width = size.getWidth();
|
|
|
+ int height = size.getHeight();
|
|
|
+ boolean horizontal = width > height;
|
|
|
+ ImageFile imageFile = new ImageFile(originalObjectId, width, height, horizontal,
|
|
|
+ jpegObjectId, jpegUrl, webpObjectId, webpUrl);
|
|
|
mediaRepository.saveImageFile(imageFile);
|
|
|
-
|
|
|
- return new UploadFileRet("objectResult1.getObjectId()", jpegUrl);
|
|
|
+ return new UploadFileRet(originalObjectId, jpegUrl);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private String getJpegUrl(String originalObjectName, String originalPath) throws Exception {
|
|
|
+ private ObjectResult getJpegObject(String originalObjectName, String originalPath) throws Exception {
|
|
|
byte[] bytes = ImageOps.convert2jpg(new File(originalPath));
|
|
|
return saveImage(originalObjectName, bytes, ".jpeg");
|
|
|
}
|
|
|
|
|
|
- private String getWebpUrl(String originalObjectName, String originalPath) throws Exception {
|
|
|
+ private ObjectResult getWebpObject(String originalObjectName, String originalPath) throws Exception {
|
|
|
BufferedImage bi = ImageIO.read(new File(originalPath));
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
ImageIO.write(bi, "webp", baos);
|
|
|
return saveImage(originalObjectName, baos.toByteArray(), ".webp");
|
|
|
}
|
|
|
|
|
|
- private String saveImage(String originalObjectName, byte[] bytes, String suffix) throws Exception {
|
|
|
+ private ObjectResult getThumbnailObject(String originalObjectName, String originalPath) throws Exception {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObjectResult saveImage(String originalObjectName, byte[] bytes, String suffix) throws Exception {
|
|
|
ObjectProp objectProp = objectNameService.getObjectProp(originalObjectName, suffix);
|
|
|
String contentId = UUID.randomUUID().toString().replace("-", "");
|
|
|
File savedFile = fileStoreService.saveFile(bytes, contentId);
|
|
|
String sha256sum = DigestUtil.sha256sum(savedFile.getAbsolutePath());
|
|
|
- ObjectResult objectResult = putObjectService.putObject(objectProp, contentId, savedFile, "", sha256sum);
|
|
|
- return objectNameService.getObjectUrl(objectResult.getObjectName());
|
|
|
+ return putObjectService.putObject(objectProp, contentId, savedFile, "", sha256sum);
|
|
|
}
|
|
|
}
|