aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-11 14:05:43 +0300
committerGravatar Vitaly Takmazov2018-04-11 14:05:43 +0300
commitf7a2f1440ef0c13a472b1b815186615d2c54168a (patch)
tree2270b2bd9948cdb809e40942b63cf4c84172a53a /juick-common/src/main/java/com/juick/service
parent6f346454e906d07551c35a7173fd8175b4d0975d (diff)
server: ImagesService refactoring
Diffstat (limited to 'juick-common/src/main/java/com/juick/service')
-rw-r--r--juick-common/src/main/java/com/juick/service/ImagesService.java17
-rw-r--r--juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java31
2 files changed, 36 insertions, 12 deletions
diff --git a/juick-common/src/main/java/com/juick/service/ImagesService.java b/juick-common/src/main/java/com/juick/service/ImagesService.java
index b5cff16e..192217fe 100644
--- a/juick-common/src/main/java/com/juick/service/ImagesService.java
+++ b/juick-common/src/main/java/com/juick/service/ImagesService.java
@@ -2,6 +2,23 @@ package com.juick.service;
import com.juick.Message;
+import java.io.IOException;
+
public interface ImagesService {
void setAttachmentMetadata(String imgDir, String baseUrl, Message msg) throws Exception;
+ /**
+ * Move attached image from temp folder to image folder.
+ * Create preview images in corresponding folders.
+ *
+ * @param tempFilename Name of the image file in the temp folder.
+ * @param outputFilename Name that will be used in the image folder.
+ */
+ void saveImageWithPreviews(String tempFilename, String outputFilename) throws IOException;
+ /**
+ * Save new avatar in all required sizes.
+ *
+ * @param tempFilename Name of the image file in the temp folder.
+ * @param uid User id that is used to build image file names.
+ */
+ void saveAvatar(String tempFilename, int uid) throws IOException;
}
diff --git a/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java b/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java
index 3a5c77dd..dbc3f3a9 100644
--- a/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java
+++ b/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java
@@ -7,9 +7,14 @@ import com.juick.server.util.ImageUtils;
import org.springframework.util.StringUtils;
import java.io.File;
+import java.io.IOException;
import java.nio.file.Paths;
public class ImagesServiceImpl implements ImagesService {
+ private ImageUtils imageUtils;
+ public ImagesServiceImpl(String imgDir, String tmpDir) {
+ imageUtils = new ImageUtils(imgDir, tmpDir);
+ }
@Override
public void setAttachmentMetadata(String imgDir, String baseUrl, Message msg) throws Exception {
if (!StringUtils.isEmpty(msg.getAttachmentType())) {
@@ -42,30 +47,32 @@ public class ImagesServiceImpl implements ImagesService {
builder.append(".").append(msg.getAttachmentType());
String originalUrl = builder.toString();
- Attachment original = new Attachment();
+ Attachment original = imageUtils.getAttachment(fullImage);
original.setUrl(originalUrl);
- original.setHeight(ImageUtils.getImageHeight(fullImage));
- original.setWidth(ImageUtils.getImageWidth(fullImage));
- Attachment medium = new Attachment();
+ Attachment medium = imageUtils.getAttachment(mediumImage);
medium.setUrl(photo.getMedium());
- medium.setWidth(ImageUtils.getImageWidth(mediumImage));
- medium.setHeight(ImageUtils.getImageHeight(mediumImage));
original.setMedium(medium);
- Attachment small = new Attachment();
+ Attachment small = imageUtils.getAttachment(smallImage);
small.setUrl(photo.getSmall());
- small.setWidth(ImageUtils.getImageWidth(smallImage));
- small.setHeight(ImageUtils.getImageHeight(smallImage));
original.setSmall(small);
- Attachment thumb = new Attachment();
+ Attachment thumb = imageUtils.getAttachment(thumbnailImage);
thumb.setUrl(photo.getMedium());
- thumb.setWidth(ImageUtils.getImageWidth(thumbnailImage));
- thumb.setHeight(ImageUtils.getImageHeight(thumbnailImage));
original.setThumbnail(thumb);
msg.setAttachment(original);
}
}
+
+ @Override
+ public void saveImageWithPreviews(String tempFilename, String outputFilename) throws IOException {
+ imageUtils.saveImageWithPreviews(tempFilename, outputFilename);
+ }
+
+ @Override
+ public void saveAvatar(String tempFilename, int uid) throws IOException {
+ imageUtils.saveAvatar(tempFilename, uid);
+ }
}