Spaces:
Running
Running
| validateAndLoadJson(data, sourceName) { | |
| if (!Array.isArray(data)) { | |
| throw new Error('Invalid JSON format: Expected array'); | |
| } | |
| const isValid = data.every(item => | |
| item.text !== undefined && | |
| typeof item.start_time === 'number' && | |
| typeof item.end_time === 'number' | |
| ); | |
| if (!isValid) { | |
| throw new Error('Each item must have: text (string), start_time (number), end_time (number)'); | |
| } | |
| this.jsonTimestamps = data; | |
| this.updateJsonUI(sourceName, data.length); | |
| } | |
| updateJsonUI(filename, wordCount) { | |
| const jsonStatus = document.getElementById('json-status'); | |
| const jsonFilename = document.getElementById('json-filename'); | |
| const jsonWordsCount = document.getElementById('json-words-count'); | |
| if (jsonStatus && jsonFilename && jsonWordsCount) { | |
| jsonStatus.classList.remove('hidden'); | |
| jsonFilename.textContent = filename; | |
| jsonWordsCount.textContent = `${wordCount} palavras`; | |
| // Visual feedback | |
| const zone = document.getElementById('json-upload-zone'); | |
| zone.classList.add('border-green-500', 'bg-green-100'); | |
| setTimeout(() => { | |
| zone.classList.remove('border-green-500', 'bg-green-100'); | |
| }, 1000); | |
| } | |
| } |