document validation takes json certificates

This commit is contained in:
NicolasCantu 2025-06-05 15:38:06 +02:00
parent b828e5197a
commit 6167d59501

View File

@ -10,7 +10,7 @@ export function getDocumentValidation(container: HTMLElement) {
const state = { const state = {
documentFile: null as File | null, documentFile: null as File | null,
certificateFile: null as File | null certificateJson: null as Record<string, any> | null
}; };
const wrapper = document.createElement('div'); const wrapper = document.createElement('div');
@ -38,19 +38,34 @@ export function getDocumentValidation(container: HTMLElement) {
cursor: pointer; cursor: pointer;
background: #fafafa; background: #fafafa;
`; `;
box.textContent = `Drop ${label} PDF here`; box.textContent = `Drop ${label} here`;
box.ondragover = e => { e.preventDefault(); box.style.background = '#eee'; }; box.ondragover = e => { e.preventDefault(); box.style.background = '#eee'; };
box.ondragleave = () => { box.style.background = '#fafafa'; }; box.ondragleave = () => { box.style.background = '#fafafa'; };
box.ondrop = e => { box.ondrop = async e => {
e.preventDefault(); e.preventDefault();
const file = e.dataTransfer?.files?.[0]; const file = e.dataTransfer?.files?.[0];
if (file && file.type === 'application/pdf') { if (!file) return;
onDrop(file); if (label === 'Document') {
box.textContent = `${label} uploaded: ${file.name}`; if (file.type === 'application/pdf') {
box.style.borderColor = 'green'; onDrop(file);
box.style.background = '#e6ffed'; box.textContent = `${label} uploaded: ${file.name}`;
} else { box.style.borderColor = 'green';
alert('Please drop a valid PDF file.'); box.style.background = '#e6ffed';
} else {
alert('Please drop a valid PDF file.');
}
} else if (label === 'Certificate') {
try {
const text = await file.text();
const json = JSON.parse(text);
onDrop(file);
state.certificateJson = json;
box.textContent = `Certificate loaded: ${file.name}`;
box.style.borderColor = 'green';
box.style.background = '#e6ffed';
} catch (err) {
alert('Invalid certificate file. Must be valid JSON.');
}
} }
}; };
return box; return box;
@ -62,7 +77,6 @@ export function getDocumentValidation(container: HTMLElement) {
}); });
const certBox = createDropBox('Certificate', file => { const certBox = createDropBox('Certificate', file => {
state.certificateFile = file;
checkSuccess(); checkSuccess();
}); });
@ -73,7 +87,7 @@ export function getDocumentValidation(container: HTMLElement) {
container.appendChild(wrapper); container.appendChild(wrapper);
function checkSuccess() { function checkSuccess() {
if (state.documentFile && state.certificateFile) { if (state.documentFile && state.certificateJson) {
showSuccessScreen(); showSuccessScreen();
} }
} }
@ -108,7 +122,7 @@ export function getDocumentValidation(container: HTMLElement) {
successWrapper.appendChild(docLabel); successWrapper.appendChild(docLabel);
const certLabel = document.createElement('div'); const certLabel = document.createElement('div');
certLabel.textContent = `Certificate: ${state.certificateFile!.name}`; certLabel.textContent = `Certificate: ${state.certificateJson!.name}`;
successWrapper.appendChild(certLabel); successWrapper.appendChild(certLabel);
// === Mocked verification data === // === Mocked verification data ===