HEX
Server: LiteSpeed
System: Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: swifizcd (1555)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/swifizcd/julnohub.com.ng/wp-content/plugins/extendify/src/AutoLaunch/functions/patterns.js
import { AI_HOST } from '@constants';
import { reqDataBasics } from '@shared/lib/data';
import { retryTwice } from './helpers';

const generatePatterns = async (page, data) => {
	const { siteProfile } = data;
	return await retryTwice(async () => {
		const response = await fetch(`${AI_HOST}/api/patterns`, {
			method: 'POST',
			headers: { 'Content-Type': 'application/json' },
			body: JSON.stringify({ ...reqDataBasics, siteProfile, page }),
		});
		if (!response.ok) {
			throw new Error(
				`Pattern generation failed with status ${response.status}`,
			);
		}
		return await response.json();
	});
};

export const generatePageContent = async (pages, data) => {
	const result = await Promise.allSettled(
		pages.map(
			(page) =>
				generatePatterns(page, data)
					.then((response) => response)
					.catch(() => page), // safe fallback
		),
	);

	return result?.map((page, i) => page.value || pages[i]);
};