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
← All changes | src/AutoLaunch/fetchers/get-logo.js +39 -11 3.0.4 → 3.2.2 View file →
@@ -5,11 +5,12 @@
5 5 retryTwice,
6 6 setStatus,
7 7 } from '@auto-launch/functions/helpers';
8 8 import { updateOption } from '@auto-launch/functions/wp';
9 +import { launchStrings } from '@auto-launch/strings';
9 10 import { AI_HOST } from '@constants';
11 +import { digest } from '@shared/api/digest';
10 12 import { reqDataBasics } from '@shared/lib/data';
11 -import { __ } from '@wordpress/i18n';
12 13 import { uploadMedia } from '@wordpress/media-utils';
13 14
14 15 const { showAILogo } = window.extSharedData;
15 16 const fallback = {
@@ -23,22 +24,38 @@
23 24 export const handleSiteLogo = async ({ siteProfile }) => {
24 25 if (!showAILogo) return fallback;
25 26
26 27 // translators: this is for a action log UI. Keep it short
27 - setStatus(__('Generating a logo', 'extendify-local'));
28 + setStatus(launchStrings().statusLogo);
28 29
29 30 const { logoObjectName: objectName } = siteProfile;
30 31 const body = JSON.stringify({ ...reqDataBasics, objectName });
31 32 const response = await retryTwice(() =>
32 33 fetchWithTimeout(url, { method, headers, body }),
33 - );
34 + ).catch((error) => {
35 + return { ok: false, statusText: error.message, status: 0 };
36 + });
34 37
35 - if (!response?.ok) return fallback;
38 + if (!response?.ok) {
39 + digest({
40 + error: {
41 + message: response.statusText,
42 + name: 'FetchError',
43 + status: response.status,
44 + },
45 + details: { source: 'auto-launch', caller: 'handleSiteLogo', objectName },
46 + });
47 + return fallback;
48 + }
36 49
37 - const logoUrl = await failWithFallback(async () => {
38 - const { logoUrl } = getLogoShape.parse(await response.json());
39 - return logoUrl;
40 - }, fallback.logoUrl);
50 + const logoUrl = await failWithFallback(
51 + async () => {
52 + const { logoUrl } = getLogoShape.parse(await response.json());
53 + return logoUrl;
54 + },
55 + fallback.logoUrl,
56 + { caller: 'handleSiteLogo' },
57 + );
41 58
42 59 // If this errors we just move on.
43 60 await uploadLogo(logoUrl);
44 61
@@ -44,13 +61,18 @@
44 61
45 62 return getLogoShape.parse({ logoUrl });
46 63 };
47 64
48 -export const uploadLogo = async (url) => {
65 +// The backend serves the real brand logo from a `logos-custom/` path; other
66 +// logos keep the duotone-prefixed upload name.
67 +export const isExternalLogo = (url) => url?.includes('logos-custom/') ?? false;
68 +
69 +export const uploadLogo = async (url, { external = false } = {}) => {
49 70 const blob = await (await fetch(url)).blob();
50 71 const type = blob.type;
51 72 const fileExtension = type.replace('image/', '');
52 - const logoName = `ext-custom-logo-${Date.now()}`;
73 + const prefix = external ? 'ext-logo-' : 'ext-custom-logo-';
74 + const logoName = `${prefix}${Date.now()}`;
53 75 const image = new File([blob], `${logoName}.${fileExtension}`, { type });
54 76
55 77 await uploadMedia({
56 78 filesList: [image],
@@ -57,7 +79,13 @@
57 79 onFileChange: async ([fileObj]) => {
58 80 if (!fileObj?.id) return;
59 81 await updateOption('site_logo', fileObj.id);
60 82 },
61 - onError: console.error,
83 + onError: (err) => {
84 + console.error('Error uploading logo:', err);
85 + digest({
86 + error: err,
87 + details: { source: 'auto-launch', caller: 'uploadLogo' },
88 + });
89 + },
62 90 });
63 91 };