From c8e91ba949e654c1a515c7f299f7d6f80deb7e6d Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 4 Jun 2024 19:16:10 +0100 Subject: [PATCH] add hastebin compatibility --- .../backend/controller/IndexController.java | 20 +++++++++++++------ .../backend/controller/PasteController.java | 2 +- src/main/resources/static/assets/script.js | 3 +-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/cc/fascinated/backend/controller/IndexController.java b/src/main/java/cc/fascinated/backend/controller/IndexController.java index 3beb445..b97abd2 100644 --- a/src/main/java/cc/fascinated/backend/controller/IndexController.java +++ b/src/main/java/cc/fascinated/backend/controller/IndexController.java @@ -4,11 +4,13 @@ import cc.fascinated.backend.exception.impl.ResourceNotFoundException; import cc.fascinated.backend.model.Paste; import cc.fascinated.backend.service.PasteService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; /** * @author Fascinated (fascinated7) @@ -33,9 +35,6 @@ public class IndexController { public String paste(@PathVariable String id, Model model) { try { Paste paste = pasteService.getPaste(id); - if (paste == null) { // If the paste does not exist, redirect to the home page - return "redirect:/"; - } model.addAttribute("paste", paste); model.addAttribute("title", "Paste - " + paste.getId()); model.addAttribute("rawUrl", "/raw/" + paste.getId()); @@ -56,4 +55,13 @@ public class IndexController { return "redirect:/"; } } + + /** + * This is to allow for Hastebin compatibility. + */ + @PostMapping(value = "/documents") + public ResponseEntity uploadPaste(@RequestBody String content, @RequestHeader(HttpHeaders.CONTENT_TYPE) String contentType) { + String id = pasteService.createPaste(content, contentType); + return ResponseEntity.ok(Map.of("key", id)); + } } diff --git a/src/main/java/cc/fascinated/backend/controller/PasteController.java b/src/main/java/cc/fascinated/backend/controller/PasteController.java index 1fedb9e..bc56b63 100644 --- a/src/main/java/cc/fascinated/backend/controller/PasteController.java +++ b/src/main/java/cc/fascinated/backend/controller/PasteController.java @@ -23,7 +23,7 @@ public class PasteController { @PostMapping(value = "/upload") public ResponseEntity uploadPaste(@RequestBody String content, @RequestHeader(HttpHeaders.CONTENT_TYPE) String contentType) { String id = pasteService.createPaste(content, contentType); - return ResponseEntity.ok(Map.of("id", id)); + return ResponseEntity.ok(Map.of("key", id)); } @GetMapping(value = "/paste/{id}") diff --git a/src/main/resources/static/assets/script.js b/src/main/resources/static/assets/script.js index 6ec7976..82bbe33 100644 --- a/src/main/resources/static/assets/script.js +++ b/src/main/resources/static/assets/script.js @@ -43,8 +43,7 @@ const toast = (message, duration = 3000) => { Toastify({ text: message, duration: duration, - close: true, gravity: "bottom", - position: "right", + position: "right" }).showToast(); };