Skip to content

Commit

Permalink
fix: Update api query after 7.0 server version (#2966)
Browse files Browse the repository at this point in the history
* update api query after 7.0 version

* remove useless code
  • Loading branch information
jeanfbrito authored Nov 12, 2024
1 parent 4b4640a commit 68efa03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/servers/supportedVersions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -93,9 +94,13 @@ const getServerInfo = async (url: string): Promise<ServerInfo> => {
return response.data;
};

const getUniqueId = async (url: string): Promise<string> => {
const getUniqueId = async (url: string, version: string): Promise<string> => {
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;

Expand Down Expand Up @@ -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'));

Expand Down
1 change: 1 addition & 0 deletions src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const supportedVersions = ({

export const server = <T extends string>(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
Expand Down

0 comments on commit 68efa03

Please sign in to comment.