Skip to content

Commit

Permalink
update api query after 7.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanfbrito committed Nov 7, 2024
1 parent ba14487 commit 106f3a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 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,14 @@ 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> => {
if (!url || !version) return '';
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 +327,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 106f3a4

Please sign in to comment.