1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/scripts/settings/webSettings.js
Julien Machiels 37bd08fef6
Update src/scripts/settings/webSettings.js
Co-authored-by: Cameron <Influence365@gmail.com>
2020-08-11 15:32:40 +02:00

65 lines
1.5 KiB
JavaScript

let data;
async function getConfig() {
if (data) return Promise.resolve(data);
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();
return data;
} catch (error) {
console.warn('failed to fetch the web config file:', error);
return getDefaultConfig();
}
}
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');
}
data = await response.json();
return data;
} catch (error) {
console.error('failed to fetch the default web config file:', error);
}
}
export function getMultiServer() {
return getConfig().then(config => {
return config.multiserver;
}).catch(error => {
console.log('cannot get web config:', error);
return false;
});
}
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 [];
});
}