diff options
Diffstat (limited to 'juick-www/src/main/java/com')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/controllers/NewMessage.java | 35 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/controllers/Settings.java | 20 |
2 files changed, 6 insertions, 49 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java index 1931b1d9..4dcf6c10 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java @@ -24,15 +24,14 @@ import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; import com.juick.server.util.HttpNotFoundException; import com.juick.server.util.HttpUtils; +import com.juick.server.util.ImageUtils; import com.juick.service.*; import com.juick.util.UserUtils; import com.juick.www.Utils; import com.juick.www.WebApp; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; -import org.imgscalr.Scalr; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; @@ -47,11 +46,9 @@ import rocks.xmpp.core.stanza.model.Message; import rocks.xmpp.extensions.nick.model.Nickname; import rocks.xmpp.extensions.oob.model.x.OobX; -import javax.imageio.ImageIO; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.awt.image.BufferedImage; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; @@ -59,9 +56,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; /** @@ -226,18 +220,7 @@ public class NewMessage { String fname = mid + "." + attachmentType; String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - Path origName = Paths.get(webApp.getImgDir(), "p", fname); - Files.move(Paths.get(webApp.getTmpDir(), attachmentFName), origName); - BufferedImage originalImage = ImageIO.read(origName.toFile()); - ImageIO.write(Scalr.resize(originalImage, 1024), - FilenameUtils.getExtension(origName.toString()), - Paths.get(webApp.getImgDir(), "photos-1024", fname).toFile()); - ImageIO.write(Scalr.resize(originalImage, 512), - FilenameUtils.getExtension(origName.toString()), - Paths.get(webApp.getImgDir(), "photos-512", fname).toFile()); - ImageIO.write(Scalr.resize(originalImage, 160), - FilenameUtils.getExtension(origName.toString()), - Paths.get(webApp.getImgDir(), "ps", fname).toFile()); + ImageUtils.saveImageWithPreviews(attachmentFName, fname, webApp.getTmpDir(), webApp.getImgDir()); body = attachmentURL + "\n" + body; try { @@ -385,18 +368,8 @@ public class NewMessage { String fname = mid + "-" + ridnew + "." + attachmentType; String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - Path origName = Paths.get(webApp.getImgDir(), "p", fname); - Files.move(Paths.get(webApp.getTmpDir(), attachmentFName), origName); - BufferedImage originalImage = ImageIO.read(origName.toFile()); - ImageIO.write(Scalr.resize(originalImage, 1024), - FilenameUtils.getExtension(origName.toString()), - Paths.get(webApp.getImgDir(), "photos-1024", fname).toFile()); - ImageIO.write(Scalr.resize(originalImage, 512), - FilenameUtils.getExtension(origName.toString()), - Paths.get(webApp.getImgDir(), "photos-512", fname).toFile()); - ImageIO.write(Scalr.resize(originalImage, 160), - FilenameUtils.getExtension(origName.toString()), - Paths.get(webApp.getImgDir(), "ps", fname).toFile()); + ImageUtils.saveImageWithPreviews(attachmentFName, fname, webApp.getTmpDir(), webApp.getImgDir()); + body = attachmentURL + "\n" + body; try { xmsg.addExtension(new OobX(new URI(attachmentURL))); diff --git a/juick-www/src/main/java/com/juick/www/controllers/Settings.java b/juick-www/src/main/java/com/juick/www/controllers/Settings.java index 3c4511c1..d2b65661 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/Settings.java +++ b/juick-www/src/main/java/com/juick/www/controllers/Settings.java @@ -21,12 +21,11 @@ import com.juick.server.helpers.NotifyOpts; import com.juick.server.helpers.UserInfo; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpUtils; +import com.juick.server.util.ImageUtils; import com.juick.service.*; import com.juick.util.UserUtils; import com.juick.www.WebApp; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; -import org.imgscalr.Scalr; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; @@ -36,7 +35,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; -import javax.imageio.ImageIO; import javax.inject.Inject; import javax.mail.Message; import javax.mail.MessagingException; @@ -48,12 +46,7 @@ import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.awt.image.BufferedImage; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -167,16 +160,7 @@ public class Settings { info.setDescription(request.getParameter("descr")); String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, webApp.getTmpDir()); if (StringUtils.isNotEmpty(avatarTmpPath)) { - String originalExtension = FilenameUtils.getExtension(avatarTmpPath); - String originalName = String.format("%s.%s", visitor.getUid(), originalExtension); - String targetName = String.format("%s.png", visitor.getUid()); - Path ao = Paths.get(webApp.getImgDir(), "ao", originalName); - Path a = Paths.get(webApp.getImgDir(), "a", targetName); - Path as = Paths.get(webApp.getImgDir(), "as", targetName); - Files.move(Paths.get(webApp.getTmpDir(), avatarTmpPath), ao, StandardCopyOption.REPLACE_EXISTING); - BufferedImage originalImage = ImageIO.read(ao.toFile()); - ImageIO.write(Scalr.resize(originalImage, 96), "png", a.toFile()); - ImageIO.write(Scalr.resize(originalImage, 32), "png", as.toFile()); + ImageUtils.saveAvatar(avatarTmpPath, visitor.getUid(), webApp.getTmpDir(), webApp.getImgDir()); } if (userService.updateUserInfo(visitor, info)) { result = String.format("<p>Your info is updated.</p><p><a href='/%s/'>Back to blog</a>.</p>", visitor.getName()); |