handler for POST requests to user inboxes
This commit is contained in:
parent
be59844d57
commit
a88f154714
1 changed files with 47 additions and 0 deletions
|
|
@ -1,10 +1,13 @@
|
|||
package dev.activitypub.activitypubbot;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -15,10 +18,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Here we handle any JSON/REST requests, which is how ActivityPub instances talk to each other.
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class RestHandler {
|
||||
|
||||
|
|
@ -82,4 +87,46 @@ public class RestHandler {
|
|||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString( response );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@PostMapping(value = "/users/{username}/inbox", produces = "application/activity+json") // content type based on Masto request
|
||||
public String inboxpost(@PathVariable String username, @RequestBody Map<String, Object> postdata) {
|
||||
log.info("RestHandler::inboxpost: " + username + " map: " + postdata.toString());
|
||||
Bot bot = botServ.getBotByUsername( username );
|
||||
if( bot == null ) {
|
||||
//return new ResponseEntity<>("These are not the droids you are looking for.", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
if( !postdata.containsKey("type") ) {
|
||||
// no request type, so we think we've been sent junk
|
||||
throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, "No request 'type' specified.");
|
||||
}
|
||||
|
||||
// What sort of inbox post is this... we probably eventually want the terms
|
||||
// here to be via some sort of request type handler registry. Perhaps an
|
||||
// ActivityPubActivity interface defining some consumer of JSON...
|
||||
switch ((String)postdata.get("type")) {
|
||||
case "Follow":
|
||||
// process a follow request, a job for BotService? FollowService? How to represent a "follow"...
|
||||
// Note: https://w3c.github.io/activitypub/#followers
|
||||
return "{ follow: \"the leader\"; }";
|
||||
case "Create":
|
||||
case "Update":
|
||||
case "Delete":
|
||||
case "Accept":
|
||||
case "Reject":
|
||||
case "Add":
|
||||
case "Remove":
|
||||
case "Announce":
|
||||
case "Undo":
|
||||
// not implemented:
|
||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Nope!");
|
||||
default:
|
||||
// unprocessable content
|
||||
throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, "Unknown 'type': " + postdata.get("type") );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue