From ed9f1256cf2bfd93b749b6e2ef22114d7fcd89bc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 27 Sep 2018 22:47:07 +0300 Subject: drop unused post mappings --- .../juick/server/www/controllers/NewMessage.java | 116 --------------------- 1 file changed, 116 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server/www/controllers') diff --git a/juick-server/src/main/java/com/juick/server/www/controllers/NewMessage.java b/juick-server/src/main/java/com/juick/server/www/controllers/NewMessage.java index c476e5c2..6fb13009 100644 --- a/juick-server/src/main/java/com/juick/server/www/controllers/NewMessage.java +++ b/juick-server/src/main/java/com/juick/server/www/controllers/NewMessage.java @@ -105,74 +105,6 @@ public class NewMessage { .sorted((e1, e2) -> Integer.compare(e2.getUsageCount(), e1.getUsageCount())).map(t -> t.getTag().getName()).collect(Collectors.toList())); return "views/post"; } - - @PostMapping("/comment") - public String doPostComment( - @RequestParam Integer mid, - @RequestParam(required = false, defaultValue = "0") Integer rid, - @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String body, - @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String img, - @RequestParam(required = false) MultipartFile attach) throws IOException { - com.juick.User visitor = UserUtils.getCurrentUser(); - if (visitor.isAnonymous() || visitor.isBanned()) { - throw new HttpForbiddenException(); - } - com.juick.Message msg = messagesService.getMessage(mid); - if (msg == null) { - throw new HttpNotFoundException(); - } - - com.juick.Message reply = null; - if (rid > 0) { - reply = messagesService.getReply(mid, rid); - if (reply == null) { - throw new HttpNotFoundException(); - } - } - - if ((StringUtils.isEmpty(body) || body.length() > 4096) && StringUtils.isEmpty(img) && attach == null) { - throw new HttpBadRequestException(); - } - body = body.replace("\r", StringUtils.EMPTY); - - if ((msg.ReadOnly && msg.getUser().getUid() != visitor.getUid()) - || userService.isInBLAny(msg.getUser().getUid(), visitor.getUid()) - || (reply != null && userService.isInBLAny(reply.getUser().getUid(), visitor.getUid()))) { - throw new HttpForbiddenException(); - } - - URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir); - - if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) { - try { - URL imgUrl = new URL(img); - attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir); - } catch (Exception e) { - logger.error("DOWNLOAD ERROR", e); - throw new HttpBadRequestException(); - } - } - - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap params = new LinkedMultiValueMap<>(); - HttpEntity> request = new HttpEntity<>(params, headers); - - - params.add("body", rid == 0 ? String.format("#%d %s", mid, body) : String.format("#%d/%d %s", mid, rid, body)); - params.add("hash", userService.getHashByUID(visitor.getUid())); - if (StringUtils.isNotEmpty(attachmentFName.toString())) { - params.add("img", attachmentFName.toASCIIString()); - } - URI postUri = UriComponentsBuilder.fromUriString(apiUrl).path("/api/post").build().toUri(); - ResponseEntity result = rest.postForEntity( - postUri, - request, CommandResult.class); - logger.info("/comment: {}", jsonMapper.writeValueAsString(result.getBody())); - boolean wasReply = result.getBody().getNewMessage().isPresent(); - return wasReply ? "redirect:/" + msg.getUser().getName() + "/" + mid + "#" + result.getBody().getNewMessage().get().getRid() : "redirect:/" + msg.getUser().getName() + "/" + mid; - } - @PostMapping("/pm/send") public String doPostPM(@RequestParam(name = "uname", required = false) String unameParam, @RequestParam String body) throws IOException { @@ -212,52 +144,4 @@ public class NewMessage { return "redirect:/pm/sent"; } - @PostMapping("/post2") - public String doPostMessage(@RequestParam(name = "body", required = false) String bodyParam, - @RequestParam(required = false) String img, - @RequestParam(required = false) MultipartFile attach) throws IOException { - - com.juick.User visitor = UserUtils.getCurrentUser(); - if (visitor.isAnonymous() || visitor.isBanned()) { - throw new HttpForbiddenException(); - } - String body = StringUtils.isNotEmpty(bodyParam) ? bodyParam.replace("\r", StringUtils.EMPTY) : StringUtils.EMPTY; - - URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir); - - if (StringUtils.isBlank(attachmentFName.toString()) && StringUtils.isNotBlank(img)) { - try { - URL imgUrl = new URL(img); - attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir); - } catch (Exception e) { - logger.error("DOWNLOAD ERROR", e); - throw new HttpBadRequestException(); - } - } - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap params = new LinkedMultiValueMap<>(); - HttpEntity> request = new HttpEntity<>(params, headers); - - params.add("body", body); - params.add("hash", userService.getHashByUID(visitor.getUid())); - if (StringUtils.isNotEmpty(attachmentFName.toString())) { - params.add("img", attachmentFName.toASCIIString()); - } - URI postUri = UriComponentsBuilder.fromUriString(apiUrl).path("/api/post").build().toUri(); - try { - ResponseEntity result = rest.postForEntity(postUri, - request, CommandResult.class); - Message newMessage = result.getBody().getNewMessage().orElse(new Message()); - if (newMessage.getMid() > 0) { - logger.info("/post: {}", jsonMapper.writeValueAsString(result.getBody())); - return String.format("redirect:/%d", newMessage.getMid()); - } else { - logger.info("{} : {}", body, result.getBody().getText()); - } - } catch (HttpClientErrorException e) { - logger.error("post error", e); - } - return "redirect:/?show=my"; - } } -- cgit v1.2.3