aboutsummaryrefslogtreecommitdiff
path: root/juick-common/src/main/java/com/juick/server/CommandsManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-07-24 14:08:36 +0300
committerGravatar Vitaly Takmazov2018-07-24 14:08:36 +0300
commit3fa18888d5ca53b59c778de3f829870614d05c27 (patch)
tree7e38b5838a45ae783e0cb636b4fb10ddcedfbf97 /juick-common/src/main/java/com/juick/server/CommandsManager.java
parent10ee29dcb05f992fe2b7aa726b6ac7c9e9aba87d (diff)
Ignore uploaded file extension
* guess content type from content stream
Diffstat (limited to 'juick-common/src/main/java/com/juick/server/CommandsManager.java')
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java
index b9f27940..7dd372b1 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -106,12 +106,17 @@ public class CommandsManager {
}
// new message
String body = TagUtils.toString(tags).equals(input) ? StringUtils.EMPTY : input.substring(TagUtils.toString(tags).length()).trim();
- String attachmentType = StringUtils.isNotEmpty(attachment.toString()) ? attachment.toString().substring(attachment.toString().length() - 3) : null;
+ boolean haveAttachment = StringUtils.isNotEmpty(attachment.toString());
+ 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);
+ }
int mid = messagesService.createMessage(user.getUid(), body, attachmentType, tags);
subscriptionService.subscribeMessage(messagesService.getMessage(mid), user);
- if (StringUtils.isNotEmpty(attachmentType)) {
- String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost()
- : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
+ if (haveAttachment) {
String fname = String.format("%d.%s", mid, attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
}
@@ -494,13 +499,17 @@ public class CommandsManager {
return CommandResult.fromString("Tags are NOT updated (5 tags maximum?)");
}
} else {
- String attachmentStr = attachment.toString();
- String attachmentType = StringUtils.isNotEmpty(attachmentStr) ? attachmentStr.substring(attachmentStr.length() - 3) : null;
+ boolean haveAttachment = StringUtils.isNotEmpty(attachment.toString());
+ 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);
+ }
int newrid = messagesService.createReply(mid, rid, user, txt, attachmentType);
applicationEventPublisher.publishEvent(new MessageReadEvent(this, user, msg));
- if (StringUtils.isNotEmpty(attachmentType)) {
- String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost()
- : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost();
+ if (haveAttachment) {
String fname = String.format("%d-%d.%s", mid, newrid, attachmentType);
imagesService.saveImageWithPreviews(attachmentFName, fname);
}