diff options
Diffstat (limited to 'src/main/java/com/juick')
-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())); |