From 9e0f3b80b25f20abd2b3f902a3e1677aa5d19fc2 Mon Sep 17 00:00:00 2001 From: phamhungd Date: Tue, 30 Dec 2025 16:20:57 +0700 Subject: [PATCH] update --- .DS_Store | Bin 10244 -> 10244 bytes app.py | 136 +++++++++++++++++++++++++++++++ gallery_favorites.json | 6 +- requirements.txt | 2 + static/modules/referenceSlots.js | 18 ++++ static/script.js | 49 +++++++++++ templates/index.html | 4 + 7 files changed, 213 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index 13272b1f0acef07d6f32ff83bb14b0af63a1b4fa..b0f911e4e5c3b95eed951d046d6044a85048397f 100644 GIT binary patch delta 264 zcmZn(XbITRAi%)@1dDQyJ5Cm0(GkhbPjN}g$xi}`p-620BJh-jMOE;h*yOvSax4tz zN-8G*7gbONF^)R|RkJY^Gn6nS0&yloazTb+aB_Zb0mx`o$qAEP#GW%Zl%AigC$7#0 zq;r6lJron0Tqu5r`Kt@hJ_%{2qYax^OSG`C0A(vDC(6nR apt-MdbE51QMkF&g7s~HrC0;qu36lXj(oqHg delta 264 zcmZn(XbITRAi!}&LM^W=_qgL^0TvyR-24=mq@4UD1_lNciOpXGp0cng9zOPH@?B9m zmWFE+awq>6RZwjRngG-aRL#av%uvFR2*jBT$psmP!O8i#1we5I#Zw0+yNEq!W|)6w zvYxm)8$ !record.data); + + if (emptyIndex === -1) { + if (imageSlotState.length < MAX_IMAGE_SLOTS) { + addImageSlot(); + emptyIndex = imageSlotState.length - 1; + } else { + return false; + } + } + + await handleSlotDropFromHistory(emptyIndex, url); + return true; + } + return { initialize, getReferenceFiles, getReferencePaths, serializeReferenceImages, setReferenceImages, + addReferenceFromUrl, }; } diff --git a/static/script.js b/static/script.js index 2c08899..6cc8494 100644 --- a/static/script.js +++ b/static/script.js @@ -102,6 +102,7 @@ document.addEventListener('DOMContentLoaded', () => { const downloadLink = document.getElementById('download-link'); const galleryGrid = document.getElementById('gallery-grid'); const imageInputGrid = document.getElementById('image-input-grid'); + const referenceUrlInput = document.getElementById('reference-url-input'); const imageDisplayArea = document.querySelector('.image-display-area'); const canvasToolbar = document.querySelector('.canvas-toolbar'); const sidebar = document.querySelector('.sidebar'); @@ -2121,4 +2122,52 @@ document.addEventListener('DOMContentLoaded', () => { }; } + // Reference URL Input Logic + if (referenceUrlInput && typeof slotManager !== 'undefined') { + referenceUrlInput.addEventListener('keydown', async (event) => { + if (event.key === 'Enter') { + event.preventDefault(); + const url = referenceUrlInput.value.trim(); + if (!url) return; + + referenceUrlInput.disabled = true; + const originalPlaceholder = referenceUrlInput.getAttribute('placeholder'); + referenceUrlInput.setAttribute('placeholder', 'Đang tải...'); + + try { + const response = await fetch('/download_image', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ url }) + }); + + const data = await response.json(); + + if (!response.ok) { + throw new Error(data.error || 'Failed to download image'); + } + + if (data.path) { + const success = await slotManager.addReferenceFromUrl(data.path); + if (success) { + referenceUrlInput.value = ''; + } else { + alert('Không còn slot trống cho ảnh tham chiếu.'); + } + } else { + throw new Error('No image path returned'); + } + + } catch (error) { + console.error('Download error:', error); + alert(`Lỗi tải ảnh: ${error.message}`); + } finally { + referenceUrlInput.disabled = false; + referenceUrlInput.setAttribute('placeholder', originalPlaceholder); + referenceUrlInput.focus(); + } + } + }); + } + }); diff --git a/templates/index.html b/templates/index.html index c53c863..f35facf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -172,6 +172,10 @@
+
+ +