diff --git a/api/extract.php b/api/extract.php index c3e8c38..b3cd7e7 100644 --- a/api/extract.php +++ b/api/extract.php @@ -7,7 +7,7 @@ dbnToolsRequireMethod('POST'); dbnToolsRequireAuth(); const EXTRACT_MAX_BYTES = 4 * 1024 * 1024; -const EXTRACT_TEXT_LIMIT = 32000; +const EXTRACT_TEXT_LIMIT = 128000; const EXTRACT_ALLOWED_EXTS = ['txt', 'pdf', 'docx']; try { diff --git a/api/redact.php b/api/redact.php index 7467ca1..223dbb8 100644 --- a/api/redact.php +++ b/api/redact.php @@ -5,12 +5,28 @@ require_once __DIR__ . '/../includes/LegalTools.php'; dbnToolsRequireMethod('POST'); dbnToolsRequireAuth(); -$input = dbnToolsJsonInput(70000); +$input = dbnToolsJsonInput(400000); dbnToolsWithTelemetry('redact', '', function () use ($input): array { - $text = dbnToolsString($input, 'text', 32000); + $text = dbnToolsString($input, 'text', 128000); $mode = (string)($input['mode'] ?? 'standard'); $region = dbnToolsNormalizeRegion($input['region'] ?? 'nordic'); $language = dbnToolsNormalizeLanguage($input['language'] ?? 'en'); - return (new DbnLegalToolsService())->redact($text, $mode, $region, $language); + + $aliases = []; + $rawAliases = $input['aliases'] ?? []; + if (is_array($rawAliases)) { + foreach (array_slice($rawAliases, 0, 20) as $item) { + if (!is_array($item)) { + continue; + } + $original = substr(trim((string)($item['original'] ?? '')), 0, 100); + $alias = substr(trim((string)($item['alias'] ?? '')), 0, 100); + if ($original !== '' && $alias !== '') { + $aliases[] = ['original' => $original, 'alias' => $alias]; + } + } + } + + return (new DbnLegalToolsService())->redact($text, $mode, $region, $language, $aliases); }); diff --git a/assets/css/tools.css b/assets/css/tools.css index 24c5223..fd71490 100644 --- a/assets/css/tools.css +++ b/assets/css/tools.css @@ -963,3 +963,113 @@ p { color: var(--coral); border-color: #f5c6aa; } + +/* ─── Multi-file list ─────────────────────────────────────────────────────── */ + +.upload-file-list { + list-style: none; + padding: 0; + margin: 0; + text-align: left; + width: 100%; +} + +.upload-file-list li { + display: flex; + align-items: baseline; + gap: 0.5rem; + padding: 2px 0; + font-size: 0.85rem; +} + +.upload-chars { + color: var(--muted); + font-size: 0.78rem; + flex-shrink: 0; +} + +/* ─── Name aliases (Redact tool) ──────────────────────────────────────────── */ + +.alias-section { + margin-top: 0.75rem; + padding-top: 0.75rem; + border-top: 1px solid var(--line); +} + +.alias-header { + display: flex; + align-items: center; + gap: 1rem; + margin-bottom: 0.5rem; +} + +.alias-add-btn { + background: var(--soft-teal); + color: var(--teal-dark); + border: 1px solid transparent; + border-radius: 6px; + padding: 3px 10px; + font-size: 0.8rem; + font-weight: 600; + cursor: pointer; + transition: background 0.12s; +} + +.alias-add-btn:hover { + background: #c4ece5; +} + +.alias-row { + display: flex; + align-items: center; + gap: 0.5rem; + margin-bottom: 0.4rem; +} + +.alias-original, +.alias-label { + flex: 1; + padding: 0.3rem 0.55rem; + border: 1px solid var(--line); + border-radius: 6px; + font-size: 0.875rem; + background: var(--panel); + color: var(--ink); + min-width: 0; +} + +.alias-original:focus, +.alias-label:focus { + outline: 3px solid rgba(15, 118, 110, 0.28); + outline-offset: 1px; + border-color: var(--teal); +} + +.alias-arrow { + color: var(--muted); + font-size: 1rem; + flex-shrink: 0; +} + +.alias-remove { + flex-shrink: 0; + background: transparent; + color: var(--muted); + font-size: 1.1rem; + line-height: 1; + padding: 2px 6px; + border-radius: 4px; + border: 1px solid transparent; +} + +.alias-remove:hover { + background: var(--soft-coral); + color: var(--coral); + border-color: #f5c6aa; +} + +.alias-hint { + font-size: 0.76rem; + color: var(--muted); + margin: 0.35rem 0 0; +} diff --git a/assets/js/tools.js b/assets/js/tools.js index 2be7308..6e863dc 100644 --- a/assets/js/tools.js +++ b/assets/js/tools.js @@ -84,8 +84,11 @@ document.addEventListener('DOMContentLoaded', () => { uploadInput: document.querySelector('#uploadInput'), uploadPrompt: document.querySelector('#uploadPrompt'), uploadFileInfo: document.querySelector('#uploadFileInfo'), - uploadFileName: document.querySelector('#uploadFileName'), + uploadFileList: document.querySelector('#uploadFileList'), uploadClear: document.querySelector('#uploadClear'), + aliasSection: document.querySelector('#aliasSection'), + addAliasRow: document.querySelector('#addAliasRow'), + aliasRows: document.querySelector('#aliasRows'), }); els.tabs.forEach((button) => { @@ -95,6 +98,7 @@ document.addEventListener('DOMContentLoaded', () => { els.passcodeForm.addEventListener('submit', submitPasscode); els.healthButton.addEventListener('click', checkHealth); setupUpload(); + setupAliases(); setTool(state.activeTool); if (state.authenticated) { @@ -122,7 +126,9 @@ function setTool(toolName) { els.languageControl.classList.toggle('is-hidden', !tool.usesLanguage); els.redactionControl.classList.toggle('is-hidden', toolName !== 'redact'); els.uploadZone.classList.toggle('is-hidden', toolName !== 'redact'); + els.aliasSection.classList.toggle('is-hidden', toolName !== 'redact'); resetUpload(); + resetAliases(); els.status.textContent = ''; renderTrace([]); } @@ -170,6 +176,7 @@ async function runTool(event) { if (state.activeTool === 'redact') { payload.mode = currentRedactionMode(); payload.region = currentRedactionRegion(); + payload.aliases = getAliases(); } setBusy(true); @@ -200,7 +207,7 @@ function resetUpload() { els.uploadInput.value = ''; els.uploadPrompt.classList.remove('is-hidden'); els.uploadFileInfo.classList.add('is-hidden'); - els.uploadFileName.textContent = ''; + els.uploadFileList.innerHTML = ''; els.uploadZone.classList.remove('is-drag-over'); } @@ -219,8 +226,7 @@ function setupUpload() { els.uploadZone.addEventListener('drop', (e) => { e.preventDefault(); els.uploadZone.classList.remove('is-drag-over'); - const file = e.dataTransfer?.files?.[0]; - if (file) handleFileUpload(file); + if (e.dataTransfer?.files?.length) handleFiles(e.dataTransfer.files); }); els.uploadZone.addEventListener('click', (e) => { @@ -230,49 +236,74 @@ function setupUpload() { }); els.uploadInput.addEventListener('change', () => { - const file = els.uploadInput.files?.[0]; - if (file) handleFileUpload(file); + if (els.uploadInput.files?.length) handleFiles(els.uploadInput.files); }); els.uploadClear.addEventListener('click', () => { resetUpload(); + els.input.value = ''; els.status.textContent = ''; }); } -async function handleFileUpload(file) { +async function handleFiles(fileList) { const allowed = ['pdf', 'docx', 'txt']; - const ext = file.name.split('.').pop().toLowerCase(); - if (!allowed.includes(ext)) { - els.status.textContent = 'Unsupported file type. Use .pdf, .docx, or .txt.'; - return; + const files = Array.from(fileList).slice(0, 5); + + for (const file of files) { + const ext = file.name.split('.').pop().toLowerCase(); + if (!allowed.includes(ext)) { + els.status.textContent = `Skipped ${file.name}: unsupported type. Use .pdf, .docx, or .txt.`; + return; + } } - els.status.textContent = `Extracting ${file.name}…`; + els.status.textContent = files.length === 1 ? `Extracting ${files[0].name}…` : `Extracting ${files.length} files…`; setBusy(true); + const parts = []; + let totalChars = 0; + let anyTruncated = false; + try { - const formData = new FormData(); - formData.append('file', file); + for (const file of files) { + const formData = new FormData(); + formData.append('file', file); - const resp = await fetch('api/extract.php', { - method: 'POST', - credentials: 'same-origin', - body: formData, - }); - const data = await resp.json().catch(() => ({})); + const resp = await fetch('api/extract.php', { + method: 'POST', + credentials: 'same-origin', + body: formData, + }); + const data = await resp.json().catch(() => ({})); - if (!resp.ok || !data.ok) { - throw new Error(data.error?.message || `Extraction failed (HTTP ${resp.status}).`); + if (!resp.ok || !data.ok) { + throw new Error(data.error?.message || `Extraction failed for ${file.name} (HTTP ${resp.status}).`); + } + + parts.push({ filename: file.name, chars: data.chars, truncated: data.truncated, text: data.text }); + totalChars += data.chars; + if (data.truncated) anyTruncated = true; } - els.input.value = data.text; - els.uploadFileName.textContent = file.name; + const combined = parts.length === 1 + ? parts[0].text + : parts.map((p) => `--- Document: ${p.filename} ---\n\n${p.text}`).join('\n\n'); + + const MAX_COMBINED = 128000; + const combinedTruncated = combined.length > MAX_COMBINED; + els.input.value = combinedTruncated ? combined.slice(0, MAX_COMBINED) : combined; + + els.uploadFileList.innerHTML = parts + .map((p) => `
Drop a .pdf, .docx, or .txt, or
-Text is extracted and never stored.
+Drop up to 5 files (.pdf, .docx, .txt), or
+Text is extracted in memory and never stored.
Replace a name with a bracketed alias, e.g. “David Jr” → [Junior]
+