aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-09-18 17:06:32 +0300
committerGravatar Vitaly Takmazov2019-09-18 17:06:32 +0300
commitd040ad6d6270c4aa269eeee741c8caac2145d626 (patch)
tree78cb07d5bafd9efff4cb006f7204f8f3c62db448
parent7ca0d89a7207994a8d03c8e38c1aef96fcda23ff (diff)
Parse events from /new_event endpoint
-rw-r--r--src/main/java/com/juick/server/api/Service.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/com/juick/server/api/Service.java b/src/main/java/com/juick/server/api/Service.java
index f137f2f7..b1a9e73d 100644
--- a/src/main/java/com/juick/server/api/Service.java
+++ b/src/main/java/com/juick/server/api/Service.java
@@ -159,6 +159,31 @@ public class Service {
throw new HttpForbiddenException();
}
}
+ @ApiIgnore
+ @PostMapping("/api/new_event")
+ @ResponseStatus(value = HttpStatus.OK)
+ public void processEvent(@Visitor User current, InputStream data) throws Exception {
+ if (current.getName().equals(serviceUser)) {
+ MimeMessage msg = new MimeMessage(session, data);
+ MimeMessageParser parser = new MimeMessageParser(msg);
+ parser.parse();
+ final String[] body = { parser.getPlainContent() };
+ if (body[0] == null) {
+ parser.getAttachmentList().stream()
+ .filter(a -> a.getContentType().equals("text/plain")).findFirst()
+ .ifPresent(a -> {
+ try {
+ body[0] = IOUtils.toString(a.getInputStream(), StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ logger.info("attachment error", e);
+ }
+ });
+ }
+ logger.info("got text event: {}", body[0]);
+ } else {
+ throw new HttpForbiddenException();
+ }
+ }
private void endSession(SseEmitter emitter) {
serverManager.getSessions().stream()
.filter(s -> s.getEmitter().equals(emitter))