diff options
Diffstat (limited to 'src/main/java/com/juick/CommandsManager.java')
-rw-r--r-- | src/main/java/com/juick/CommandsManager.java | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/src/main/java/com/juick/CommandsManager.java b/src/main/java/com/juick/CommandsManager.java index e2a50444..6d315a7d 100644 --- a/src/main/java/com/juick/CommandsManager.java +++ b/src/main/java/com/juick/CommandsManager.java @@ -17,20 +17,44 @@ package com.juick; +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import javax.annotation.Nonnull; +import javax.inject.Inject; + +import com.juick.model.CommandResult; import com.juick.model.Message; import com.juick.model.Tag; -import com.juick.model.User; -import com.juick.util.formatters.PlainTextFormatter; -import com.juick.model.CommandResult; import com.juick.model.TagStats; -import com.juick.www.api.SystemActivity; -import com.juick.util.annotation.UserCommand; -import com.juick.util.HttpUtils; -import com.juick.www.WebApp; -import com.juick.service.*; +import com.juick.model.User; +import com.juick.service.MessagesService; +import com.juick.service.PMQueriesService; +import com.juick.service.PrivacyQueriesService; +import com.juick.service.ShowQueriesService; +import com.juick.service.StorageService; +import com.juick.service.SubscriptionService; +import com.juick.service.TagService; +import com.juick.service.UserService; import com.juick.service.activities.DeleteMessageEvent; -import com.juick.service.component.*; +import com.juick.service.component.PingEvent; +import com.juick.service.component.SystemEvent; +import com.juick.util.HttpUtils; import com.juick.util.MessageUtils; +import com.juick.util.annotation.UserCommand; +import com.juick.util.formatters.PlainTextFormatter; +import com.juick.www.WebApp; +import com.juick.www.api.SystemActivity; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; @@ -39,19 +63,8 @@ import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; -import javax.annotation.Nonnull; -import javax.inject.Inject; -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.URI; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - /** * * @author ugnich @@ -72,12 +85,10 @@ public class CommandsManager { private PrivacyQueriesService privacyQueriesService; @Inject private SubscriptionService subscriptionService; - @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}") - private String tmpDir; @Inject - private ApplicationEventPublisher applicationEventPublisher; + private StorageService storageService; @Inject - private ImagesService imagesService; + private ApplicationEventPublisher applicationEventPublisher; @Inject private WebApp webApp; @Inject @@ -125,7 +136,7 @@ public class CommandsManager { String attachmentType = null; if (haveAttachment) { attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost() - : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost(); + : HttpUtils.downloadImage(attachment.toURL(), storageService.getTemporaryDirectory()).getHost(); attachmentType = attachmentFName.substring(attachmentFName.length() - 3); } if (StringUtils.isEmpty(body) && !haveAttachment) { @@ -134,7 +145,7 @@ public class CommandsManager { int mid = messagesService.createMessage(user.getUid(), body, attachmentType, tags.getRight()); if (haveAttachment) { String fname = String.format("%d.%s", mid, attachmentType); - imagesService.saveImageWithPreviews(attachmentFName, fname); + storageService.saveImageWithPreviews(attachmentFName, fname); } Message msg = messagesService.getMessage(mid).orElseThrow(IllegalStateException::new); msg.getUser().setAvatar(webApp.getAvatarUrl(msg.getUser())); @@ -548,7 +559,7 @@ public class CommandsManager { attachmentType = attachmentFName.substring(attachmentFName.length() - 3); } else { try { - attachmentFName = HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost(); + attachmentFName = HttpUtils.downloadImage(attachment.toURL(), storageService.getTemporaryDirectory()).getHost(); attachmentType = attachmentFName.substring(attachmentFName.length() - 3); } catch (IOException e) { logger.warn("Can not download {}", attachment.toURL()); @@ -561,7 +572,7 @@ public class CommandsManager { if (newrid > 0) { if (haveAttachment && attachmentProcessed) { String fname = String.format("%d-%d.%s", mid, newrid, attachmentType); - imagesService.saveImageWithPreviews(attachmentFName, fname); + storageService.saveImageWithPreviews(attachmentFName, fname); } applicationEventPublisher.publishEvent( new SystemEvent(this, SystemActivity.read(user, msg.get()))); |