2021-03-10 10:24:29 -05:00
|
|
|
import DefaultConfig from '../../config.json';
|
2023-04-16 23:37:37 -04:00
|
|
|
import fetchLocal from '../../utils/fetchLocal.ts';
|
2020-04-02 19:44:21 +09:00
|
|
|
|
2021-03-10 10:24:29 -05:00
|
|
|
let data;
|
2020-09-26 12:27:14 +03:00
|
|
|
|
2020-08-09 13:24:16 +02:00
|
|
|
async function getConfig() {
|
2020-04-02 19:44:21 +09:00
|
|
|
if (data) return Promise.resolve(data);
|
2020-08-09 13:24:16 +02:00
|
|
|
try {
|
2020-09-26 12:27:14 +03:00
|
|
|
const response = await fetchLocal('config.json', {
|
2023-05-15 09:46:22 -04:00
|
|
|
cache: 'no-store'
|
2020-08-09 13:24:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('network response was not ok');
|
|
|
|
}
|
|
|
|
|
|
|
|
data = await response.json();
|
|
|
|
|
2020-05-12 06:28:14 +09:00
|
|
|
return data;
|
2020-08-09 13:24:16 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.warn('failed to fetch the web config file:', error);
|
2021-03-10 10:46:39 -05:00
|
|
|
data = DefaultConfig;
|
|
|
|
return data;
|
2020-08-09 13:24:16 +02:00
|
|
|
}
|
2020-04-02 03:51:22 +09:00
|
|
|
}
|
|
|
|
|
2020-11-30 14:38:03 -05:00
|
|
|
export function getIncludeCorsCredentials() {
|
|
|
|
return getConfig()
|
2021-03-10 09:53:42 -05:00
|
|
|
.then(config => !!config.includeCorsCredentials)
|
2020-11-30 14:38:03 -05:00
|
|
|
.catch(error => {
|
|
|
|
console.log('cannot get web config:', error);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-02 17:28:25 +09:00
|
|
|
export function getMultiServer() {
|
2021-10-06 23:34:26 -04:00
|
|
|
// Enable multi-server support when served by webpack
|
2024-02-21 00:47:03 -05:00
|
|
|
if (__WEBPACK_SERVE__) {
|
2021-10-06 23:34:26 -04:00
|
|
|
return Promise.resolve(true);
|
|
|
|
}
|
|
|
|
|
2020-04-02 03:51:22 +09:00
|
|
|
return getConfig().then(config => {
|
2021-10-04 01:03:46 -04:00
|
|
|
return !!config.multiserver;
|
2020-04-24 13:46:57 +03:00
|
|
|
}).catch(error => {
|
2020-05-04 12:44:12 +02:00
|
|
|
console.log('cannot get web config:', error);
|
2020-04-24 13:46:57 +03:00
|
|
|
return false;
|
2020-04-02 03:51:22 +09:00
|
|
|
});
|
|
|
|
}
|
2020-08-02 17:28:25 +09:00
|
|
|
|
2020-09-12 09:12:40 +09:00
|
|
|
export function getServers() {
|
|
|
|
return getConfig().then(config => {
|
2020-10-30 22:13:56 +09:00
|
|
|
return config.servers || [];
|
2020-09-12 09:12:40 +09:00
|
|
|
}).catch(error => {
|
|
|
|
console.log('cannot get web config:', error);
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-08 11:39:46 +00:00
|
|
|
const baseDefaultTheme = {
|
2020-11-07 11:56:46 +00:00
|
|
|
'name': 'Dark',
|
|
|
|
'id': 'dark',
|
|
|
|
'default': true
|
|
|
|
};
|
|
|
|
|
2020-11-08 11:39:46 +00:00
|
|
|
let internalDefaultTheme = baseDefaultTheme;
|
|
|
|
|
2020-11-07 11:56:46 +00:00
|
|
|
const checkDefaultTheme = (themes) => {
|
|
|
|
if (themes) {
|
|
|
|
const defaultTheme = themes.find((theme) => theme.default);
|
|
|
|
|
2020-11-08 11:39:46 +00:00
|
|
|
if (defaultTheme) {
|
|
|
|
internalDefaultTheme = defaultTheme;
|
|
|
|
return;
|
2020-11-07 11:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-08 11:39:46 +00:00
|
|
|
internalDefaultTheme = baseDefaultTheme;
|
2020-11-07 11:56:46 +00:00
|
|
|
};
|
|
|
|
|
2020-08-02 17:28:25 +09:00
|
|
|
export function getThemes() {
|
|
|
|
return getConfig().then(config => {
|
2021-03-10 10:30:34 -05:00
|
|
|
if (!Array.isArray(config.themes)) {
|
|
|
|
console.error('web config is invalid, missing themes:', config);
|
|
|
|
}
|
2021-03-10 10:24:29 -05:00
|
|
|
const themes = Array.isArray(config.themes) ? config.themes : DefaultConfig.themes;
|
2020-11-08 11:39:46 +00:00
|
|
|
checkDefaultTheme(themes);
|
|
|
|
return themes;
|
2020-08-02 17:28:25 +09:00
|
|
|
}).catch(error => {
|
|
|
|
console.log('cannot get web config:', error);
|
2020-11-08 11:39:46 +00:00
|
|
|
checkDefaultTheme();
|
2021-03-10 10:24:29 -05:00
|
|
|
return DefaultConfig.themes;
|
2020-08-02 17:28:25 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-08 11:39:46 +00:00
|
|
|
export const getDefaultTheme = () => internalDefaultTheme;
|
|
|
|
|
2021-06-10 13:38:24 -04:00
|
|
|
export function getMenuLinks() {
|
|
|
|
return getConfig().then(config => {
|
|
|
|
if (!config.menuLinks) {
|
|
|
|
console.error('web config is invalid, missing menuLinks:', config);
|
|
|
|
}
|
|
|
|
return config.menuLinks || [];
|
|
|
|
}).catch(error => {
|
|
|
|
console.log('cannot get web config:', error);
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-02 17:28:25 +09:00
|
|
|
export function getPlugins() {
|
|
|
|
return getConfig().then(config => {
|
2021-03-10 10:30:34 -05:00
|
|
|
if (!config.plugins) {
|
|
|
|
console.error('web config is invalid, missing plugins:', config);
|
|
|
|
}
|
2021-03-10 10:24:29 -05:00
|
|
|
return config.plugins || DefaultConfig.plugins;
|
2020-08-02 17:28:25 +09:00
|
|
|
}).catch(error => {
|
|
|
|
console.log('cannot get web config:', error);
|
2021-03-10 10:24:29 -05:00
|
|
|
return DefaultConfig.plugins;
|
2020-08-02 17:28:25 +09:00
|
|
|
});
|
|
|
|
}
|