From 68efa03389f40a61f629d79d4bdb9a0c8054708f Mon Sep 17 00:00:00 2001 From: Jean Brito Date: Tue, 12 Nov 2024 14:15:12 -0300 Subject: [PATCH] fix: Update api query after 7.0 server version (#2966) * update api query after 7.0 version * remove useless code --- src/servers/supportedVersions/main.ts | 11 ++++++++--- src/urls.ts | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/servers/supportedVersions/main.ts b/src/servers/supportedVersions/main.ts index 884ac4d07..df6a3aea3 100644 --- a/src/servers/supportedVersions/main.ts +++ b/src/servers/supportedVersions/main.ts @@ -6,6 +6,7 @@ import { ipcMain } from 'electron'; import jwt from 'jsonwebtoken'; import moment from 'moment'; import { coerce, satisfies } from 'semver'; +import semverGte from 'semver/functions/gte'; import { dispatch, listen, select } from '../../store'; import { @@ -93,9 +94,13 @@ const getServerInfo = async (url: string): Promise => { return response.data; }; -const getUniqueId = async (url: string): Promise => { +const getUniqueId = async (url: string, version: string): Promise => { + const serverUrl = semverGte(`${version}.0`, '7.0.0') + ? urls.server(url).uniqueId + : urls.server(url).setting('uniqueID'); + const response = await axios.get<{ settings: { value: string }[] }>( - urls.server(url).setting('uniqueID') + serverUrl ); const value = response.data?.settings?.[0]?.value; @@ -321,7 +326,7 @@ const updateSupportedVersionsData = async ( .catch(logRequestError('server info')); if (!serverInfo) return; - const uniqueID = await getUniqueId(server.url) + const uniqueID = await getUniqueId(server.url, server.version || '') .then(dispatchUniqueIdUpdated(server.url)) .catch(logRequestError('unique ID')); diff --git a/src/urls.ts b/src/urls.ts index 2be0674b9..613b68035 100644 --- a/src/urls.ts +++ b/src/urls.ts @@ -19,6 +19,7 @@ export const supportedVersions = ({ export const server = (serverUrl: T) => ({ + uniqueId: `${serverUrl}/api/v1/settings.public?_id=uniqueID` as const, setting: (id: string) => `${serverUrl}/api/v1/settings.public?query={"_id": ${JSON.stringify( id