diff options
author | 2018-03-16 10:46:23 +0300 | |
---|---|---|
committer | 2018-03-16 10:46:23 +0300 | |
commit | 9ef168a03b75aeca0c2f7dda9ce87d4014c703a9 (patch) | |
tree | 8ace0ada0f576d97592f8bc84803a2dcf3e7a244 /juick-server-web/src/main/java/com/juick/service/ImagesServiceImpl.java | |
parent | 7cadae166b103182d7d1daaafe602cd8fb145c53 (diff) |
merge common projects
Diffstat (limited to 'juick-server-web/src/main/java/com/juick/service/ImagesServiceImpl.java')
-rw-r--r-- | juick-server-web/src/main/java/com/juick/service/ImagesServiceImpl.java | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/juick-server-web/src/main/java/com/juick/service/ImagesServiceImpl.java b/juick-server-web/src/main/java/com/juick/service/ImagesServiceImpl.java deleted file mode 100644 index 3a5c77dd..00000000 --- a/juick-server-web/src/main/java/com/juick/service/ImagesServiceImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.juick.service; - -import com.juick.Attachment; -import com.juick.Message; -import com.juick.Photo; -import com.juick.server.util.ImageUtils; -import org.springframework.util.StringUtils; - -import java.io.File; -import java.nio.file.Paths; - -public class ImagesServiceImpl implements ImagesService { - @Override - public void setAttachmentMetadata(String imgDir, String baseUrl, Message msg) throws Exception { - if (!StringUtils.isEmpty(msg.getAttachmentType())) { - Photo photo = new Photo(); - if (msg.getRid()> 0) { - photo.setSmall(String.format("%sphotos-512/%d-%d.%s", baseUrl, msg.getMid(), msg.getRid(), msg.getAttachmentType())); - photo.setMedium(String.format("%sphotos-1024/%d-%d.%s", baseUrl, msg.getMid(), msg.getRid(), msg.getAttachmentType())); - photo.setThumbnail(String.format("%sps/%d-%d.%s", baseUrl, msg.getMid(), msg.getRid(), msg.getAttachmentType())); - } else { - photo.setSmall(String.format("%sphotos-512/%d.%s", baseUrl, msg.getMid(), msg.getAttachmentType())); - photo.setMedium(String.format("%sphotos-1024/%d.%s", baseUrl, msg.getMid(), msg.getAttachmentType())); - photo.setThumbnail(String.format("%sps/%d.%s", baseUrl, msg.getMid(), msg.getAttachmentType())); - } - msg.setPhoto(photo); - String imageName = String.format("%s.%s", msg.getMid(), msg.getAttachmentType()); - if (msg.getRid() > 0) { - imageName = String.format("%s-%s.%s", msg.getMid(), msg.getRid(), msg.getAttachmentType()); - } - File fullImage = Paths.get(imgDir, "p", imageName).toFile(); - File mediumImage = Paths.get(imgDir, "photos-1024", imageName).toFile(); - File smallImage = Paths.get(imgDir, "photos-512", imageName).toFile(); - File thumbnailImage = Paths.get(imgDir, "ps", imageName).toFile(); - StringBuilder builder = new StringBuilder(); - builder.append(baseUrl); - builder.append(msg.getAttachmentType().equals("mp4") ? "video" : "p"); - builder.append("/").append(msg.getMid()); - if (msg.getRid() > 0) { - builder.append("-").append(msg.getRid()); - } - builder.append(".").append(msg.getAttachmentType()); - String originalUrl = builder.toString(); - - Attachment original = new Attachment(); - original.setUrl(originalUrl); - original.setHeight(ImageUtils.getImageHeight(fullImage)); - original.setWidth(ImageUtils.getImageWidth(fullImage)); - - Attachment medium = new Attachment(); - medium.setUrl(photo.getMedium()); - medium.setWidth(ImageUtils.getImageWidth(mediumImage)); - medium.setHeight(ImageUtils.getImageHeight(mediumImage)); - original.setMedium(medium); - - Attachment small = new Attachment(); - small.setUrl(photo.getSmall()); - small.setWidth(ImageUtils.getImageWidth(smallImage)); - small.setHeight(ImageUtils.getImageHeight(smallImage)); - original.setSmall(small); - - Attachment thumb = new Attachment(); - thumb.setUrl(photo.getMedium()); - thumb.setWidth(ImageUtils.getImageWidth(thumbnailImage)); - thumb.setHeight(ImageUtils.getImageHeight(thumbnailImage)); - original.setThumbnail(thumb); - - msg.setAttachment(original); - } - } -} |