aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java/com')
-rw-r--r--juick-www/src/main/java/com/juick/www/WebApp.java12
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java21
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Settings.java11
3 files changed, 20 insertions, 24 deletions
diff --git a/juick-www/src/main/java/com/juick/www/WebApp.java b/juick-www/src/main/java/com/juick/www/WebApp.java
index 4c706426..c3437c0b 100644
--- a/juick-www/src/main/java/com/juick/www/WebApp.java
+++ b/juick-www/src/main/java/com/juick/www/WebApp.java
@@ -49,10 +49,6 @@ public class WebApp implements DisposableBean {
@Inject
private TagService tagService;
- @Value("${img_path:/var/www/juick.com/i/}")
- private String imgDir;
- @Value("${upload_tmp_dir:/var/www/juick.com/i/tmp/}")
- private String tmpDir;
@Value("${xmpp_host:localhost}")
private String xmppHost;
@Value("${xmpp_password:secret}")
@@ -104,14 +100,6 @@ public class WebApp implements DisposableBean {
return xmpp;
}
- public String getImgDir() {
- return imgDir;
- }
-
- public String getTmpDir() {
- return tmpDir;
- }
-
public List<Tag> parseTags(String tagsStr) {
List<Tag> tags = new ArrayList<>();
if (tagsStr != null && !tagsStr.isEmpty()) {
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 8f7c8059..d188dfbe 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
@@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
@@ -65,6 +66,10 @@ public class NewMessage {
private PMQueriesService pmQueriesService;
@Inject
private WebApp webApp;
+ @Value("${img_path:/var/www/juick.com/i/}")
+ private String imgDir;
+ @Value("${upload_tmp_dir:/var/www/juick.com/i/tmp/}")
+ private String tmpDir;
private static final Logger logger = LoggerFactory.getLogger(NewMessage.class);
@@ -102,12 +107,12 @@ public class NewMessage {
List<Tag> tags = webApp.parseTags(tagsStr);
- String attachmentFName = HttpUtils.receiveMultiPartFile(attach, webApp.getTmpDir());
+ String attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
if (StringUtils.isBlank(attachmentFName) && StringUtils.isNotBlank(img)) {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl, webApp.getTmpDir());
+ attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
@@ -130,7 +135,7 @@ public class NewMessage {
String fname = mid + "." + attachmentType;
String attachmentURL = "http://i.juick.com/photos-1024/" + fname;
- ImageUtils.saveImageWithPreviews(attachmentFName, fname, webApp.getTmpDir(), webApp.getImgDir());
+ ImageUtils.saveImageWithPreviews(attachmentFName, fname, tmpDir, imgDir);
body = attachmentURL + "\n" + body;
try {
@@ -225,12 +230,12 @@ public class NewMessage {
throw new HttpForbiddenException();
}
- String attachmentFName = HttpUtils.receiveMultiPartFile(attach, webApp.getTmpDir());
+ String attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl, webApp.getTmpDir());
+ attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
@@ -259,7 +264,7 @@ public class NewMessage {
String fname = mid + "-" + ridnew + "." + attachmentType;
String attachmentURL = "http://i.juick.com/photos-1024/" + fname;
- ImageUtils.saveImageWithPreviews(attachmentFName, fname, webApp.getTmpDir(), webApp.getImgDir());
+ ImageUtils.saveImageWithPreviews(attachmentFName, fname, tmpDir, imgDir);
body = attachmentURL + "\n" + body;
try {
@@ -397,12 +402,12 @@ public class NewMessage {
}
String body = bodyParam.replace("\r", StringUtils.EMPTY);
- String attachmentFName = HttpUtils.receiveMultiPartFile(attach, webApp.getTmpDir());
+ String attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl, webApp.getTmpDir());
+ attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
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 b49c0f1c..db60acba 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
@@ -28,6 +28,7 @@ import com.juick.www.WebApp;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
@@ -60,8 +61,10 @@ import java.util.stream.IntStream;
public class Settings {
private static final Logger logger = LoggerFactory.getLogger(Settings.class);
- @Inject
- private WebApp webApp;
+ @Value("${img_path:/var/www/juick.com/i/}")
+ private String imgDir;
+ @Value("${upload_tmp_dir:/var/www/juick.com/i/tmp/}")
+ private String tmpDir;
@Inject
private TagService tagService;
@Inject
@@ -156,9 +159,9 @@ public class Settings {
info.setCountry(request.getParameter("country"));
info.setUrl(request.getParameter("url"));
info.setDescription(request.getParameter("descr"));
- String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, webApp.getTmpDir());
+ String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir);
if (StringUtils.isNotEmpty(avatarTmpPath)) {
- ImageUtils.saveAvatar(avatarTmpPath, visitor.getUid(), webApp.getTmpDir(), webApp.getImgDir());
+ ImageUtils.saveAvatar(avatarTmpPath, visitor.getUid(), tmpDir, imgDir);
}
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());