From d6e4aa12983c466ecff0a6fdc32e1a5c415baa68 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 5 Oct 2018 13:23:14 +0300 Subject: ActivityPub: encode message and reply urls --- .../main/java/com/juick/server/api/activity/Profile.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server/api') 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}) -- cgit v1.2.3