Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/extendif.../src/Draft/api
File: Data.js
import { AI_HOST } from '@constants';
[0] Fix | Delete
import { useAIConsentStore } from '@shared/state/ai-consent';
[1] Fix | Delete
import { useImageGenerationStore } from '@shared/state/generate-images.js';
[2] Fix | Delete
import { __ } from '@wordpress/i18n';
[3] Fix | Delete
[4] Fix | Delete
// Additional data to send with requests
[5] Fix | Delete
const allowList = [
[6] Fix | Delete
'siteId',
[7] Fix | Delete
'partnerId',
[8] Fix | Delete
'wpVersion',
[9] Fix | Delete
'wpLanguage',
[10] Fix | Delete
'devbuild',
[11] Fix | Delete
'isBlockTheme',
[12] Fix | Delete
'userId',
[13] Fix | Delete
'siteProfile',
[14] Fix | Delete
];
[15] Fix | Delete
[16] Fix | Delete
const { showAIConsent, userGaveConsent } = useAIConsentStore.getState();
[17] Fix | Delete
[18] Fix | Delete
const extraBody = {
[19] Fix | Delete
...Object.fromEntries(
[20] Fix | Delete
Object.entries(window.extSharedData).filter(([key]) =>
[21] Fix | Delete
allowList.includes(key),
[22] Fix | Delete
),
[23] Fix | Delete
),
[24] Fix | Delete
showAIConsent,
[25] Fix | Delete
userGaveConsent,
[26] Fix | Delete
};
[27] Fix | Delete
[28] Fix | Delete
export const completion = async (
[29] Fix | Delete
prompt,
[30] Fix | Delete
promptType,
[31] Fix | Delete
systemMessageKey,
[32] Fix | Delete
details,
[33] Fix | Delete
) => {
[34] Fix | Delete
const response = await fetch(`${AI_HOST}/api/draft/completion`, {
[35] Fix | Delete
method: 'POST',
[36] Fix | Delete
headers: { 'Content-Type': 'application/json' },
[37] Fix | Delete
body: JSON.stringify({
[38] Fix | Delete
prompt,
[39] Fix | Delete
promptType,
[40] Fix | Delete
systemMessageKey,
[41] Fix | Delete
details,
[42] Fix | Delete
globalState: useImageGenerationStore.getState(),
[43] Fix | Delete
...extraBody,
[44] Fix | Delete
}),
[45] Fix | Delete
});
[46] Fix | Delete
[47] Fix | Delete
if (!response.ok) {
[48] Fix | Delete
throw new Error(__('Service temporarily unavailable', 'extendify-local'));
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
return response;
[52] Fix | Delete
};
[53] Fix | Delete
[54] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function