| | |
| | | |
| | | use JVBase\importers\JaneAppClientImporter; |
| | | use JVBase\importers\JaneAppSalesImporter; |
| | | use JVBase\Instance; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\rest\Route; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | | use WP_Error; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | */ |
| | | class ImporterRoutes extends Rest |
| | | { |
| | | use Instance; |
| | | /** |
| | | * Register REST routes |
| | | */ |
| | |
| | | 'options' => 'string', // JSON string of options |
| | | ]) |
| | | ->auth('admin') |
| | | ->rateLimit(3, 300); // 3 imports per 5 minutes |
| | | ->rateLimit(3, 300) |
| | | ->register(); // 3 imports per 5 minutes |
| | | |
| | | // Sales import endpoint |
| | | Route::for('jane/import-sales') |
| | |
| | | 'options' => 'string', // JSON string of options |
| | | ]) |
| | | ->auth('admin') |
| | | ->rateLimit(3, 300); // 3 imports per 5 minutes |
| | | ->rateLimit(3, 300) |
| | | ->register(); // 3 imports per 5 minutes |
| | | |
| | | // Get import status |
| | | Route::for(Route::pattern('jane/import-status/{id}')) |
| | | ->get([$this, 'getImportStatus']) |
| | | ->arg('id', 'string|required') |
| | | ->auth('admin') |
| | | ->rateLimit(30, 60); |
| | | ->rateLimit(30) |
| | | ->register(); |
| | | } |
| | | |
| | | /** |
| | |
| | | // Get uploaded file |
| | | $files = $request->get_file_params(); |
| | | if (empty($files['file'])) { |
| | | return $this->error('No file uploaded', 'no_file', 400); |
| | | return $this->error('No file uploaded', 'no_file'); |
| | | } |
| | | |
| | | $file = $files['file']; |
| | | |
| | | // Validate file type |
| | | if (!$this->isValidCSV($file)) { |
| | | return $this->error('Invalid file type. Please upload a CSV file.', 'invalid_file', 400); |
| | | return $this->error('Invalid file type. Please upload a CSV file.', 'invalid_file'); |
| | | } |
| | | |
| | | // Get and parse options |
| | |
| | | // Get uploaded file |
| | | $files = $request->get_file_params(); |
| | | if (empty($files['file'])) { |
| | | return $this->error('No file uploaded', 'no_file', 400); |
| | | return $this->error('No file uploaded', 'no_file'); |
| | | } |
| | | |
| | | $file = $files['file']; |
| | | |
| | | // Validate file type |
| | | if (!$this->isValidCSV($file)) { |
| | | return $this->error('Invalid file type. Please upload a CSV file.', 'invalid_file', 400); |
| | | return $this->error('Invalid file type. Please upload a CSV file.', 'invalid_file'); |
| | | } |
| | | |
| | | // Get and parse options |