From 463a42d80f4e00cf5cc595a604f0f965993682bf Mon Sep 17 00:00:00 2001 From: olikol <78661364+olikols07@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:01:45 +0200 Subject: [PATCH] Added simple spice meter (No server integration) --- api/FileHandlers.go | 8 +++--- static/css/admin.css | 11 ++++++++- static/js/image_upload.js | 8 +++--- static/js/images.js | 48 +++++++++++++++++++++++++++++++++--- website/templates/admin.html | 10 ++++---- 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/api/FileHandlers.go b/api/FileHandlers.go index 5bbd46c..0bb414f 100644 --- a/api/FileHandlers.go +++ b/api/FileHandlers.go @@ -31,25 +31,25 @@ func FileHandler(w http.ResponseWriter, r *http.Request) { files, _ := os.ReadDir(filepath.Join(staticDir, "images")) for _, file := range files { fileName := file.Name() - data.ImageNames = append(data.ImageNames, filepath.Join(staticDir, "images", fileName)) + data.ImageNames = append(data.ImageNames, filepath.Join("/", staticDir, "images", fileName)) } files, _ = os.ReadDir(filepath.Join("uploads")) for _, file := range files { fileName := file.Name() - data.ImageNames = append(data.ImageNames, filepath.Join("uploads", fileName)) + data.ImageNames = append(data.ImageNames, filepath.Join("/uploads", fileName)) } files, _ = os.ReadDir(filepath.Join(staticDir, "spicy")) for _, file := range files { fileName := file.Name() - data.SpicyImageNames = append(data.SpicyImageNames, filepath.Join(staticDir, "spicy", fileName)) + data.ImageNames = append(data.ImageNames, filepath.Join("/", staticDir, "spicy", fileName)) } files, _ = os.ReadDir(filepath.Join(staticDir, "ascii_art")) for _, file := range files { fileName := file.Name() data.AsciiFiles = append(data.AsciiFiles, - AsciiEntry{Name: filepath.Join(staticDir, "ascii_art", fileName), FontSize: 12}, + AsciiEntry{Name: filepath.Join("/", staticDir, "ascii_art", fileName), FontSize: 12}, ) } diff --git a/static/css/admin.css b/static/css/admin.css index 3cc2bc7..d087594 100644 --- a/static/css/admin.css +++ b/static/css/admin.css @@ -79,4 +79,13 @@ button:hover { } .tab-button.active { background: #007bff; -} \ No newline at end of file +} +.gallery-image { + max-width: 90px; + max-height: 70px; + margin: 10px; + border: 2px solid #444; + border-radius: 4px; + cursor: pointer; + transition: border-color 0.3s; +} diff --git a/static/js/image_upload.js b/static/js/image_upload.js index 502c517..0171377 100644 --- a/static/js/image_upload.js +++ b/static/js/image_upload.js @@ -26,17 +26,19 @@ uploadForm.on("submit", function(e) { alert("Please select a file first."); return; } - - let formData = new FormData(); + console.log(currentFile); + + let formData = new FormData(this); formData.append("image", currentFile); $.ajax({ url: "/upload", type: "POST", data: formData, + processData: false, + contentType: false, success: function(response) { alert("Image uploaded successfully!"); - imageInput.val(""); preview.style.display = 'none'; currentFile = null; }, diff --git a/static/js/images.js b/static/js/images.js index 0c8c450..ebf7fbd 100644 --- a/static/js/images.js +++ b/static/js/images.js @@ -1,7 +1,12 @@ +let galleryTable = $("#imagesGallery") +let refreshButton = $("#refresh-gallery") + let filesList = [] -$( document ).ready(function() { - $.ajax({ +let fileMetaData = [] + +async function fetchImages() { + await $.ajax({ url: '/files', type: 'GET', success: function(response) { @@ -11,6 +16,43 @@ $( document ).ready(function() { error: function() { alert('Error fetching images.'); } - }); + + filesList.ImageNames.forEach((filePath, i) => { + let newRow = $(` + + `+ i +` + + + + + 0 + + + + `); + galleryTable.append(newRow); + + fileMetaData.push({ + "id": i, + "spice_level": 0, + "path": filePath + }); + }); + fileMetaData.forEach(file => { + $("#spice-slider-" + file.id).on("input", function() { + file.spice_level = this.value; + $("#spice-output-" + file.id).text(this.value); + console.log(fileMetaData); + }) + }); +} + +refreshButton.on("click", function() { + galleryTable.empty(); + fetchImages(); +}); + +$( document ).ready(function() { + fetchImages(); }); \ No newline at end of file diff --git a/website/templates/admin.html b/website/templates/admin.html index ffabc7d..184ac4c 100644 --- a/website/templates/admin.html +++ b/website/templates/admin.html @@ -13,8 +13,8 @@ -
-
+
+

Add New Image

@@ -26,15 +26,15 @@

- Images + Images

- +
- +
ID ImageActionsSpice lvl