Current Path: > home > codekrsu > > ameliagraphics.com > wp-content > plugins > extendify > src > > > Shared > lib
Operation : Linux premium131.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 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
__tests__ | Directory | - | - | |
dom.js | File | 254 bytes | March 26 2025 18:03:22. | |
extra-body.js | File | 307 bytes | July 16 2025 19:39:24. | |
pages.js | File | 16304 bytes | April 14 2025 20:31:16. | |
parsing.js | File | 115 bytes | April 14 2025 20:31:16. | |
unsplash.js | File | 1959 bytes | May 19 2025 16:47:28. | |
utils.js | File | 1571 bytes | May 12 2025 16:42:28. |
import { AI_HOST } from '@constants'; import { useAIConsentStore } from '@shared/state/ai-consent'; import { useUnsplashCacheStore } from '@shared/state/unsplash-cache'; const { showAIConsent, userGaveConsent } = useAIConsentStore.getState(); // Additional data to send with requests const allowList = [ 'siteId', 'partnerId', 'wpVersion', 'wpLanguage', 'devbuild', 'isBlockTheme', 'userId', 'siteProfile', ]; const extraBody = { ...Object.fromEntries( Object.entries(window.extSharedData).filter(([key]) => allowList.includes(key), ), ), showAIConsent, userGaveConsent, }; export const fetchImages = async (search, source = null) => { const queryString = new URLSearchParams({ ...extraBody, query: search, source, }); const res = await fetch( `${AI_HOST}/api/draft/image/unsplash?${queryString.toString()}`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, }, ); if (!res.ok) { throw new Error('Bad response from server'); } const images = await res.json(); if (!Array.isArray(images)) { throw new Error('Bad response from server'); } const result = images.map((image) => ({ ...image, requestMetadata: { id: res.headers.get('X-Request-Id'), total: res.headers.get('X-Total'), perPage: res.headers.get('X-Per-Page'), }, })); return result; }; export const preFetchImages = async () => { const cache = useUnsplashCacheStore.getState(); if (!cache.isEmpty() && !cache.hasExpired()) { return cache.images; } const { aiKeywords } = window.extSharedData?.siteProfile ?? {}; const queries = aiKeywords?.length ? aiKeywords : []; const images = ( await Promise.all(queries.map((query) => fetchImages(query, 'prefetch'))) ).flat(); const uniqueImagesMap = images.reduce((acc, image) => { if (!acc.has(image.id)) { acc.set(image.id, image); } return acc; }, new Map()); cache.updateCache(Array.from(uniqueImagesMap.values())); return images; };
SILENT KILLER Tool