| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Optimization\Rest; |
| 4 |
|
| 5 |
use ImageOptimization\Modules\Optimization\Classes\{ |
| 6 |
Bulk_Optimization\Bulk_Optimization_Controller, |
| 7 |
Route_Base, |
| 8 |
}; |
| 9 |
|
| 10 |
use Throwable; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Get_Bulk_Optimization_Images extends Route_Base { |
| 17 |
protected string $path = 'bulk/images'; |
| 18 |
|
| 19 |
public function get_name(): string { |
| 20 |
return 'bulk-optimization-images'; |
| 21 |
} |
| 22 |
|
| 23 |
public function get_methods(): array { |
| 24 |
return [ 'GET' ]; |
| 25 |
} |
| 26 |
|
| 27 |
public function GET() { |
| 28 |
$error = $this->verify_capability(); |
| 29 |
|
| 30 |
if ( $error ) { |
| 31 |
return $error; |
| 32 |
} |
| 33 |
|
| 34 |
try { |
| 35 |
$images = Bulk_Optimization_Controller::get_processed_images(); |
| 36 |
|
| 37 |
return $this->respond_success_json([ |
| 38 |
'images' => $images, |
| 39 |
]); |
| 40 |
} catch ( Throwable $t ) { |
| 41 |
return $this->respond_error_json([ |
| 42 |
'message' => $t->getMessage(), |
| 43 |
'code' => 'internal_server_error', |
| 44 |
]); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|