diff options
Diffstat (limited to 'juick-server/src/main/java')
3 files changed, 14 insertions, 5 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java index cc63a4ce..3a32b4e5 100644 --- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java +++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java @@ -2,6 +2,7 @@ package com.juick.server; import com.juick.Message; import com.juick.User; +import com.juick.server.api.activity.model.Image; import com.juick.server.api.activity.model.Link; import com.juick.server.api.activity.model.Note; import com.juick.server.api.activity.model.Person; @@ -9,6 +10,7 @@ import com.juick.server.api.activity.model.activities.Accept; import com.juick.server.api.activity.model.activities.Announce; import com.juick.server.api.activity.model.activities.Create; import com.juick.server.api.activity.model.activities.Delete; +import com.juick.server.util.HttpUtils; import com.juick.service.SocialService; import com.juick.service.UserService; import com.juick.service.activities.*; @@ -192,8 +194,10 @@ public class ActivityPubManager implements ActivityListener, NotificationListene note.setPublished(msg.getTimestamp()); note.setContent(MessageUtils.formatMessage(msg.getText())); if (StringUtils.isNotBlank(msg.getAttachmentType())) { - Link attachment = new Link(); - attachment.setHref(msg.getAttachment().getMedium().getUrl()); + Image attachment = new Image(); + attachment.setId(msg.getAttachment().getMedium().getUrl()); + attachment.setUrl(msg.getAttachment().getMedium().getUrl()); + attachment.setMediaType(HttpUtils.mediaType(msg.getAttachmentType())); note.setAttachment(attachment); } return note; diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java index 61a64f8d..83ef36dd 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java @@ -6,7 +6,7 @@ public class Note extends Context { private String content; private String attributedTo; private String inReplyTo; - private Link attachment; + private Image attachment; private List<String> to; private List<String> cc; @@ -26,11 +26,11 @@ public class Note extends Context { this.attributedTo = attributedTo; } - public Link getAttachment() { + public Image getAttachment() { return attachment; } - public void setAttachment(Link attachment) { + public void setAttachment(Image attachment) { this.attachment = attachment; } diff --git a/juick-server/src/main/java/com/juick/server/util/HttpUtils.java b/juick-server/src/main/java/com/juick/server/util/HttpUtils.java index 9f356aa5..b70eb3ad 100644 --- a/juick-server/src/main/java/com/juick/server/util/HttpUtils.java +++ b/juick-server/src/main/java/com/juick/server/util/HttpUtils.java @@ -20,6 +20,7 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; import org.springframework.web.multipart.MultipartFile; import javax.imageio.ImageIO; @@ -79,6 +80,10 @@ public class HttpUtils { } } + public static String mediaType(String attachmentType) { + return attachmentType.equals("jpg") ? MediaType.IMAGE_JPEG_VALUE : MediaType.IMAGE_PNG_VALUE; + } + public static URI downloadImage(URL url, String tmpDir) throws IOException { ImageInputStream iis = ImageIO.createImageInputStream(url.openStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); |