Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/flowlord/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (tm *taskMaster) StartHandler(serveErr chan<- error) error {
router.Get("/refresh", tm.refreshHandler)
router.Post("/backload", tm.Backloader)
router.Post("/rerun", tm.rerunHandler)
router.Post("/import", tm.importHandler)
router.Get("/workflow/*", tm.workflowFiles)
router.Get("/workflow", tm.workflowFiles)
router.Get("/notify", func(w http.ResponseWriter, r *http.Request) {
Expand Down
55 changes: 48 additions & 7 deletions apps/flowlord/handler/about.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,51 @@
</table>
</div>
</div>

<div class="cache-section">
<h3>Task Import</h3>
<p class="meta-hint">Backfill the SQLite cache from a JSONL source: upload a file from your machine (Browse) or enter an object path on <code>s3://</code>, <code>gs://</code>, <code>mc://</code>, or <code>mcs://</code> (globs allowed). Local server paths are not accepted. Each line must be a JSON task object (same format as bus/logger output). Tasks are inserted or updated in the cache only; nothing is re-queued to the message bus.</p>
<div class="info-card">
<div class="form-group">
<label for="importPath">JSONL source</label>
<div class="import-source-wrap">
<div class="import-source-field" id="importPathRow">
<input type="text" id="importPath" class="form-control" placeholder="e.g. gs://bucket/tasks/*.jsonl, s3://bucket/prefix/tasks.jsonl" spellcheck="false" autocomplete="off">
<button type="button" id="importBrowseBtn" class="btn btn-secondary" title="Choose a local JSONL file">Browse…</button>
<input type="file" id="importFile" class="import-file-hidden" accept=".jsonl,.json,.txt" tabindex="-1" aria-hidden="true">
</div>
<div class="import-attachment-row" id="importAttachmentRow" hidden>
<span class="import-attachment-chip">
<span class="import-attachment-kind">Local file</span>
<span class="filter-chip-text" id="importAttachmentName"></span>
<span class="import-attachment-size" id="importAttachmentSize"></span>
<button type="button" id="importAttachmentClear" class="filter-chip-clear" title="Remove file" aria-label="Remove selected file">×</button>
</span>
</div>
</div>
<p class="form-hint">Browse uploads from your computer. Remote paths use flowlord&apos;s file credentials (<code>s3://</code>, <code>gs://</code>, <code>mc://</code>, <code>mcs://</code>; no <code>.</code> / <code>..</code> path segments).</p>
</div>
<div class="action-buttons">
<button type="button" id="importBtn" class="btn btn-primary" disabled>
Import Tasks
</button>
</div>
<div id="importStatus" class="preview-status" style="display: none;"></div>
<div id="importErrors" class="import-errors" style="display: none;">
<h4>Parse Errors</h4>
<ul id="importErrorsList"></ul>
</div>
</div>
</div>
</div>
</div>


<script src="{{if .isLocal}}./static{{else}}/static{{end}}/about.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
window.FlowlordAbout.init('/import');
});

// Format numbers with commas for readability
document.querySelectorAll('.row-count').forEach(function(cell) {
const num = parseInt(cell.textContent, 10);
Expand All @@ -140,31 +181,31 @@
(function() {
const startTimeStr = document.getElementById('startTime').value;
if (!startTimeStr) return;

const startTime = new Date(startTimeStr);
const uptimeEl = document.getElementById('uptime');

function formatDuration(ms) {
const seconds = Math.floor(ms / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);

const parts = [];
if (days > 0) parts.push(days + 'd');
if (hours % 24 > 0) parts.push((hours % 24) + 'h');
if (minutes % 60 > 0) parts.push((minutes % 60) + 'm');
if (seconds % 60 > 0 || parts.length === 0) parts.push((seconds % 60) + 's');

return parts.join(' ');
}

function updateUptime() {
const now = new Date();
const diff = now - startTime;
uptimeEl.textContent = formatDuration(diff);
}

updateUptime();
setInterval(updateUptime, 1000);
})();
Expand Down
261 changes: 261 additions & 0 deletions apps/flowlord/handler/static/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
// About page task import
(function() {
'use strict';

const elements = {};
let pendingUpload = null;

function formatFileSize(bytes) {
if (bytes < 1024) {
return bytes + ' B';
}
if (bytes < 1024 * 1024) {
return (bytes / 1024).toFixed(1) + ' KB';
}
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
}

function hasServerPath() {
return elements.pathInput && elements.pathInput.value.trim().length > 0;
}

function remotePathError(path) {
if (!/^(s3|gs|gcs|mc|mcs|minio):\/\//i.test(path)) {
return 'Remote import paths must start with s3://, gs://, gcs://, mc://, or mcs://.';
}
if (path.indexOf('\\') >= 0) {
return 'Remote paths cannot contain backslashes.';
}
const objectPart = path.replace(/^[^:]+:\/\/[^/]+\//, '');
const segments = objectPart.split('/');
for (let i = 0; i < segments.length; i++) {
if (segments[i] === '.' || segments[i] === '..') {
return 'Remote paths cannot include . or .. path segments.';
}
}
return '';
}

function hasUpload() {
return pendingUpload !== null;
}

function updateImportEnabled() {
elements.importBtn.disabled = !(hasUpload() || hasServerPath());
}

function syncControls() {
if (!elements.pathInput) {
return;
}
elements.pathInput.disabled = hasUpload();
if (elements.browseBtn) {
elements.browseBtn.disabled = false;
}
updateImportEnabled();
}

function hideAttachment() {
if (elements.attachmentRow) {
elements.attachmentRow.hidden = true;
}
}

function showAttachment(file) {
if (!file || !elements.attachmentRow) {
hideAttachment();
return;
}
if (elements.attachmentName) {
elements.attachmentName.textContent = file.name;
}
if (elements.attachmentSize) {
elements.attachmentSize.textContent = formatFileSize(file.size);
}
elements.attachmentRow.hidden = false;
}

function resetImportSource() {
pendingUpload = null;
if (elements.fileInput) {
elements.fileInput.value = '';
}
if (elements.pathInput) {
elements.pathInput.value = '';
}
hideAttachment();
syncControls();
}

function clearPendingUpload() {
pendingUpload = null;
if (elements.fileInput) {
elements.fileInput.value = '';
}
hideAttachment();
syncControls();
}

function init(apiEndpoint) {
elements.pathInput = document.getElementById('importPath');
elements.pathRow = document.getElementById('importPathRow');
elements.fileInput = document.getElementById('importFile');
elements.browseBtn = document.getElementById('importBrowseBtn');
elements.attachmentRow = document.getElementById('importAttachmentRow');
elements.attachmentName = document.getElementById('importAttachmentName');
elements.attachmentSize = document.getElementById('importAttachmentSize');
elements.attachmentClear = document.getElementById('importAttachmentClear');
elements.importBtn = document.getElementById('importBtn');
elements.status = document.getElementById('importStatus');
elements.errorsSection = document.getElementById('importErrors');
elements.errorsList = document.getElementById('importErrorsList');

if (!elements.importBtn || !elements.pathInput) {
return;
}

hideAttachment();
syncControls();

elements.pathInput.addEventListener('input', function() {
if (hasUpload()) {
return;
}
syncControls();
hideResults();
});

if (elements.browseBtn && elements.fileInput) {
elements.browseBtn.addEventListener('click', function() {
elements.fileInput.click();
});

elements.fileInput.addEventListener('change', function() {
const file = elements.fileInput.files[0];
if (!file) {
return;
}
pendingUpload = file;
elements.pathInput.value = '';
showAttachment(file);
syncControls();
hideResults();
});
}

if (elements.attachmentClear) {
elements.attachmentClear.addEventListener('click', function() {
clearPendingUpload();
hideResults();
});
}

elements.importBtn.addEventListener('click', function() {
uploadFile(apiEndpoint);
});
}

function hideResults() {
elements.status.style.display = 'none';
elements.errorsSection.style.display = 'none';
elements.errorsList.innerHTML = '';
}

function showStatus(message, className) {
elements.status.textContent = message;
elements.status.className = 'preview-status ' + (className || 'info');
elements.status.style.display = 'block';
}

function showErrors(errors) {
if (!errors || errors.length === 0) {
elements.errorsSection.style.display = 'none';
return;
}
elements.errorsList.innerHTML = '';
errors.forEach(function(err) {
const li = document.createElement('li');
li.textContent = err;
elements.errorsList.appendChild(li);
});
elements.errorsSection.style.display = 'block';
}

function uploadFile(apiEndpoint) {
if (!hasUpload() && !hasServerPath()) {
return;
}

const wasUpload = hasUpload();

const formData = new FormData();
if (wasUpload) {
formData.append('file', pendingUpload);
} else {
const remotePath = elements.pathInput.value.trim();
const pathErr = remotePathError(remotePath);
if (pathErr) {
showStatus(pathErr, 'error');
return;
}
formData.append('path', remotePath);
}

elements.importBtn.disabled = true;
showStatus('Importing…', 'info');

fetch(apiEndpoint, {
method: 'POST',
body: formData
})
.then(function(response) {
if (!response.ok) {
return response.text().then(function(text) {
throw new Error(text || ('HTTP ' + response.status));
});
}
return response.json();
})
.then(function(result) {
const summary = result.imported + ' imported, ' +
result.skipped + ' skipped, ' +
result.lines + ' lines parsed';
let className = 'info';
if (result.status === 'partial') {
className = 'execution-success';
} else if (result.status === 'failed' || result.status.indexOf('sync failed') === 0) {
className = 'error';
} else if (result.imported > 0) {
className = 'execution-success';
}
let message = summary;
if (result.status && result.status !== 'ok') {
message += ' (' + result.status + ')';
}
if (result.imported > 0) {
message += '. Refresh the page to update table statistics.';
}
showStatus(message, className);
showErrors(result.errors);

if (wasUpload && result.status !== 'failed') {
resetImportSource();
} else if (!wasUpload && result.status !== 'failed') {
if (elements.pathInput) {
elements.pathInput.value = '';
}
syncControls();
}
})
.catch(function(err) {
showStatus('Import failed: ' + err.message, 'error');
})
.finally(function() {
syncControls();
});
}

window.FlowlordAbout = {
init: init
};
})();
Loading
Loading