aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-10-23 08:09:05 +0300
committerGravatar Vitaly Takmazov2021-10-23 08:10:06 +0300
commit4b96a9b2e71b7a67effdd55b26ca532ff849d0ef (patch)
tree597a9b268622a10b440f3b119c529e624b8fdb62 /src/main/java/com/juick/www/api
parent6b31c254b5a7ab6735c625459ba7936d9b2851e6 (diff)
ImagesService -> StorageService
img_path -> storage_path property
Diffstat (limited to 'src/main/java/com/juick/www/api')
-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
3 files changed, 37 insertions, 30 deletions
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));
}
}