add hastebin compatibility
This commit is contained in:
parent
78af91e971
commit
c8e91ba949
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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}")
|
||||
|
@ -43,8 +43,7 @@ const toast = (message, duration = 3000) => {
|
||||
Toastify({
|
||||
text: message,
|
||||
duration: duration,
|
||||
close: true,
|
||||
gravity: "bottom",
|
||||
position: "right",
|
||||
position: "right"
|
||||
}).showToast();
|
||||
};
|
||||
|
Reference in New Issue
Block a user