Skip to content

Commit

Permalink
[api] Switch to public API for get_config()
Browse files Browse the repository at this point in the history
  • Loading branch information
romainr committed Jun 8, 2021
1 parent e9325e6 commit 472cf7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion desktop/core/src/desktop/js/api/urls.js
Expand Up @@ -21,7 +21,6 @@ export const DOCUMENTS_API = '/desktop/api2/doc/';
export const DOCUMENTS_SEARCH_API = '/desktop/api2/docs/';
export const GET_HUE_CONFIG_API = '/desktop/api2/get_hue_config';
export const FETCH_CONFIG_API = '/api/get_config/';
export const FETCH_CONFIG_API_PRIVATE = '/desktop/api2/get_config/';
export const HDFS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('/');
export const ADLS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('adl:/');
export const ABFS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('ABFS://');
Expand Down
Expand Up @@ -156,7 +156,7 @@
}
try {
await getConfig(true);
await getConfig();
} catch (err) {
errorMessage.value = 'Failed loading the Hue config!';
console.error(err);
Expand Down
8 changes: 3 additions & 5 deletions desktop/core/src/desktop/js/config/hueConfig.ts
Expand Up @@ -47,11 +47,10 @@ type ConnectorTest<T extends keyof InterpreterMap> = (connector: InterpreterMap[
let lastConfigPromise: Promise<HueConfig> | undefined;
let lastKnownConfig: HueConfig | undefined;

export const refreshConfig = async (viaApi?: boolean): Promise<HueConfig> => {
export const refreshConfig = async (): Promise<HueConfig> => {
lastConfigPromise = new Promise<HueConfig>(async (resolve, reject) => {
try {
const url = viaApi ? URLS.FETCH_CONFIG_API : URLS.FETCH_CONFIG_API_PRIVATE;
const apiResponse = await post<HueConfig>(url, {}, { silenceErrors: true });
const apiResponse = await post<HueConfig>(URLS.FETCH_CONFIG_API, {}, { silenceErrors: true });
if (apiResponse.status == 0) {
lastKnownConfig = apiResponse;
resolve(lastKnownConfig);
Expand All @@ -77,8 +76,7 @@ export const refreshConfig = async (viaApi?: boolean): Promise<HueConfig> => {

export const getLastKnownConfig = (): HueConfig | undefined => lastKnownConfig;

export const getConfig = async (viaApi?: boolean): Promise<HueConfig> =>
getLastKnownConfig() || refreshConfig(viaApi);
export const getConfig = async (): Promise<HueConfig> => getLastKnownConfig() || refreshConfig();

const getInterpreters = <T extends keyof InterpreterMap>(appType: T): InterpreterMap[T][] => {
if (!lastKnownConfig || !lastKnownConfig.app_config) {
Expand Down

0 comments on commit 472cf7f

Please sign in to comment.