patched adapter bug
Build and Release Core / Test and Build (push) Failing after 5m41s

This commit is contained in:
t
2026-05-07 13:24:30 -04:00
parent 7fecb4905e
commit bda39c40f6
5 changed files with 81 additions and 56 deletions
+45 -33
View File
@@ -1,50 +1,47 @@
const dropZone = document.getElementById('drop-zone');
const fileInput = document.getElementById('file-input');
async function uploadScan() {
const fileInput = document.getElementById('scanFile');
const adapterSelect = document.getElementById('adapterSelect');
const resultDiv = document.getElementById('ingestResult');
async function processFile(file) {
const statusText = document.getElementById('status-text');
document.getElementById('status-area').classList.remove('d-none');
const file = fileInput.files[0];
const adapterName = adapterSelect.value;
const adapterSelect = document.getElementById('adapter-select');
const adapterId = adapterSelect.value;
let adapterName = "";
if (adapterSelect.selectedIndex > 0) {
adapterName = adapterSelect.options[adapterSelect.selectedIndex].getAttribute('data-name');
if (!file) {
showResult("Please select a file to upload.", false);
return;
}
if (!adapterName) {
showResult("Please select an adapter.", false);
return;
}
// Show processing state
showResult("Processing...", true, true);
try {
let response;
// Route appropriately based on file extension
if (file.name.toLowerCase().endsWith('.json')) {
if (!adapterName) {
statusText.innerText = "Unknown JSON format. Redirecting to Adapter Builder...";
setTimeout(() => {
window.location.href = `/admin/adapters/new?filename=${encodeURIComponent(file.name)}`;
}, 1200);
return;
}
const rawText = await file.text();
response = await fetch(`/api/ingest/${encodeURIComponent(adapterName)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: rawText
});
}
else {
} else {
let formData = new FormData();
formData.append('file', file);
if (adapterId) {
formData.append('adapter_id', adapterId);
}
formData.append('adapter_name', adapterName); // Pass adapter name for CSVs
response = await fetch('/api/ingest/csv', { method: 'POST', body: formData });
}
if (!response.ok) {
// Auto-redirect to builder if the adapter doesn't match the file structure
if (response.status === 404) {
statusText.innerText = "Format not recognized. Redirecting to Adapter Builder...";
showResult("Format not recognized. Redirecting to Adapter Builder...", false);
setTimeout(() => {
window.location.href = `/admin/adapters/new?filename=${encodeURIComponent(file.name)}`;
}, 1200);
@@ -53,16 +50,31 @@ async function processFile(file) {
throw new Error(errText);
}
} else {
statusText.innerText = "Yeehaw! Tickets corralled successfully.";
setTimeout(() => window.location.href = "/dashboard", 800);
showResult("Yeehaw! Tickets corralled successfully.", true);
setTimeout(() => window.location.href = "/dashboard", 1000);
}
} catch (err) {
statusText.innerText = "Stampede! Error: " + err.message;
showResult("Stampede! Error: " + err.message, false);
}
}
dropZone.onclick = () => fileInput.click();
fileInput.onchange = (e) => processFile(e.target.files[0]);
dropZone.ondragover = (e) => { e.preventDefault(); dropZone.style.background = "#e1f5fe"; };
dropZone.ondragleave = () => dropZone.style.background = "#f8f9fa";
dropZone.ondrop = (e) => { e.preventDefault(); processFile(e.dataTransfer.files[0]); };
// Helper function to handle status messages nicely
function showResult(msg, isSuccess, isInfo = false) {
const div = document.getElementById('ingestResult');
div.style.display = 'block';
div.innerText = msg;
if (isInfo) {
div.style.backgroundColor = '#e0f2fe';
div.style.color = '#0369a1';
div.style.border = '1px solid #bae6fd';
} else if (isSuccess) {
div.style.backgroundColor = '#dcfce7';
div.style.color = '#166534';
div.style.border = '1px solid #bbf7d0';
} else {
div.style.backgroundColor = '#fee2e2';
div.style.color = '#991b1b';
div.style.border = '1px solid #fecaca';
}
}