Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -1,114 +1,173 @@
|
|
1 |
-
class
|
2 |
constructor() {
|
3 |
this.fileInput = document.getElementById('file-upload');
|
4 |
-
this.
|
5 |
this.resultsContainer = document.getElementById('analysis-results');
|
|
|
|
|
6 |
|
7 |
this.initializeEventListeners();
|
8 |
}
|
9 |
|
10 |
initializeEventListeners() {
|
11 |
this.fileInput.addEventListener('change', (e) => this.handleFileChange(e));
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
const uploadArea = document.querySelector('.upload-area');
|
15 |
-
uploadArea.addEventListener('dragover', (e) => {
|
16 |
-
e.preventDefault();
|
17 |
-
uploadArea.style.borderColor = 'var(--primary-color)';
|
18 |
-
});
|
19 |
|
20 |
-
|
21 |
-
uploadArea.
|
|
|
|
|
|
|
22 |
});
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
uploadArea.addEventListener('drop', (e) => {
|
25 |
-
e.preventDefault();
|
26 |
-
uploadArea.style.borderColor = '#d1d5db';
|
27 |
const files = Array.from(e.dataTransfer.files);
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
});
|
30 |
}
|
31 |
|
32 |
-
|
33 |
-
const
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
|
37 |
-
async
|
38 |
-
this.
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
});
|
51 |
-
}
|
52 |
}
|
53 |
-
|
54 |
-
this.loading.classList.add('hidden');
|
55 |
}
|
56 |
|
57 |
-
async
|
58 |
return new Promise((resolve, reject) => {
|
59 |
const reader = new FileReader();
|
60 |
|
61 |
-
reader.onload =
|
62 |
const content = new Uint8Array(e.target.result);
|
63 |
-
const issues = [];
|
64 |
-
|
65 |
-
// Check file size (10MB limit)
|
66 |
-
if (file.size > 10000000) {
|
67 |
-
issues.push('File size exceeds 10MB');
|
68 |
-
}
|
69 |
-
|
70 |
-
// Check PDF header
|
71 |
const header = content.slice(0, 4);
|
72 |
const isPDF = String.fromCharCode(...header) === '%PDF';
|
|
|
73 |
if (!isPDF) {
|
74 |
-
|
75 |
}
|
76 |
-
|
77 |
-
resolve({
|
78 |
-
name: file.name,
|
79 |
-
issues,
|
80 |
-
size: file.size,
|
81 |
-
timestamp: new Date().toISOString()
|
82 |
-
});
|
83 |
};
|
84 |
|
85 |
-
reader.onerror = () => reject(new Error('
|
86 |
reader.readAsArrayBuffer(file);
|
87 |
});
|
88 |
}
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
}
|
110 |
|
111 |
-
//
|
112 |
document.addEventListener('DOMContentLoaded', () => {
|
113 |
-
new
|
114 |
});
|
|
|
1 |
+
class PDFComplianceAnalyzer {
|
2 |
constructor() {
|
3 |
this.fileInput = document.getElementById('file-upload');
|
4 |
+
this.loadingElement = document.getElementById('loading');
|
5 |
this.resultsContainer = document.getElementById('analysis-results');
|
6 |
+
this.reportContainer = document.getElementById('compliance-report');
|
7 |
+
this.reportContent = document.querySelector('.report-content');
|
8 |
|
9 |
this.initializeEventListeners();
|
10 |
}
|
11 |
|
12 |
initializeEventListeners() {
|
13 |
this.fileInput.addEventListener('change', (e) => this.handleFileChange(e));
|
14 |
+
this.setupDragAndDrop();
|
15 |
+
}
|
16 |
+
|
17 |
+
setupDragAndDrop() {
|
18 |
const uploadArea = document.querySelector('.upload-area');
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
21 |
+
uploadArea.addEventListener(eventName, (e) => {
|
22 |
+
e.preventDefault();
|
23 |
+
uploadArea.classList.add('drag-over');
|
24 |
+
});
|
25 |
});
|
26 |
+
|
27 |
+
['dragleave', 'drop'].forEach(eventName => {
|
28 |
+
uploadArea.addEventListener(eventName, (e) => {
|
29 |
+
e.preventDefault();
|
30 |
+
uploadArea.classList.remove('drag-over');
|
31 |
+
});
|
32 |
+
});
|
33 |
+
|
34 |
uploadArea.addEventListener('drop', (e) => {
|
|
|
|
|
35 |
const files = Array.from(e.dataTransfer.files);
|
36 |
+
if (files.length > 0 && files[0].type === 'application/pdf') {
|
37 |
+
this.analyzePDF(files[0]);
|
38 |
+
} else {
|
39 |
+
this.showError('Por favor, envie apenas arquivos PDF.');
|
40 |
+
}
|
41 |
});
|
42 |
}
|
43 |
|
44 |
+
handleFileChange(e) {
|
45 |
+
const file = e.target.files[0];
|
46 |
+
if (file && file.type === 'application/pdf') {
|
47 |
+
this.analyzePDF(file);
|
48 |
+
} else {
|
49 |
+
this.showError('Por favor, selecione um arquivo PDF válido.');
|
50 |
+
}
|
51 |
}
|
52 |
|
53 |
+
async analyzePDF(file) {
|
54 |
+
this.showLoading(true);
|
55 |
+
this.clearResults();
|
56 |
+
|
57 |
+
try {
|
58 |
+
// Simulação da análise do PDF
|
59 |
+
await this.validatePDF(file);
|
60 |
+
const report = await this.generateComplianceReport(file);
|
61 |
+
this.displayResults(report);
|
62 |
+
} catch (error) {
|
63 |
+
this.showError(error.message);
|
64 |
+
} finally {
|
65 |
+
this.showLoading(false);
|
|
|
|
|
66 |
}
|
|
|
|
|
67 |
}
|
68 |
|
69 |
+
async validatePDF(file) {
|
70 |
return new Promise((resolve, reject) => {
|
71 |
const reader = new FileReader();
|
72 |
|
73 |
+
reader.onload = (e) => {
|
74 |
const content = new Uint8Array(e.target.result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
const header = content.slice(0, 4);
|
76 |
const isPDF = String.fromCharCode(...header) === '%PDF';
|
77 |
+
|
78 |
if (!isPDF) {
|
79 |
+
reject(new Error('O arquivo não é um PDF válido.'));
|
80 |
}
|
81 |
+
resolve(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
};
|
83 |
|
84 |
+
reader.onerror = () => reject(new Error('Erro ao ler o arquivo.'));
|
85 |
reader.readAsArrayBuffer(file);
|
86 |
});
|
87 |
}
|
88 |
|
89 |
+
async generateComplianceReport(file) {
|
90 |
+
// Simulação de análise de conformidade
|
91 |
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
92 |
|
93 |
+
return {
|
94 |
+
status: 'compliant',
|
95 |
+
confidence: 92.5,
|
96 |
+
details: {
|
97 |
+
format: 'Válido',
|
98 |
+
version: 'PDF 1.7',
|
99 |
+
pages: 1,
|
100 |
+
signature: 'Presente e válida',
|
101 |
+
metadata: 'Completo',
|
102 |
+
accessibility: 'Conforme'
|
103 |
+
},
|
104 |
+
checks: [
|
105 |
+
{ name: 'Estrutura do documento', status: 'pass', score: 100 },
|
106 |
+
{ name: 'Metadados', status: 'pass', score: 95 },
|
107 |
+
{ name: 'Assinatura digital', status: 'pass', score: 100 },
|
108 |
+
{ name: 'Acessibilidade', status: 'pass', score: 85 }
|
109 |
+
]
|
110 |
+
};
|
111 |
+
}
|
112 |
+
|
113 |
+
displayResults(report) {
|
114 |
+
this.reportContainer.classList.remove('hidden');
|
115 |
|
116 |
+
const statusClass = report.status === 'compliant' ? 'alert-success' : 'alert-error';
|
117 |
+
const statusText = report.status === 'compliant' ? 'Conforme' : 'Não conforme';
|
118 |
+
|
119 |
+
this.reportContent.innerHTML = `
|
120 |
+
<div class="alert ${statusClass}">
|
121 |
+
<h3>Status: ${statusText}</h3>
|
122 |
+
<p>Nível de confiança: ${report.confidence}%</p>
|
123 |
+
</div>
|
124 |
+
|
125 |
+
<div class="report-section">
|
126 |
+
<h3>Detalhes do Documento</h3>
|
127 |
+
${Object.entries(report.details).map(([key, value]) => `
|
128 |
+
<div class="metric">
|
129 |
+
<span>${key}:</span>
|
130 |
+
<span>${value}</span>
|
131 |
+
</div>
|
132 |
+
`).join('')}
|
133 |
+
</div>
|
134 |
+
|
135 |
+
<div class="report-section">
|
136 |
+
<h3>Verificações de Conformidade</h3>
|
137 |
+
${report.checks.map(check => `
|
138 |
+
<div class="metric">
|
139 |
+
<span>${check.name}</span>
|
140 |
+
<span>${check.score}% - ${check.status === 'pass' ? 'Aprovado' : 'Reprovado'}</span>
|
141 |
+
</div>
|
142 |
+
`).join('')}
|
143 |
+
</div>
|
144 |
+
`;
|
145 |
+
}
|
146 |
+
|
147 |
+
showError(message) {
|
148 |
+
this.resultsContainer.innerHTML = `
|
149 |
+
<div class="alert alert-error">
|
150 |
+
<p>${message}</p>
|
151 |
+
</div>
|
152 |
+
`;
|
153 |
+
}
|
154 |
+
|
155 |
+
showLoading(show) {
|
156 |
+
if (show) {
|
157 |
+
this.loadingElement.classList.remove('hidden');
|
158 |
+
} else {
|
159 |
+
this.loadingElement.classList.add('hidden');
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
clearResults() {
|
164 |
+
this.resultsContainer.innerHTML = '';
|
165 |
+
this.reportContainer.classList.add('hidden');
|
166 |
+
this.reportContent.innerHTML = '';
|
167 |
}
|
168 |
}
|
169 |
|
170 |
+
// Inicialização
|
171 |
document.addEventListener('DOMContentLoaded', () => {
|
172 |
+
new PDFComplianceAnalyzer();
|
173 |
});
|