2020-04-02 19:44:21 +09:00
|
|
|
let data;
|
|
|
|
|
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 {
|
|
|
|
const response = await fetch('config.json', {
|
|
|
|
cache: 'no-cache'
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2020-05-12 06:28:14 +09:00
|
|
|
return getDefaultConfig();
|
2020-08-09 13:24:16 +02:00
|
|
|
}
|
2020-05-12 06:28:14 +09:00
|
|
|
}
|
|
|
|
|
2020-08-09 13:24:16 +02:00
|
|
|
async function getDefaultConfig() {
|
|
|
|
try {
|
|
|
|
const response = await fetch('config.template.json', {
|
|
|
|
cache: 'no-cache'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('network response was not ok');
|
|
|
|
}
|
|
|
|
|
2020-08-09 14:24:59 +02:00
|
|
|
data = await response.json();
|
2020-04-02 19:50:09 +09:00
|
|
|
return data;
|
2020-08-09 13:24:16 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error('failed to fetch the default web config file:', error);
|
|
|
|
}
|
2020-04-02 03:51:22 +09:00
|
|
|
}
|
|
|
|
|
2020-08-02 17:28:25 +09:00
|
|
|
export function getMultiServer() {
|
2020-04-02 03:51:22 +09:00
|
|
|
return getConfig().then(config => {
|
|
|
|
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
|
|
|
|
|
|
|
export function getThemes() {
|
|
|
|
return getConfig().then(config => {
|
|
|
|
return config.themes;
|
|
|
|
}).catch(error => {
|
|
|
|
console.log('cannot get web config:', error);
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getPlugins() {
|
|
|
|
return getConfig().then(config => {
|
|
|
|
return config.plugins;
|
|
|
|
}).catch(error => {
|
|
|
|
console.log('cannot get web config:', error);
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
}
|