AJAX API Endpoints
Relevant source files
The following files were used as context for generating this wiki page:
AJAX API endpoints in the Duplicator project serve as the communication bridge between the frontend web interface and the backend PHP/SQLite services. These endpoints facilitate asynchronous operations such as managing machine configurations, handling file uploads, retrieving machine templates, and processing document library queries without requiring full page reloads.
The system utilizes a central routing mechanism within the main entry point to dispatch requests to specific API files or controller logic. This architecture supports the Electron-based desktop environment by allowing the frontend to interact with local services managed by the integrated Caddy and PHP-SAMP/FPM processes.
API Routing and Architecture
Requests are primarily routed through app/public/index.php, which acts as a front controller. It checks the page parameter in the $_GET array to determine if the request is destined for an API endpoint. If a match is found, it includes the corresponding file from the app/api/ directory or executes inline logic.
The routing logic ensures that API-specific headers, such as Content-Type: application/json, are set before returning data to the client.
Sources: app/public/index.php:127-317
Machine Management Endpoints
These endpoints handle the retrieval and deletion of machine-related data. They are critical for the administration panel where users manage duplicators and photocopiers.
Machine Template Retrieval
Used to fetch configuration templates for specific machine types.
- Endpoint:
?page=get-machine-template - Method: GET
- File:
app/api/get-machine-template.php(referenced viaindex.php)
Machine Deletion
Handles the removal of a machine from the database. This endpoint includes explicit authentication checks to ensure only administrators can perform deletions.
- Endpoint:
?page=ajax_delete_machine - Method: POST
- Parameters:
machine_id(int),machine_type(string: 'duplicopieur'|'photocopieur')
Sources: app/public/index.php:235-317, app/api/get-machine-template.php
| Parameter | Type | Description |
|---|---|---|
machine_id | Integer | The unique identifier of the machine to be deleted. |
machine_type | String | Must be either 'duplicopieur' or 'photocopieur'. |
| Sources: app/public/index.php:336-353 |
Help and Q&A Endpoints
The Help Management system uses AJAX to provide a rich text editing experience for machine-specific tutorials. This includes support for CRUD operations on Questions & Answers (Q&A) and file management for supplementary PDFs.
Q&A Management Logic
The admin_aide_machines.php model handles AJAX requests for retrieving specific Q&A entries during editing.
Help PDF Management
The system allows administrators to upload and list PDFs specifically for the help section.
- Upload:
?page=upload_aide_pdf&action=upload(POST) - Listing:
?page=upload_aide_pdf&action=list(GET)
Sources: app/view/admin_aide_machines.html.php:366-417, app/public/index.php:248-257
Document Library and Processing
The project includes specialized endpoints for a "Bibliothèque" (Library) that supports full-text search and directory indexing.
| Endpoint | File | Description |
|---|---|---|
search_bibliotheque | api/search_bibliotheque.php | Performs full-text search within the document library. |
preview_directory | api/preview_directory.php | Indexes and previews external directories for document inclusion. |
get_bibliotheque_thumbnail | api/get_bibliotheque_thumbnail.php | Retrieves or generates thumbnails for library files. |
index_file | api/index_file.php | Indexes a specific file into the search engine. |
| Sources: app/public/index.php:264-290 |
Document Retrieval Sequence
The flow for retrieving a file from the library involves permission checks and serving the file through an API proxy to maintain security.
Sources: app/public/index.php:292-300
Internal System Endpoints
These endpoints are used for system diagnostics and progress monitoring, often called by the Electron main process or utility scripts.
Ghostscript Status Check
Used primarily on Windows to verify if the Ghostscript binary is available for PDF processing tasks.
- Endpoint:
?check_ghostscript - Response:
{"available": true}or{"available": false, "error": "..."}
Sources: main-caddy.js:23-45, app/public/index.php:127-131
Image Processing Progress
Monitors the status of long-running image conversion tasks (e.g., PDF to PNG).
- Endpoint:
?page=check_image_progress - File:
api/check_image_progress.php
Sources: app/api/check_image_progress.php
Conclusion
The AJAX API endpoints form the backbone of the Duplicator project's interactive features. By delegating specific tasks to standalone files under the app/api/ directory, the architecture maintains a clean separation of concerns. This design allows the project to handle complex tasks like document indexing, machine configuration, and PDF imposition while providing a responsive user experience within the Electron wrapper.