diff options
author | Vitaly Takmazov | 2018-09-27 22:47:07 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-09-27 22:47:07 +0300 |
commit | ed9f1256cf2bfd93b749b6e2ef22114d7fcd89bc (patch) | |
tree | ed846bd7a981d763e659371088e19313c3b081a4 /juick-server/src/main | |
parent | 5f4af8dbe4c431218c4bd186a75f50c23b8e5df0 (diff) |
drop unused post mappings
Diffstat (limited to 'juick-server/src/main')
3 files changed, 2 insertions, 118 deletions
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<String, String> params = new LinkedMultiValueMap<>(); - HttpEntity<MultiValueMap<String, String>> 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<CommandResult> 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<String, String> params = new LinkedMultiValueMap<>(); - HttpEntity<MultiValueMap<String, String>> 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<CommandResult> 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"; - } } diff --git a/juick-server/src/main/resources/templates/views/post.html b/juick-server/src/main/resources/templates/views/post.html index 1f642ce1..3753b36c 100644 --- a/juick-server/src/main/resources/templates/views/post.html +++ b/juick-server/src/main/resources/templates/views/post.html @@ -2,7 +2,7 @@ {% import "views/macros/tags" %} {% block content %} <article> -<form action="/post2" method="post" id="postmsg" enctype="multipart/form-data"> +<form id="postmsg"> <p style="text-align: left"> <b>Фото:</b> <span id="attachmentfile"> <input style="width: 100%;" type="file" name="attach"/> <i>({{ i18n("messages","postForm.imageFormats") }})</i></span> diff --git a/juick-server/src/main/resources/templates/views/thread.html b/juick-server/src/main/resources/templates/views/thread.html index 1ec9c233..343a2591 100644 --- a/juick-server/src/main/resources/templates/views/thread.html +++ b/juick-server/src/main/resources/templates/views/thread.html @@ -87,7 +87,7 @@ {% endif %} </nav> {% if msg.VisitorCanComment %} - <form action="/comment" method="POST" enctype="multipart/form-data" class="msg-comment-target"> + <form class="msg-comment-target"> <input type="hidden" name="mid" value="{{ msg.mid }}"/> <div class="msg-comment"> <div class="ta-wrapper"> |