diff options
Diffstat (limited to 'juick-xmpp-ft/src/main/java/com/juick')
-rw-r--r-- | juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java index 37ca7ec6..6726a156 100644 --- a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java +++ b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java @@ -16,6 +16,8 @@ import rocks.xmpp.extensions.oob.model.x.OobX; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; @@ -39,7 +41,8 @@ public class XMPPFTServer { fileTransferManager.addFileTransferOfferListener(e -> { try { List<String> allowedTypes = new ArrayList<String>() {{ add("png"); add("jpg"); }}; - if (allowedTypes.contains(FilenameUtils.getExtension(e.getName()))) { + String attachmentExtension = FilenameUtils.getExtension(e.getName()); + if (allowedTypes.contains(attachmentExtension)) { Path filePath = Paths.get(tmpDir, e.getName()); FileTransfer ft = e.accept(filePath).get(); ft.addFileTransferStatusListener(st -> { @@ -52,10 +55,13 @@ public class XMPPFTServer { msg.setTo(Jid.of(juickJid)); msg.setBody(e.getDescription()); try { - String attachmentUrl = DigestUtils.md5Hex(String.format("%s-%s", e.getInitiator().toString(), e.getSessionId()).getBytes()); - msg.addExtension(new OobX(new URL(attachmentUrl), "!!!!Juick!!")); + String attachmentUrl = String.format("juick://%s.%s", + DigestUtils.md5Hex(String.format("%s-%s", + e.getInitiator().toString(), e.getSessionId()).getBytes()), + attachmentExtension); + msg.addExtension(new OobX(new URI(attachmentUrl).toURL(), "!!!!Juick!!")); component.sendMessage(msg); - } catch (MalformedURLException e1) { + } catch (MalformedURLException | URISyntaxException e1) { logger.warn("attachment error", e1); } } |