cleanup
This commit is contained in:
parent
f3360b6041
commit
af219e69bb
@ -4,10 +4,18 @@ import lombok.NonNull;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class Config {
|
||||
@Configuration @EnableWebMvc
|
||||
public class Config implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry
|
||||
.addResourceHandler("/static/**")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer configureCors() {
|
||||
|
40
src/main/resources/static/assets/script.js
Normal file
40
src/main/resources/static/assets/script.js
Normal file
@ -0,0 +1,40 @@
|
||||
// Handle custom key binds behavior
|
||||
document.addEventListener("keydown", function (event) {
|
||||
// Upload the paste when Ctrl + Enter is pressed
|
||||
if (event.ctrlKey && event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
upload();
|
||||
}
|
||||
});
|
||||
|
||||
// Upload the paste when the paste button is clicked
|
||||
document.getElementById("paste-button").addEventListener("click", () => upload());
|
||||
|
||||
// Upload the paste to the server
|
||||
const upload = async () => {
|
||||
var pasteInput = document.getElementById("paste-input");
|
||||
var paste = pasteInput.value;
|
||||
|
||||
if (!paste || paste.trim() === "") {
|
||||
pasteInput.focus();
|
||||
alert("Your paste is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Uploading paste...");
|
||||
try {
|
||||
const response = await fetch("/api/upload", {
|
||||
method: "POST",
|
||||
body: paste,
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message);
|
||||
}
|
||||
|
||||
window.location.href = "/" + data.id;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
alert(`${error.message || "An error occurred while uploading the paste."}`);
|
||||
}
|
||||
};
|
@ -29,39 +29,5 @@
|
||||
</body>
|
||||
|
||||
<!-- Paste Script -->
|
||||
<script>
|
||||
// Handle custom key binds behavior
|
||||
document.addEventListener('keydown', function(event) {
|
||||
// Upload the paste when Ctrl + Enter is pressed
|
||||
if (event.ctrlKey && event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
upload();
|
||||
}
|
||||
});
|
||||
|
||||
// Upload the paste when the paste button is clicked
|
||||
document.getElementById('paste-button').addEventListener('click', () => upload());
|
||||
|
||||
// Upload the paste to the server
|
||||
const upload = () => {
|
||||
var pasteInput = document.getElementById('paste-input');
|
||||
var paste = pasteInput.value;
|
||||
|
||||
if (!paste || paste.trim() === ''){
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/api/upload', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
},
|
||||
body: paste
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).then(function(data) {
|
||||
window.location.href = '/' + data.id;
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<script src="/static/assets/script.js"></script>
|
||||
</html>
|
Reference in New Issue
Block a user