aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www')
-rw-r--r--src/main/java/com/juick/www/WebApp.java5
-rw-r--r--src/main/java/com/juick/www/api/Post.java52
-rw-r--r--src/main/java/com/juick/www/api/Service.java7
-rw-r--r--src/main/java/com/juick/www/api/Users.java8
-rw-r--r--src/main/java/com/juick/www/controllers/Settings.java8
-rw-r--r--src/main/java/com/juick/www/rss/MessagesView.java43
6 files changed, 66 insertions, 57 deletions
diff --git a/src/main/java/com/juick/www/WebApp.java b/src/main/java/com/juick/www/WebApp.java
index cebedb9b..85e21b1a 100644
--- a/src/main/java/com/juick/www/WebApp.java
+++ b/src/main/java/com/juick/www/WebApp.java
@@ -19,6 +19,7 @@ package com.juick.www;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -30,9 +31,11 @@ import java.util.stream.Stream;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
+import com.juick.model.Attachment;
import com.juick.model.Message;
import com.juick.model.Tag;
import com.juick.model.User;
+import com.juick.service.StorageService;
import com.juick.service.TagService;
import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
@@ -50,6 +53,8 @@ import org.springframework.web.util.UriComponentsBuilder;
@Component
public class WebApp {
@Inject
+ private StorageService storageService;
+ @Inject
private TagService tagService;
@Inject
private ResourceUrlProvider resourceUrlProvider;
diff --git a/src/main/java/com/juick/www/api/Post.java b/src/main/java/com/juick/www/api/Post.java
index c993ebe3..bced92bf 100644
--- a/src/main/java/com/juick/www/api/Post.java
+++ b/src/main/java/com/juick/www/api/Post.java
@@ -17,38 +17,46 @@
package com.juick.www.api;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+import java.util.Optional;
+
+import javax.inject.Inject;
+import javax.validation.constraints.NotNull;
+
+import com.juick.ActivityPubManager;
+import com.juick.CommandsManager;
+import com.juick.model.CommandResult;
import com.juick.model.Message;
import com.juick.model.Reaction;
import com.juick.model.Status;
import com.juick.model.User;
-import com.juick.model.CommandResult;
-import com.juick.ActivityPubManager;
-import com.juick.CommandsManager;
-import com.juick.util.HttpBadRequestException;
-import com.juick.util.HttpForbiddenException;
-import com.juick.util.HttpNotFoundException;
-import com.juick.util.HttpUtils;
import com.juick.service.MessagesService;
+import com.juick.service.StorageService;
import com.juick.service.UserService;
import com.juick.service.activities.UpdateEvent;
import com.juick.service.security.annotation.Visitor;
+import com.juick.util.HttpBadRequestException;
+import com.juick.util.HttpForbiddenException;
+import com.juick.util.HttpNotFoundException;
+import com.juick.util.HttpUtils;
+
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
-import javax.inject.Inject;
-import javax.validation.constraints.NotNull;
-import java.net.URI;
-import java.net.URL;
-import java.util.List;
-import java.util.Optional;
-
/**
* Created by vt on 24/11/2016.
*/
@@ -60,8 +68,8 @@ public class Post {
private UserService userService;
@Inject
private MessagesService messagesService;
- @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String tmpDir;
+ @Inject
+ private StorageService storageService;
@Inject
CommandsManager commandsManager;
@Inject
@@ -78,7 +86,7 @@ public class Post {
@RequestParam(required = false) MultipartFile attach) throws Exception {
body = body.replace("\r", StringUtils.EMPTY);
- URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
+ URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, storageService.getTemporaryDirectory());
if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) {
URI juickUri = URI.create(img);
@@ -87,7 +95,7 @@ public class Post {
} else {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir);
+ attachmentFName = HttpUtils.downloadImage(imgUrl, storageService.getTemporaryDirectory());
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
@@ -135,11 +143,11 @@ public class Post {
throw new HttpForbiddenException();
}
- URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir);
+ URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, storageService.getTemporaryDirectory());
if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) {
try {
- attachmentFName = HttpUtils.downloadImage(new URL(img), tmpDir);
+ attachmentFName = HttpUtils.downloadImage(new URL(img), storageService.getTemporaryDirectory());
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
diff --git a/src/main/java/com/juick/www/api/Service.java b/src/main/java/com/juick/www/api/Service.java
index fc0132b1..f7c7a4aa 100644
--- a/src/main/java/com/juick/www/api/Service.java
+++ b/src/main/java/com/juick/www/api/Service.java
@@ -27,6 +27,7 @@ import com.juick.util.HttpBadRequestException;
import com.juick.util.HttpForbiddenException;
import com.juick.service.EmailService;
import com.juick.service.MessagesService;
+import com.juick.service.StorageService;
import com.juick.service.UserService;
import com.juick.service.component.AccountVerificationEvent;
import com.juick.service.security.annotation.Visitor;
@@ -77,8 +78,8 @@ public class Service {
private ApplicationEventPublisher applicationEventPublisher;
@Inject
private User serviceUser;
- @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String tmpDir;
+ @Inject
+ private StorageService storageService;
@Value("${banned_emails:}")
private String[] ignoredEmails;
@Inject
@@ -139,7 +140,7 @@ public class Service {
try {
logger.info("got inputstream: {}", a.getInputStream());
FileOutputStream fos = new FileOutputStream(
- Paths.get(tmpDir, attachmentFName[0]).toString());
+ Paths.get(storageService.getTemporaryDirectory(), attachmentFName[0]).toString());
IOUtils.copy(a.getInputStream(), fos);
fos.close();
} catch (IOException e) {
diff --git a/src/main/java/com/juick/www/api/Users.java b/src/main/java/com/juick/www/api/Users.java
index 0294ec53..49a4494f 100644
--- a/src/main/java/com/juick/www/api/Users.java
+++ b/src/main/java/com/juick/www/api/Users.java
@@ -63,9 +63,7 @@ public class Users {
@Inject
private WebApp webApp;
@Inject
- private ImagesService imagesService;
- @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String tmpDir;
+ private StorageService storageService;
@Inject
private ApplicationEventPublisher applicationEventPublisher;
@@ -168,9 +166,9 @@ public class Users {
@PostMapping("/api/me/upload")
public void updateInfo(@Visitor User visitor,
@RequestParam MultipartFile avatar) throws IOException {
- String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir).getHost();
+ String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, storageService.getTemporaryDirectory()).getHost();
if (StringUtils.isNotEmpty(avatarTmpPath)) {
- imagesService.saveAvatar(avatarTmpPath, visitor.getUid());
+ storageService.saveAvatar(avatarTmpPath, visitor);
applicationEventPublisher.publishEvent(new UpdateUserEvent(this, visitor));
}
}
diff --git a/src/main/java/com/juick/www/controllers/Settings.java b/src/main/java/com/juick/www/controllers/Settings.java
index 50b4ea14..a5597735 100644
--- a/src/main/java/com/juick/www/controllers/Settings.java
+++ b/src/main/java/com/juick/www/controllers/Settings.java
@@ -63,8 +63,6 @@ import java.util.stream.IntStream;
public class Settings {
private static final Logger logger = LoggerFactory.getLogger(Settings.class);
- @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String tmpDir;
@Inject
private TagService tagService;
@Inject
@@ -76,7 +74,7 @@ public class Settings {
@Inject
private TelegramService telegramService;
@Inject
- private ImagesService imagesService;
+ private StorageService storageService;
@Inject
private WebApp webApp;
@Inject
@@ -166,9 +164,9 @@ public class Settings {
visitor.setCountry(request.getParameter("country"));
visitor.setUrl(request.getParameter("url"));
visitor.setDescription(request.getParameter("descr"));
- String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir).getHost();
+ String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, storageService.getTemporaryDirectory()).getHost();
if (StringUtils.isNotEmpty(avatarTmpPath)) {
- imagesService.saveAvatar(avatarTmpPath, visitor.getUid());
+ storageService.saveAvatar(avatarTmpPath, visitor);
}
if (userService.updateUserInfo(visitor)) {
result = String.format("<p>Your info is updated.</p><p><a href='/%s/'>Back to blog</a>.</p>", visitor.getName());
diff --git a/src/main/java/com/juick/www/rss/MessagesView.java b/src/main/java/com/juick/www/rss/MessagesView.java
index 6355c47d..2c7d4a7d 100644
--- a/src/main/java/com/juick/www/rss/MessagesView.java
+++ b/src/main/java/com/juick/www/rss/MessagesView.java
@@ -17,14 +17,29 @@
package com.juick.www.rss;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.annotation.Nonnull;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import com.juick.model.Attachment;
import com.juick.model.Message;
import com.juick.model.User;
-import com.juick.service.ImagesService;
+import com.juick.service.StorageService;
+import com.juick.util.MessageUtils;
+import com.juick.www.WebApp;
import com.juick.www.rss.extension.JuickModule;
import com.juick.www.rss.extension.JuickModuleImpl;
-import com.juick.www.WebApp;
-import com.juick.util.MessageUtils;
import com.rometools.modules.atom.modules.AtomLinkModule;
import com.rometools.modules.atom.modules.AtomLinkModuleImpl;
import com.rometools.modules.mediarss.MediaEntryModuleImpl;
@@ -47,21 +62,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
-import javax.annotation.Nonnull;
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
/**
* Created by vitalyster on 13.12.2016.
*/
@@ -70,9 +70,9 @@ public class MessagesView extends AbstractRssFeedView {
private static final Logger logger = LoggerFactory.getLogger(Feeds.class);
@Inject
- private WebApp webApp;
+ private StorageService storageService;
@Inject
- private ImagesService imagesService;
+ private WebApp webApp;
@PostConstruct
public void init() {
@@ -99,12 +99,11 @@ public class MessagesView extends AbstractRssFeedView {
String link = String.format("https://juick.com/%s/", user.getName());
feed.setLink(link);
try {
+ Attachment avatar = storageService.getAvatarMetadata(user);
Image rssImage = new Image();
rssImage.setUrl(webApp.getAvatarUrl(user));
rssImage.setTitle(title);
rssImage.setLink(link);
- Attachment avatar;
- avatar = imagesService.getImageMetadata(rssImage.getUrl());
rssImage.setHeight(avatar.getHeight());
rssImage.setWidth(avatar.getWidth());
feed.setImage(rssImage);