Rewrote js in jquery and started working on showing images and potentialy addin metadata to images (Spicy lvl, etc)

This commit is contained in:
2025-08-27 08:07:11 +02:00
parent 1e58cc3d3a
commit c05f7fea76
7 changed files with 120 additions and 83 deletions
+47
View File
@@ -0,0 +1,47 @@
let imageInput = $("#imageInput")
let imagePreview = $("#preview")
let uploadForm = $("#imageForm")
let currentFile = null;
imageInput.on("change", function() {
currentFile = this.files[0];
if (currentFile) {
const reader = new FileReader();
reader.onload = function(e) {
preview.src = e.target.result;
preview.style.display = 'block';
}
reader.readAsDataURL(currentFile);
} else {
preview.style.display = 'none';
}
})
uploadForm.on("submit", function(e) {
e.preventDefault();
if (!currentFile) {
alert("Please select a file first.");
return;
}
let formData = new FormData();
formData.append("image", currentFile);
$.ajax({
url: "/upload",
type: "POST",
data: formData,
success: function(response) {
alert("Image uploaded successfully!");
imageInput.val("");
preview.style.display = 'none';
currentFile = null;
},
error: function(xhr, status, error) {
alert("Error uploading image: " + xhr.responseText);
}
});
})