diff options
author | Vitaly Takmazov | 2021-10-23 08:09:05 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2021-10-23 08:10:06 +0300 |
commit | 4b96a9b2e71b7a67effdd55b26ca532ff849d0ef (patch) | |
tree | 597a9b268622a10b440f3b119c529e624b8fdb62 /src/main/java/com/juick/www/api/Post.java | |
parent | 6b31c254b5a7ab6735c625459ba7936d9b2851e6 (diff) |
ImagesService -> StorageService
img_path -> storage_path property
Diffstat (limited to 'src/main/java/com/juick/www/api/Post.java')
-rw-r--r-- | src/main/java/com/juick/www/api/Post.java | 52 |
1 files changed, 30 insertions, 22 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(); |