aboutsummaryrefslogtreecommitdiff
path: root/juick-api
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api')
-rw-r--r--juick-api/build.gradle1
-rw-r--r--juick-api/src/main/java/com/juick/api/Main.java27
2 files changed, 25 insertions, 3 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle
index 4b8ce36a..0fc56186 100644
--- a/juick-api/build.gradle
+++ b/juick-api/build.gradle
@@ -27,6 +27,7 @@ dependencies {
compile 'org.msbotframework4j:msbotframework4j-builder:0.1.4'
compile 'com.neovisionaries:nv-websocket-client:1.27'
compile 'org.apache.commons:commons-dbcp2:2.0'
+ compile 'net.coobird:thumbnailator:0.4.8'
providedRuntime 'mysql:mysql-connector-java:5.1.39'
}
compileJava.options.encoding = 'UTF-8'
diff --git a/juick-api/src/main/java/com/juick/api/Main.java b/juick-api/src/main/java/com/juick/api/Main.java
index 676aab79..47c4e448 100644
--- a/juick-api/src/main/java/com/juick/api/Main.java
+++ b/juick-api/src/main/java/com/juick/api/Main.java
@@ -30,6 +30,7 @@ import com.juick.xmpp.StreamComponent;
import com.juick.xmpp.extensions.JuickMessage;
import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
+import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -44,6 +45,9 @@ import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.net.Socket;
import java.net.URL;
+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.Properties;
@@ -68,6 +72,8 @@ public class Main extends HttpServlet implements Stream.StreamListener {
TelegramBotHook tgb;
SkypeEndpoint sep;
+ String tmpDir, imgDir;
+
@Override
public void init() throws ServletException {
super.init();
@@ -87,7 +93,8 @@ public class Main extends HttpServlet implements Stream.StreamListener {
sep = new SkypeEndpoint();
setupXmppComponent(conf.getProperty("xmpp_host", "localhost"), Integer.parseInt(conf.getProperty("xmpp_port", "5347")),
conf.getProperty("xmpp_jid", "api.localhost"), conf.getProperty("xmpp_password"));
-
+ tmpDir = conf.getProperty("upload_tmp_dir", "/var/www/juick.com/i/tmp/");
+ imgDir = conf.getProperty("img_path", "/var/www/juick.com/i/");
} catch (IOException e) {
log("API initialization error", e);
}
@@ -301,7 +308,14 @@ public class Main extends HttpServlet implements Stream.StreamListener {
String fname = mid + "." + 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, attachmentFName), 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();
@@ -422,7 +436,14 @@ public class Main extends HttpServlet implements Stream.StreamListener {
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, attachmentFName), 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();