cleanup
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m3s
Publish Docker Image / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m13s

This commit is contained in:
Lee 2024-06-02 13:01:46 +01:00
parent f3360b6041
commit af219e69bb
3 changed files with 51 additions and 37 deletions

@ -4,10 +4,18 @@ import lombok.NonNull;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry; 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; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration @EnableWebMvc
public class Config { public class Config implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
}
@Bean @Bean
public WebMvcConfigurer configureCors() { public WebMvcConfigurer configureCors() {

@ -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> </body>
<!-- Paste Script --> <!-- Paste Script -->
<script> <script src="/static/assets/script.js"></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>
</html> </html>