| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimizer\Modules\Optimization\Rest; |
| 4 |
|
| 5 |
use ImageOptimizer\Modules\Optimization\Classes\{ |
| 6 |
Bulk_Optimization, |
| 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_Operations extends Route_Base { |
| 17 |
protected string $path = 'bulk/operations'; |
| 18 |
|
| 19 |
public function get_name(): string { |
| 20 |
return 'bulk-optimization-operations'; |
| 21 |
} |
| 22 |
|
| 23 |
public function get_methods(): array { |
| 24 |
return [ 'GET' ]; |
| 25 |
} |
| 26 |
|
| 27 |
public function GET() { |
| 28 |
try { |
| 29 |
$operations = Bulk_Optimization::get_processed_images(); |
| 30 |
|
| 31 |
return $this->respond_success_json([ |
| 32 |
'operations' => $operations, |
| 33 |
]); |
| 34 |
} catch ( Throwable $t ) { |
| 35 |
return $this->respond_error_json([ |
| 36 |
'message' => $t->getMessage(), |
| 37 |
'code' => 'internal_server_error', |
| 38 |
]); |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
|