aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-21 13:54:35 +0300
committerGravatar Vitaly Takmazov2016-07-21 13:54:35 +0300
commit491f22135b985e1dfa8d2ff15ea38e59269659c1 (patch)
tree58164f5a1243c81650e64a5b42b4542965df3030 /juick-www/src/main
parentc19397fb6d4635120a1a8cdaef6d66f0b36e3c4b (diff)
www: Thumbnailator for comments
Diffstat (limited to 'juick-www/src/main')
-rw-r--r--juick-www/src/main/java/com/juick/www/Main.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/NewMessage.java20
2 files changed, 22 insertions, 2 deletions
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();