- Redesigned frontend with Outfit/Figtree typography, coral accent palette, noise texture, glassmorphism header, and staggered animations - Split monolithic index.html into modular JS (app, api, upload, batch, results, page-viewer, utils) and extracted CSS - Fixed worker.py to generate page images for Visual Page Inspector - Added Docker Compose stack (web, worker, redis, postgres) - Added batch upload, HTML report export, rate limiting, and Redis queue - Extended test suite with checker, remediation, worker, and DB tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
/* API communication layer */
|
|
|
|
const API_BASE = 'api.php';
|
|
|
|
async function apiCall(action, options = {}) {
|
|
const { method = 'GET', body = null, params = {} } = options;
|
|
|
|
let url = API_BASE;
|
|
const queryParams = new URLSearchParams({ action, ...params });
|
|
|
|
if (method === 'GET') {
|
|
url += '?' + queryParams.toString();
|
|
}
|
|
|
|
const headers = {};
|
|
|
|
// Add MSAL token if available
|
|
if (window.msalToken) {
|
|
headers['Authorization'] = 'Bearer ' + window.msalToken;
|
|
}
|
|
|
|
const fetchOptions = { method, headers };
|
|
if (body) {
|
|
if (body instanceof FormData) {
|
|
body.append('action', action);
|
|
fetchOptions.body = body;
|
|
} else {
|
|
fetchOptions.body = body;
|
|
}
|
|
}
|
|
|
|
const response = await fetch(url, fetchOptions);
|
|
return response.json();
|
|
}
|
|
|
|
async function uploadFile(file) {
|
|
const formData = new FormData();
|
|
formData.append('pdf', file);
|
|
return apiCall('upload', { method: 'POST', body: formData });
|
|
}
|
|
|
|
async function startCheck(jobId, quickMode) {
|
|
const formData = new FormData();
|
|
formData.append('job_id', jobId);
|
|
if (quickMode) formData.append('quick_mode', '1');
|
|
return apiCall('check', { method: 'POST', body: formData });
|
|
}
|
|
|
|
async function checkStatus(jobId) {
|
|
return apiCall('status', { params: { job_id: jobId } });
|
|
}
|
|
|
|
async function getResult(jobId) {
|
|
return apiCall('result', { params: { job_id: jobId } });
|
|
}
|
|
|
|
async function getDebugInfo(jobId) {
|
|
return apiCall('debug', { params: { job_id: jobId } });
|
|
}
|
|
|
|
async function remediatePdf(jobId) {
|
|
const formData = new FormData();
|
|
formData.append('job_id', jobId);
|
|
return apiCall('remediate', { method: 'POST', body: formData });
|
|
}
|
|
|
|
async function getStats() {
|
|
return apiCall('stats');
|
|
}
|
|
|
|
async function uploadBatch(files) {
|
|
const formData = new FormData();
|
|
for (let i = 0; i < files.length; i++) {
|
|
formData.append('pdfs[]', files[i]);
|
|
}
|
|
return apiCall('batch_upload', { method: 'POST', body: formData });
|
|
}
|
|
|
|
async function checkBatchStatus(batchId) {
|
|
return apiCall('batch_status', { params: { batch_id: batchId } });
|
|
}
|
|
|
|
function getExportUrl(jobId, format) {
|
|
const params = new URLSearchParams({ action: 'export', job_id: jobId, format: format });
|
|
return API_BASE + '?' + params.toString();
|
|
}
|