From e17ac99c67e5069745f3f19a91c18b6d3288b6e9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Jan 2023 20:42:34 +0300 Subject: ActivityPub: cleanup media types and redirects --- src/main/java/com/juick/www/controllers/Site.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/juick/www/controllers') diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index e8acc650..cbc14496 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -477,11 +477,16 @@ public class Site { return "views/pm_sent"; } - @GetMapping(value = "/{uname}/{mid}", produces = { MediaType.TEXT_HTML_VALUE, Context.ACTIVITY_MEDIA_TYPE, - Context.LD_JSON_MEDIA_TYPE }) + @GetMapping(value = "/{uname}/{mid}", produces = { Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_MEDIA_TYPE, + Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE }) + public String threadRedirect(@PathVariable int mid) { + String linkedDataLocation = "/n/" + mid + "-0"; + return "redirect:" + linkedDataLocation; + } + + @GetMapping(value = "/{uname}/{mid}", consumes = MediaType.ALL_VALUE, produces = MediaType.TEXT_HTML_VALUE) protected String threadAction(@ModelAttribute User visitor, ModelMap model, @PathVariable String uname, @PathVariable int mid, - @RequestHeader(name = HttpHeaders.ACCEPT, required = false) String acceptHeader, @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie) { if (!messagesService.canViewThread(mid, visitor.getUid())) { throw new HttpForbiddenException(); @@ -499,16 +504,6 @@ public class Site { if (user.isAnonymous() || !msg.getUser().equals(user)) { return String.format("redirect:/%s/%d", msg.getUser().getName(), mid); } - String linkedDataLocation = "/n/" + mid + "-0"; - if (StringUtils.isNotBlank(acceptHeader)) { - var mediaTypes = MediaType.parseMediaTypes(acceptHeader); - var isLinkedDataRequest = (mediaTypes.stream().anyMatch(mediaType -> !mediaType.isWildcardType() - && (mediaType.isCompatibleWith(MediaType.valueOf(Context.ACTIVITY_MEDIA_TYPE)) - || mediaType.isCompatibleWith(MediaType.valueOf(Context.LD_JSON_MEDIA_TYPE))))); - if (isLinkedDataRequest) { - return "redirect:" + linkedDataLocation; - } - } msg.VisitorCanComment = !visitor.isAnonymous(); msg.getUser().setAvatar(webApp.getAvatarWebPath(msg.getUser())); List replies = messagesService.getReplies(visitor, msg.getMid()); -- cgit v1.2.3