add hastebin compatibility
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m45s
Publish Docker Image / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m14s

This commit is contained in:
Lee 2024-06-04 19:16:10 +01:00
parent 78af91e971
commit c8e91ba949
3 changed files with 16 additions and 9 deletions

View File

@ -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));
}
}

View File

@ -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}")

View File

@ -43,8 +43,7 @@ const toast = (message, duration = 3000) => {
Toastify({
text: message,
duration: duration,
close: true,
gravity: "bottom",
position: "right",
position: "right"
}).showToast();
};