Path: blob/main/components/supervisor/frontend/src/ide/gitpod-server-compatibility.ts
2501 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { serverUrl } from "../shared/urls";78const currentHost = new URL(serverUrl.toString()).hostname;910export const isSaaS = currentHost === "gitpod.io";1112const versionRegex = new RegExp("main.(\\d+)");1314function getVersionInfo(version: string) {15const result = versionRegex.exec(version);16if (!result) {17return;18}19return Number(result[1]);20}2122const serverVersion = (async () => {23const url = serverUrl.withApi({ pathname: "/version" }).toString();24const fetchVersion = async (retry: number) => {25try {26const resp = await fetch(url);27const currentVersionStr = await resp.text();28return getVersionInfo(currentVersionStr);29} catch (e) {30if (retry - 1 <= 0) {31throw e;32}33fetchVersion(retry - 1);34}35};36try {37return await fetchVersion(3);38} catch (e) {39console.error("failed to fetch server verson:", e);40}41})();4243export async function isSaaSServerGreaterThan(version: string) {44if (!isSaaS) {45return false;46}47const serverVersionNum = await serverVersion;48const versionNum = getVersionInfo(version);49return !!serverVersionNum && !!versionNum && serverVersionNum >= versionNum;50}515253