mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-25 18:48:00 +08:00
* [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * Added replace remediation action * Add submit logic * Add submit alt text logic, generate AI alt text * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation --------- Co-authored-by: Raz Ohad <admin@bainternet.info>
73 lines
1.4 KiB
PHP
73 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace EA11y\Modules\Scanner\Rest;
|
|
|
|
use EA11y\Modules\Scanner\Classes\Route_Base;
|
|
use EA11y\Modules\Scanner\Classes\Utils;
|
|
use EA11y\Classes\Utils as Global_Utils;
|
|
use Throwable;
|
|
use WP_Error;
|
|
use WP_REST_Response;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly
|
|
}
|
|
|
|
class Generate_Alt_Text extends Route_Base {
|
|
public string $path = 'generate-alt-text';
|
|
|
|
public function get_methods(): array {
|
|
return [ 'POST' ];
|
|
}
|
|
|
|
public function get_name(): string {
|
|
return 'generate-alt-text';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return WP_Error|WP_REST_Response
|
|
*
|
|
*/
|
|
public function POST( $request ) {
|
|
try {
|
|
$error = $this->verify_capability();
|
|
|
|
if ( $error ) {
|
|
return $error;
|
|
}
|
|
|
|
$image = $request->get_param( 'image' );
|
|
$svg = $request->get_param( 'svg' );
|
|
|
|
if ( ! ( $image || $svg ) ) {
|
|
return $this->respond_error_json( [
|
|
'message' => 'Missing required parameters',
|
|
'code' => 'missing_parameters',
|
|
] );
|
|
}
|
|
|
|
$src = $image ?? Utils::create_tmp_file_from_png_base64( $svg );
|
|
|
|
$result = Global_Utils::get_api_client()->make_request(
|
|
'POST',
|
|
'ai/image-alt',
|
|
[],
|
|
[],
|
|
false,
|
|
$src
|
|
);
|
|
|
|
return $this->respond_success_json( [
|
|
'message' => 'Alt text generated',
|
|
'data' => $result->response,
|
|
] );
|
|
|
|
} catch ( Throwable $t ) {
|
|
return $this->respond_error_json( [
|
|
'message' => $t->getMessage(),
|
|
'code' => 'internal_server_error',
|
|
] );
|
|
}
|
|
}
|
|
}
|