2024-02-08 09:47:19 +00:00
|
|
|
import { isAirgapped } from "@appsmith/utils/airgapHelpers";
|
|
|
|
|
|
|
|
|
|
async function loadScript(src: string) {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
const s = document.createElement("script");
|
|
|
|
|
s.src = src;
|
|
|
|
|
s.onload = resolve;
|
|
|
|
|
s.onerror = reject;
|
|
|
|
|
s.crossOrigin = "anonymous";
|
|
|
|
|
s.id = "googleapis";
|
|
|
|
|
const headElement = document.getElementsByTagName("head")[0];
|
|
|
|
|
headElement && headElement.appendChild(s);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const executeGoogleApi = async () => {
|
|
|
|
|
const airGapped = isAirgapped();
|
|
|
|
|
// if the googleAPIsLoaded is already loaded, do not load it again.
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-02-08 09:47:19 +00:00
|
|
|
if (airGapped || (window as any).googleAPIsLoaded) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const gapiLoaded = () => {
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-02-08 09:47:19 +00:00
|
|
|
(window as any).googleAPIsLoaded = true;
|
|
|
|
|
};
|
|
|
|
|
const onError = () => {
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-02-08 09:47:19 +00:00
|
|
|
(window as any).googleAPIsLoaded = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await loadScript("https://apis.google.com/js/api.js").then(
|
|
|
|
|
gapiLoaded,
|
|
|
|
|
onError,
|
|
|
|
|
);
|
|
|
|
|
};
|