diff options
author | Vitaly Takmazov | 2018-10-05 13:23:14 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-10-05 13:26:48 +0300 |
commit | d6e4aa12983c466ecff0a6fdc32e1a5c415baa68 (patch) | |
tree | fcf573111bc2699725fcde8f7e9c7b02e8a9cf66 /juick-server/src/main | |
parent | 25e10eabde194dd75d3f91d2ed5683f1858cf7e1 (diff) |
ActivityPub: encode message and reply urls
Diffstat (limited to 'juick-server/src/main')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/ActivityPubManager.java | 16 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/activity/Profile.java | 16 |
2 files changed, 18 insertions, 14 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 77f96347..46b7177f 100644 --- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java +++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java @@ -22,6 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import org.springframework.util.Base64Utils; import org.springframework.web.util.UriComponentsBuilder; import javax.annotation.Nonnull; @@ -167,19 +168,14 @@ public class ActivityPubManager implements ActivityListener, NotificationListene return uri.replacePath(String.format("/u/%s/following/toc", user.getName())).toUriString(); } public String messageUri(Message msg) { - UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); - uri.replacePath(String.format("/n/%d", msg.getMid())); - if (MessageUtils.isReply(msg)) { - uri.fragment(String.valueOf(msg.getRid())); - } - return uri.toUriString(); + return messageUri(msg.getMid(), msg.getRid()); } public String messageUri(int mid, int rid) { UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); - uri.replacePath(String.format("/n/%d", mid)); - if (rid > 0) { - uri.fragment(String.valueOf(rid)); - } + String postId = rid > 0 ? + String.format("%d#%d", mid, rid) + : String.valueOf(mid); + uri.replacePath(String.format("/n/%s", Base64Utils.encodeToUrlSafeString(postId.getBytes()))); return uri.toUriString(); } diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java index 98d2ba9d..4186539d 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.util.Base64Utils; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import org.springframework.web.util.UriComponents; @@ -222,10 +223,17 @@ public class Profile { throw new HttpNotFoundException(); } - @GetMapping(value = "/n/{mid}", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_JSON_MEDIA_TYPE}) - public Context showNote(@PathVariable int mid) { - Message message = messagesService.getMessage(mid); - return Context.build(activityPubManager.makeNote(message)); + @GetMapping(value = "/n/{base64id}", produces = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_JSON_MEDIA_TYPE}) + public Context showNote(@PathVariable String base64id) { + String postId = new String(Base64Utils.decodeFromUrlSafeString(base64id)); + String[] ids = postId.split("#", 2); + if (ids.length > 1) { + // reply + return Context.build(activityPubManager.makeNote( + messagesService.getReply(Integer.valueOf(ids[0]), Integer.valueOf(ids[1])))); + } + return Context.build(activityPubManager.makeNote( + messagesService.getMessage(Integer.valueOf(ids[0])))); } @PostMapping(value = "/api/inbox", consumes = {Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_JSON_MEDIA_TYPE}) |