PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
extendify / src / AutoLaunch / fetchers / get-strings.js

get-strings.js in Extendify 3.2.2, at src/AutoLaunch/fetchers/get-strings.js

48 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getStringsShape } from '@auto-launch/fetchers/shape';
2 import {
3 failWithFallback,
4 fetchWithTimeout,
5 retryTwice,
6 setStatus,
7 } from '@auto-launch/functions/helpers';
8 import { launchStrings } from '@auto-launch/strings';
9 import { AI_HOST } from '@constants';
10 import { digest } from '@shared/api/digest';
11 import { reqDataBasics } from '@shared/lib/data';
12
13 const fallback = { aiHeaders: [], aiBlogTitles: [], heroDescription: '' };
14 const url = `${AI_HOST}/api/site-strings`;
15 const method = 'POST';
16 const headers = { 'Content-Type': 'application/json' };
17
18 export const handleSiteStrings = async ({ siteProfile }) => {
19 // translators: this is for a action log UI. Keep it short
20 setStatus(launchStrings().statusIdeas);
21
22 const body = JSON.stringify({ ...reqDataBasics, siteProfile });
23
24 const response = await retryTwice(() =>
25 fetchWithTimeout(url, { method, headers, body }),
26 ).catch((error) => {
27 return { ok: false, statusText: error.message, status: 0 };
28 });
29
30 if (!response?.ok) {
31 digest({
32 error: {
33 message: response.statusText,
34 name: 'FetchError',
35 status: response.status,
36 },
37 details: { source: 'auto-launch', caller: 'handleSiteStrings' },
38 });
39 return fallback;
40 }
41
42 return failWithFallback(
43 async () => getStringsShape.parse(await response.json()),
44 fallback,
45 { caller: 'handleSiteStrings' },
46 );
47 };
48