From 491f22135b985e1dfa8d2ff15ea38e59269659c1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 21 Jul 2016 13:54:35 +0300 Subject: www: Thumbnailator for comments --- juick-www/build.gradle | 1 + juick-www/src/main/java/com/juick/www/Main.java | 4 +++- .../src/main/java/com/juick/www/NewMessage.java | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/juick-www/build.gradle b/juick-www/build.gradle index 22d9672e..82dee993 100644 --- a/juick-www/build.gradle +++ b/juick-www/build.gradle @@ -37,6 +37,7 @@ dependencies { compile "org.springframework:spring-jdbc:4.3.1.RELEASE" compile 'org.apache.commons:commons-dbcp2:2.0' compile 'org.json:json:20151123' + compile 'net.coobird:thumbnailator:0.4.8' testCompile 'junit:junit:4.12' providedCompile 'javax.servlet:javax.servlet-api:3.1.0' providedRuntime 'mysql:mysql-connector-java:5.1.39' diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java index d7ecd0cb..a08ea73e 100644 --- a/juick-www/src/main/java/com/juick/www/Main.java +++ b/juick-www/src/main/java/com/juick/www/Main.java @@ -55,7 +55,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { Help help = new Help(); User pagesUser = new User(); UserThread pagesUserThread = new UserThread(); - NewMessage pagesNewMessage = new NewMessage(); + NewMessage pagesNewMessage; FacebookLogin loginFacebook = new FacebookLogin(); VKontakteLogin loginVK = new VKontakteLogin(); TwitterAuth twitterAuth; @@ -83,6 +83,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { setupXmppComponent(conf.getProperty("xmpp_password")); twitterAuth = new TwitterAuth(conf.getProperty("twitter_consumer_key"), conf.getProperty("twitter_consumer_secret")); + pagesNewMessage = new NewMessage(conf.getProperty("upload_tmp_dir", "/var/www/juick.com/i/tmp/"), + conf.getProperty("img_path", "/var/www/juick.com/i/")); PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600); } catch (Exception e) { log(null, e); diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java index bb169b60..63cfe3ed 100644 --- a/juick-www/src/main/java/com/juick/www/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/NewMessage.java @@ -26,6 +26,7 @@ import com.juick.xmpp.extensions.JuickMessage; import com.juick.xmpp.extensions.JuickUser; import com.juick.xmpp.extensions.Nickname; import com.juick.xmpp.extensions.XOOB; +import net.coobird.thumbnailator.Thumbnails; import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletException; @@ -36,6 +37,9 @@ import java.io.PrintWriter; import java.io.UnsupportedEncodingException; 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.ArrayList; import java.util.List; import java.util.logging.Level; @@ -49,6 +53,13 @@ public class NewMessage { private static final Logger logger = Logger.getLogger(NewMessage.class.getName()); + private String tmpDir, imgDir; + + public NewMessage(String tmpDir, String imgDir) { + this.tmpDir = tmpDir; + this.imgDir = imgDir; + } + protected void doGetNewMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()) { @@ -361,7 +372,14 @@ public class NewMessage { String fname = mid + "-" + ridnew + "." + attachmentType; String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - Runtime.getRuntime().exec("/var/www/juick.com/cgi/p-convert.sh /var/www/juick.com/i/tmp/" + attachmentFName + " " + fname); + Path origName = Paths.get(imgDir, "p", fname); + Files.move(Paths.get(tmpDir, attachmentType), origName); + Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-1024", fname).toFile()); + Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-512", fname).toFile()); + Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9) + .toFile(Paths.get(imgDir, "ps", fname).toFile()); body = attachmentURL + "\n" + body; XOOB xoob = new XOOB(); -- cgit v1.2.3