Add configuration version checking

This commit is contained in:
James Lyne 2021-12-09 18:26:57 +00:00
parent b98f37729d
commit e082502f88
3 changed files with 13 additions and 2 deletions

View File

@ -147,8 +147,11 @@
playersSearch: true,
// Use more compact pre-2.0 player marker style
compactPlayerMarkers: true,
}
compactPlayerMarkers: false,
},
// Config version. Do not modify.
version: 1
};
</script>

1
src/index.d.ts vendored
View File

@ -67,6 +67,7 @@ interface LiveAtlasGlobalConfig {
servers: Map<string, LiveAtlasServerDefinition>;
messages: LiveAtlasGlobalMessageConfig;
ui: LiveAtlasUIConfig;
version?: number;
}
interface LiveAtlasServerDefinition {

View File

@ -17,6 +17,9 @@
import {LiveAtlasGlobalConfig, LiveAtlasServerDefinition} from "@/index";
import ConfigurationError from "@/errors/ConfigurationError";
import {DynmapUrlConfig} from "@/dynmap";
import {useStore} from "@/store";
const expectedConfigVersion = 1;
const validateLiveAtlasConfiguration = (config: any): Map<string, LiveAtlasServerDefinition> => {
const check = '\nCheck your server configuration in index.html is correct.',
@ -125,6 +128,10 @@ export const getServerDefinitions = (config: LiveAtlasGlobalConfig): Map<string,
throw new ConfigurationError(`No configuration found.\nCheck for any syntax errors in your configuration in index.html. Your browser console may contain additional information.`);
}
if (config.version !== expectedConfigVersion) {
throw new ConfigurationError(`Configuration version mismatch.\nUse a fresh copy of index.html from your current LiveAtlas version (${useStore().state.version}) and reapply any customisations.`);
}
if (typeof config.servers !== 'undefined') {
return validateLiveAtlasConfiguration(config.servers);
}