PluginProbe
Extendify / 2.2.2
Extendify v2.2.2
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 0.6.0 0.7.0 All 126 releases
extendify / src / Shared / lib / utils.js

utils.js in Extendify 2.2.2, at src/Shared/lib/utils.js

67 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { pingServer } from '@shared/api/DataApi';
2
3 export const isOnLaunch = () => {
4 const q = new URLSearchParams(window.location.search);
5 return ['page'].includes(q.get('extendify-launch'));
6 };
7
8 export const deepMerge = (target, ...sources) => {
9 return sources.reduce((acc, source) => {
10 if (!isObject(acc) || !isObject(source)) {
11 return null;
12 }
13
14 const newTarget = { ...acc };
15
16 for (const key in source) {
17 if (isObject(source[key]) && key in newTarget) {
18 newTarget[key] = deepMerge(newTarget[key], source[key]);
19 } else {
20 newTarget[key] = source[key];
21 }
22 }
23
24 return newTarget;
25 }, target);
26 };
27
28 export const isObject = (value) => {
29 return typeof value === 'object' && !Array.isArray(value) && value !== null;
30 };
31
32 export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
33
34 export const wasPluginInstalled = (activePlugins, pluginSlug) =>
35 activePlugins?.filter((p) => p.includes(pluginSlug))?.length;
36
37 /**
38 * Will ping every 1s until we get a 200 response from the server.
39 * This is used because we were dealing with a particular issue where
40 * servers we're very resource limited and rate limiting was common.
41 * */
42 export const waitFor200Response = async () => {
43 try {
44 // This will error if not 200
45 await pingServer();
46 return true;
47 } catch (error) {
48 // Do nothing
49 }
50 await new Promise((resolve) => setTimeout(resolve, 1000));
51 return waitFor200Response();
52 };
53
54 export const retryOperation = async (operation, { maxAttempts = 1 }) => {
55 for (let attempt = 1; attempt <= maxAttempts; attempt++) {
56 try {
57 await waitFor200Response();
58 await operation();
59 break;
60 } catch (error) {
61 if (attempt === maxAttempts) {
62 throw error;
63 }
64 }
65 }
66 };
67