diff --git a/controllers/contextController.js b/controllers/contextController.js index a145e4b..47ae2fc 100644 --- a/controllers/contextController.js +++ b/controllers/contextController.js @@ -228,10 +228,10 @@ class ContextController { const { id } = req.params; const { image } = req.body; - if (!image || !Array.isArray(image) || image.length === 0) { + if (!image || typeof image !== 'string' || image.trim().length === 0) { return res.status(400).json({ success: false, - message: 'Image must be a non-empty array of URLs' + message: 'Image must be a non-empty string (URL)' }); } diff --git a/models/Context.js b/models/Context.js index 48d3b12..c45851d 100644 --- a/models/Context.js +++ b/models/Context.js @@ -45,7 +45,7 @@ const Context = sequelize.define('Context', { }, image: { type: DataTypes.TEXT, - comment: 'Array of image URLs' + comment: 'Single image URL string' }, type_context: { type: DataTypes.STRING(50), diff --git a/public/contexts.html b/public/contexts.html index acc8f95..da2a631 100644 --- a/public/contexts.html +++ b/public/contexts.html @@ -402,9 +402,9 @@
- - -
Must be valid JSON array of URLs
+ + +
Enter a single image URL
@@ -647,22 +647,18 @@ const headers = getHeaders(); const uuid = document.getElementById('imagesUuid').value.trim(); - const imageUrlsStr = document.getElementById('imageUrls').value.trim(); + const imageUrl = document.getElementById('imageUrls').value.trim(); - if (!uuid || !imageUrlsStr) { - showResult('imagesResult', { error: 'UUID and image URLs are required' }, false); + if (!uuid || !imageUrl) { + showResult('imagesResult', { error: 'UUID and image URL are required' }, false); return; } try { - const image = JSON.parse(imageUrlsStr); - if (!Array.isArray(image)) { - throw new Error('Image URLs must be an array'); - } const response = await fetch(`${API_BASE}/${uuid}/add-images`, { method: 'POST', headers: headers, - body: JSON.stringify({ image }) + body: JSON.stringify({ image: imageUrl }) }); const data = await response.json(); showResult('imagesResult', data, response.ok);