mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-28 04:25:29 +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>
39 lines
768 B
JavaScript
39 lines
768 B
JavaScript
import apiFetch from '@wordpress/api-fetch';
|
|
import { addQueryArgs } from '@wordpress/url';
|
|
import APIError from './exceptions/APIError';
|
|
|
|
const wpV2Prefix = '/wp/v2';
|
|
|
|
class API {
|
|
static async request({ path, data, method = 'POST' }) {
|
|
try {
|
|
if ('GET' === method && !path.startsWith(wpV2Prefix)) {
|
|
path = addQueryArgs(path, { sb_time: new Date().getTime() });
|
|
}
|
|
|
|
const response = await apiFetch({
|
|
path,
|
|
method,
|
|
data,
|
|
});
|
|
|
|
if (path.startsWith(wpV2Prefix)) {
|
|
return response;
|
|
}
|
|
|
|
if (!response.success) {
|
|
throw new APIError(response.data.message);
|
|
}
|
|
|
|
return response.data;
|
|
} catch (e) {
|
|
if (e instanceof APIError) {
|
|
throw e;
|
|
} else {
|
|
throw new APIError(e.message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default API;
|