diff options
author | Vitaly Takmazov | 2019-01-30 09:40:15 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-01-30 09:40:15 +0300 |
commit | 8bcb61d239a9c56641d60b861a92c1a339994e52 (patch) | |
tree | 6f12aa42842544b52c3f25fe07c7f7386c638b8a /src/main/java | |
parent | b09dac438ad29903a79916d20c90e1a2154fabf6 (diff) |
Append URL if attachment can not be downloaded
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/juick/server/CommandsManager.java | 23 | ||||
-rw-r--r-- | src/main/java/com/juick/server/SignatureManager.java | 2 |
2 files changed, 19 insertions, 6 deletions
diff --git a/src/main/java/com/juick/server/CommandsManager.java b/src/main/java/com/juick/server/CommandsManager.java index 4a7f90ef..1c726e60 100644 --- a/src/main/java/com/juick/server/CommandsManager.java +++ b/src/main/java/com/juick/server/CommandsManager.java @@ -35,12 +35,15 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.lang3.tuple.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Component; import javax.annotation.Nonnull; import javax.inject.Inject; +import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; import java.util.*; @@ -54,6 +57,7 @@ import java.util.stream.Collectors; */ @Component public class CommandsManager { + private static final Logger logger = LoggerFactory.getLogger(CommandsManager.class); @Inject private MessagesService messagesService; @Inject @@ -527,12 +531,21 @@ public class CommandsManager { String attachmentFName = null; String attachmentType = null; if (haveAttachment) { - attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost() - : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost(); - attachmentType = attachmentFName.substring(attachmentFName.length() - 3); + if (attachment.getScheme().equals("juick")) { + attachmentFName = attachment.getHost(); + attachmentType = attachmentFName.substring(attachmentFName.length() - 3); + } else { + try { + attachmentFName = HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost(); + } catch (IOException e) { + logger.warn("Can not download {}", attachment.toURL()); + } + } } - int newrid = messagesService.createReply(mid, rid, user, txt, attachmentType); - if (haveAttachment) { + boolean attachmentDownloaded = StringUtils.isNotEmpty(attachmentType); + String messageText = attachmentDownloaded ? txt : String.format("%s %s", txt, attachment.toASCIIString()); + int newrid = messagesService.createReply(mid, rid, user, messageText, attachmentType); + if (attachmentDownloaded) { String fname = String.format("%d-%d.%s", mid, newrid, attachmentType); imagesService.saveImageWithPreviews(attachmentFName, fname); } diff --git a/src/main/java/com/juick/server/SignatureManager.java b/src/main/java/com/juick/server/SignatureManager.java index 23f5c37a..083a5edf 100644 --- a/src/main/java/com/juick/server/SignatureManager.java +++ b/src/main/java/com/juick/server/SignatureManager.java @@ -98,7 +98,7 @@ public class SignatureManager { Verifier verifier = new Verifier(key, signature); try { boolean result = verifier.verify(method, path, headers); - logger.info("signature is valid: {}", result); + logger.info("signature of {} is valid: {}", signature.getKeyId(), result); if (result) { User user = new User(); user.setUri(URI.create(person.getId())); |