mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #2503 from thornbill/fix-invalid-configs
Fix default values for invalid config.json files
(cherry picked from commit 7650c885d6
)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
parent
85013363e8
commit
5ec953e344
1 changed files with 15 additions and 24 deletions
|
@ -1,5 +1,6 @@
|
||||||
let data;
|
import DefaultConfig from '../../config.json';
|
||||||
|
|
||||||
|
let data;
|
||||||
const urlResolver = document.createElement('a');
|
const urlResolver = document.createElement('a');
|
||||||
|
|
||||||
// `fetch` with `file:` support
|
// `fetch` with `file:` support
|
||||||
|
@ -55,30 +56,14 @@ async function getConfig() {
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('failed to fetch the web config file:', error);
|
console.warn('failed to fetch the web config file:', error);
|
||||||
return getDefaultConfig();
|
data = DefaultConfig;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getDefaultConfig() {
|
|
||||||
try {
|
|
||||||
const response = await fetchLocal('config.template.json', {
|
|
||||||
cache: 'no-cache'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('network response was not ok');
|
|
||||||
}
|
|
||||||
|
|
||||||
data = await response.json();
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
|
||||||
console.error('failed to fetch the default web config file:', error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getIncludeCorsCredentials() {
|
export function getIncludeCorsCredentials() {
|
||||||
return getConfig()
|
return getConfig()
|
||||||
.then(config => config.includeCorsCredentials)
|
.then(config => !!config.includeCorsCredentials)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log('cannot get web config:', error);
|
console.log('cannot get web config:', error);
|
||||||
return false;
|
return false;
|
||||||
|
@ -87,7 +72,7 @@ export function getIncludeCorsCredentials() {
|
||||||
|
|
||||||
export function getMultiServer() {
|
export function getMultiServer() {
|
||||||
return getConfig().then(config => {
|
return getConfig().then(config => {
|
||||||
return config.multiserver;
|
return !!config.multiserver;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log('cannot get web config:', error);
|
console.log('cannot get web config:', error);
|
||||||
return false;
|
return false;
|
||||||
|
@ -126,13 +111,16 @@ const checkDefaultTheme = (themes) => {
|
||||||
|
|
||||||
export function getThemes() {
|
export function getThemes() {
|
||||||
return getConfig().then(config => {
|
return getConfig().then(config => {
|
||||||
const themes = Array.isArray(config.themes) ? config.themes : [];
|
if (!Array.isArray(config.themes)) {
|
||||||
|
console.error('web config is invalid, missing themes:', config);
|
||||||
|
}
|
||||||
|
const themes = Array.isArray(config.themes) ? config.themes : DefaultConfig.themes;
|
||||||
checkDefaultTheme(themes);
|
checkDefaultTheme(themes);
|
||||||
return themes;
|
return themes;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log('cannot get web config:', error);
|
console.log('cannot get web config:', error);
|
||||||
checkDefaultTheme();
|
checkDefaultTheme();
|
||||||
return [];
|
return DefaultConfig.themes;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,9 +128,12 @@ export const getDefaultTheme = () => internalDefaultTheme;
|
||||||
|
|
||||||
export function getPlugins() {
|
export function getPlugins() {
|
||||||
return getConfig().then(config => {
|
return getConfig().then(config => {
|
||||||
return config.plugins;
|
if (!config.plugins) {
|
||||||
|
console.error('web config is invalid, missing plugins:', config);
|
||||||
|
}
|
||||||
|
return config.plugins || DefaultConfig.plugins;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log('cannot get web config:', error);
|
console.log('cannot get web config:', error);
|
||||||
return [];
|
return DefaultConfig.plugins;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue