update context image should be text
All checks were successful
Deploy to Production / deploy (push) Successful in 20s

This commit is contained in:
silverpro89
2026-02-10 17:43:17 +07:00
parent 5957636b07
commit 09e72e37e7
3 changed files with 10 additions and 14 deletions

View File

@@ -228,10 +228,10 @@ class ContextController {
const { id } = req.params; const { id } = req.params;
const { image } = req.body; 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({ return res.status(400).json({
success: false, success: false,
message: 'Image must be a non-empty array of URLs' message: 'Image must be a non-empty string (URL)'
}); });
} }

View File

@@ -45,7 +45,7 @@ const Context = sequelize.define('Context', {
}, },
image: { image: {
type: DataTypes.TEXT, type: DataTypes.TEXT,
comment: 'Array of image URLs' comment: 'Single image URL string'
}, },
type_context: { type_context: {
type: DataTypes.STRING(50), type: DataTypes.STRING(50),

View File

@@ -402,9 +402,9 @@
<input type="text" id="imagesUuid" placeholder="Paste UUID or click from list above"> <input type="text" id="imagesUuid" placeholder="Paste UUID or click from list above">
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Image URLs * (JSON Array)</label> <label>Image URL * (String)</label>
<textarea id="imageUrls" placeholder='["https://example.com/image1.jpg", "https://example.com/image2.jpg"]'></textarea> <input type="text" id="imageUrls" placeholder="https://example.com/image.jpg">
<div class="small-note">Must be valid JSON array of URLs</div> <div class="small-note">Enter a single image URL</div>
</div> </div>
<button onclick="addImages()">Add Images (Status 3 → 4)</button> <button onclick="addImages()">Add Images (Status 3 → 4)</button>
<div class="result" id="imagesResult"></div> <div class="result" id="imagesResult"></div>
@@ -647,22 +647,18 @@
const headers = getHeaders(); const headers = getHeaders();
const uuid = document.getElementById('imagesUuid').value.trim(); const uuid = document.getElementById('imagesUuid').value.trim();
const imageUrlsStr = document.getElementById('imageUrls').value.trim(); const imageUrl = document.getElementById('imageUrls').value.trim();
if (!uuid || !imageUrlsStr) { if (!uuid || !imageUrl) {
showResult('imagesResult', { error: 'UUID and image URLs are required' }, false); showResult('imagesResult', { error: 'UUID and image URL are required' }, false);
return; return;
} }
try { 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`, { const response = await fetch(`${API_BASE}/${uuid}/add-images`, {
method: 'POST', method: 'POST',
headers: headers, headers: headers,
body: JSON.stringify({ image }) body: JSON.stringify({ image: imageUrl })
}); });
const data = await response.json(); const data = await response.json();
showResult('imagesResult', data, response.ok); showResult('imagesResult', data, response.ok);