[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: DataApi.js
import { AI_HOST, IMAGES_HOST, PATTERNS_HOST } from '@constants'; import { getSiteStyle } from '@page-creator/api/WPApi'; import { useUserStore } from '@page-creator/state/user'; const { siteTitle } = window.extSharedData; const extraBody = { ...Object.fromEntries( Object.entries(window.extSharedData).filter(([key]) => // Optionally add items to request body [ 'partnerId', 'devbuild', 'version', 'siteId', 'wpLanguage', 'wpVersion', 'siteProfile', ].includes(key), ), ), }; const fetchPageTemplates = async (details = {}) => { const { showLocalizedCopy, activePlugins, installedPlugins } = window.extSharedData; const { allowsInstallingPlugins } = useUserStore.getState(); const sitePlugins = details?.sitePlugins || []; const plugins = activePlugins?.map((path) => { return path.split('/')[0]; }) ?? []; const data = Object.entries(details).reduce((acc, [key, value]) => { if (value === null) return acc; acc[key] = typeof value === 'object' ? JSON.stringify(value) : value; return acc; }, {}); const res = await fetch(`${PATTERNS_HOST}/api/page-creator`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...extraBody, showLocalizedCopy: !!showLocalizedCopy, allowsInstallingPlugins, plugins: JSON.stringify(plugins), installedPlugins: JSON.stringify(installedPlugins), allowedPlugins: JSON.stringify(sitePlugins), ...data, }), }); if (!res.ok) throw new Error('Bad response from server'); return await res.json(); }; export const getGeneratedPageTemplate = async ({ pageProfile, siteImages, sitePlugins, }) => { const siteStyle = await getSiteStyle(); // we need the new generated AI description from the page profile const page = await fetchPageTemplates({ siteInformation: { title: siteTitle }, siteImages, siteStyle, pageProfile, sitePlugins, }); if (!page?.template) { throw new Error('Could not get page'); } const currentTheme = window.extSharedData?.themeSlug || 'extendable'; if (currentTheme !== 'extendable') { page.template.patterns = page.template.patterns.filter( (pattern) => !pattern.patternTypes.includes('page-title'), ); } return page; }; export const generateCustomContent = async ({ page, userState, pageProfile, }) => { const res = await fetch(`${AI_HOST}/api/patterns`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...extraBody, page, userState, siteProfile: pageProfile, }), }); if (!res.ok) throw new Error('Bad response from server'); return await res.json(); }; export const getPageProfile = async ({ description, siteProfile }) => { const response = await fetch(`${AI_HOST}/api/page-profile`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...extraBody, siteDescription: siteProfile?.description || '', description, }), }); if (!response?.ok) { throw new Error('Something went wrong while fetching the profile'); } const data = await response.json(); return data?.aiDescription ? data : { aiTitle: null, aiPageType: null, aiDescription: null, aiKeywords: [], }; }; export const getPageImages = async ({ pageProfile }) => { const { aiSiteType, aiSiteCategory, aiDescription, aiKeywords } = pageProfile; const search = new URLSearchParams({ aiSiteType, aiSiteCategory, aiDescription, aiKeywords, ...extraBody, source: 'page-creator', }); if (siteTitle) search.append('title', siteTitle); const response = await fetch(`${IMAGES_HOST}/api/search?${search}`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }); if (!response?.ok) { throw new Error('Something went wrong while fetching the images'); } const data = await response.json(); return data?.siteImages ? data : { siteImages: [] }; }; export const getSitePlugins = async ({ pageProfile }) => { const url = `${AI_HOST}/api/site-plugins`; const method = 'POST'; const headers = { 'Content-Type': 'application/json' }; const fallback = []; if (!pageProfile) { return fallback; } const { wpLanguage, partnerId, pluginGroupId } = window.extSharedData; const body = JSON.stringify({ type: pageProfile?.aiPageType || '', description: pageProfile?.aiDescription || '', keywords: pageProfile?.aiKeywords || [], siteQuestions: [], wpLanguage, partnerId, pluginGroupId, }); let response; try { response = await fetch(url, { method, headers, body }); if (!response?.ok) throw new Error('Bad response from server'); } catch (_error) { try { response = await fetch(url, { method, headers, body }); } catch { return fallback; } } if (!response?.ok) return fallback; try { const data = await response.json(); return data?.selectedPlugins ?? fallback; } catch (_error) { return fallback; } }; export const getImprintPageTemplate = async () => { const siteStyle = await getSiteStyle(); const endpoint = `${PATTERNS_HOST}/api/page-imprint`; const res = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...extraBody, siteStyle: JSON.stringify(siteStyle), }), }); if (!res.ok) throw new Error('Could not get imprint page'); const response = await res.json(); if (!response?.template) { throw new Error('No template found for imprint page'); } return { ...response.template }; };
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium56.web-hosting.com
Server IP: 198.54.119.70
PHP Version: 8.2.30
Server Software: LiteSpeed
System: Linux premium56.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 70.69 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: bkunreyz
User ID (UID): 830
Group ID (GID): 826
Script Owner UID: 830
Current Dir Owner: 830