From 40b9f29e036ebf1c18cdaba8928e56a31d2bfe4f Mon Sep 17 00:00:00 2001 From: Walidoux Date: Thu, 4 May 2023 16:13:54 +0100 Subject: [PATCH] refactor(config/Endpoints): clean up --- src/config/Endpoints.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/config/Endpoints.ts b/src/config/Endpoints.ts index 92ec65a..f8033d0 100644 --- a/src/config/Endpoints.ts +++ b/src/config/Endpoints.ts @@ -1,29 +1,22 @@ import { getClient, ResponseType } from '@tauri-apps/api/http' -import { DomainTypes } from './Domain' import type { GamedataEndpoints } from '../tools/rusty' +import { useLocalStorage } from '../hooks/useLocalStorage' + +const { lang } = useLocalStorage() +export const client = await getClient() const PROD_VERSION_REGEX = /(production-[^/]+)/im const STABLE_PROD_VERSION = 'PRODUCTION-202304181630-471782382' - export let PROD_VERSION: string | undefined -const HABBO_URL = (domain: DomainTypes): string => { +const HABBO_URL = (domain: string): string => { return `https://www.habbo.${domain}` } export const HABBO_GORDON_URL = `https://images.habbo.com/gordon/${PROD_VERSION ?? STABLE_PROD_VERSION}` -export const client = await getClient() -await client - .get(`${HABBO_URL(DomainTypes.English)}/gamedata/external_variables/0`, { - responseType: ResponseType.Text - }) - .then(({ data }) => { - return (PROD_VERSION = (data as string).match(PROD_VERSION_REGEX)?.[0]) - }) - -export const GAMEDATA_ENDPOINTS = async (domain: DomainTypes): Promise => { +export const GAMEDATA_ENDPOINTS = async (domain: string): Promise => { return [ { src: `${HABBO_URL(domain)}/gamedata/furnidata_json/0`, @@ -33,6 +26,14 @@ export const GAMEDATA_ENDPOINTS = async (domain: DomainTypes): Promise { +export const ASSETS_ENDPOINTS = (domain: string): string[] => { return [`${HABBO_URL(domain)}/`] } + +await client + .get(`${HABBO_URL(lang())}/gamedata/external_variables/0`, { + responseType: ResponseType.Text + }) + .then(({ data }) => { + return (PROD_VERSION = (data as string).match(PROD_VERSION_REGEX)?.[0]) + })