Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/extendif.../src/Shared/api
File: DataApi.js
import { AI_HOST, INSIGHTS_HOST } from '@constants';
[0] Fix | Delete
import { reqDataBasics } from '@shared/lib/data';
[1] Fix | Delete
import { useImageGenerationStore } from '@shared/state/generate-images';
[2] Fix | Delete
import apiFetch from '@wordpress/api-fetch';
[3] Fix | Delete
import { __ } from '@wordpress/i18n';
[4] Fix | Delete
[5] Fix | Delete
export const generateImage = async (imageData, signal) => {
[6] Fix | Delete
const response = await fetch(`${AI_HOST}/api/draft/image`, {
[7] Fix | Delete
method: 'POST',
[8] Fix | Delete
mode: 'cors',
[9] Fix | Delete
headers: { 'Content-Type': 'application/json' },
[10] Fix | Delete
signal: signal,
[11] Fix | Delete
body: JSON.stringify({
[12] Fix | Delete
...imageData,
[13] Fix | Delete
globalState: useImageGenerationStore.getState(),
[14] Fix | Delete
...reqDataBasics,
[15] Fix | Delete
}),
[16] Fix | Delete
});
[17] Fix | Delete
[18] Fix | Delete
const body = await response.json();
[19] Fix | Delete
[20] Fix | Delete
const imageCredits = {
[21] Fix | Delete
remaining: response.headers.get('x-ratelimit-remaining'),
[22] Fix | Delete
total: response.headers.get('x-ratelimit-limit'),
[23] Fix | Delete
refresh: response.headers.get('x-ratelimit-reset'),
[24] Fix | Delete
};
[25] Fix | Delete
[26] Fix | Delete
if (!response.ok) {
[27] Fix | Delete
if (body.status && body.status === 'content-policy-violation') {
[28] Fix | Delete
throw {
[29] Fix | Delete
message: __(
[30] Fix | Delete
'Your request was rejected as a result of our safety system. Your prompt may contain text that is not allowed by our safety system.',
[31] Fix | Delete
'extendify-local',
[32] Fix | Delete
),
[33] Fix | Delete
imageCredits,
[34] Fix | Delete
};
[35] Fix | Delete
}
[36] Fix | Delete
throw {
[37] Fix | Delete
message: __('Service temporarily unavailable', 'extendify-local'),
[38] Fix | Delete
imageCredits,
[39] Fix | Delete
};
[40] Fix | Delete
}
[41] Fix | Delete
return {
[42] Fix | Delete
images: body,
[43] Fix | Delete
imageCredits,
[44] Fix | Delete
id: response.headers.get('x-request-id'),
[45] Fix | Delete
};
[46] Fix | Delete
};
[47] Fix | Delete
[48] Fix | Delete
export const recordPluginActivity = async ({ slug, source }) => {
[49] Fix | Delete
try {
[50] Fix | Delete
const res = await fetch(`${INSIGHTS_HOST}/api/v1/plugin-install`, {
[51] Fix | Delete
method: 'POST',
[52] Fix | Delete
headers: { 'Content-Type': 'application/json', 'X-Extendify': 'true' },
[53] Fix | Delete
body: JSON.stringify({
[54] Fix | Delete
...reqDataBasics,
[55] Fix | Delete
slug,
[56] Fix | Delete
source,
[57] Fix | Delete
siteCreatedAt: window.extSharedData?.siteCreatedAt,
[58] Fix | Delete
}),
[59] Fix | Delete
});
[60] Fix | Delete
[61] Fix | Delete
// this should not break the app.
[62] Fix | Delete
if (!res.ok) {
[63] Fix | Delete
console.error('Bad response from server');
[64] Fix | Delete
return null;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
return await res.json();
[68] Fix | Delete
} catch (error) {
[69] Fix | Delete
console.error('Error sending plugin installation notification:', error);
[70] Fix | Delete
return null;
[71] Fix | Delete
}
[72] Fix | Delete
};
[73] Fix | Delete
[74] Fix | Delete
export const pingServer = async () =>
[75] Fix | Delete
await apiFetch({ path: '/extendify/v1/shared/ping' });
[76] Fix | Delete
[77] Fix | Delete
export const getPartnerPlugins = async (key) => {
[78] Fix | Delete
const plugins = await apiFetch({
[79] Fix | Delete
path: '/extendify/v1/shared/partner-plugins',
[80] Fix | Delete
});
[81] Fix | Delete
if (!Object.keys(plugins?.data ?? {}).length) {
[82] Fix | Delete
throw new Error('Could not get plugins');
[83] Fix | Delete
}
[84] Fix | Delete
if (key && plugins.data?.[key]) {
[85] Fix | Delete
return plugins.data[key];
[86] Fix | Delete
}
[87] Fix | Delete
return plugins.data;
[88] Fix | Delete
};
[89] Fix | Delete
[90] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function