Move dynmap urls into dynmap object for server configuration
This commit is contained in:
parent
167aebf6f5
commit
1173dcbbce
92
index.html
92
index.html
@ -20,44 +20,68 @@
|
||||
<meta name="description" content="Minecraft Dynamic Map" />
|
||||
|
||||
<title>Minecraft Dynamic Map - LiveAtlas</title>
|
||||
<!-- Remove this if you are using multiple maps -->
|
||||
|
||||
<!-- Remove this if you are using multiple servers in the config below -->
|
||||
<script src="./standalone/config.js"></script>
|
||||
|
||||
<script>
|
||||
window.liveAtlasConfig = {
|
||||
// Server URLS can be defined here instead of using the standalone/config.js file.
|
||||
// Multiple servers are supported too.
|
||||
// servers: {
|
||||
// creative: {
|
||||
// label: 'Creative',
|
||||
// configuration: 'http://dynmap.local/standalone/creative/MySQL_configuration.php',
|
||||
// update: 'http://dynmap.local/standalone/creative/MySQL_update.php?world={world}&ts={timestamp}',
|
||||
// sendmessage: 'http://dynmap.local/standalone/creative/MySQL_sendmessage.php',
|
||||
// login: 'http://dynmap.local/standalone/creative/MySQL_login.php',
|
||||
// register: 'http://dynmap.local/standalone/creative/MySQL_register.php',
|
||||
// tiles: 'http://dynmap.local/standalone/creative/MySQL_tiles.php?tile=',
|
||||
// markers: 'http://dynmap.local/standalone/creative/MySQL_markers.php?marker='
|
||||
// },
|
||||
// survival: {
|
||||
// label: 'Survival',
|
||||
// configuration: 'http://dynmap.local/standalone/survival/MySQL_configuration.php',
|
||||
// update: 'http://dynmap.local/standalone/survival/MySQL_update.php?world={world}&ts={timestamp}',
|
||||
// sendmessage: 'http://dynmap.local/standalone/survival/MySQL_sendmessage.php',
|
||||
// login: 'http://dynmap.local/standalone/survival/MySQL_login.php',
|
||||
// register: 'http://dynmap.local/standalone/survival/MySQL_register.php',
|
||||
// tiles: 'http://dynmap.local/standalone/survival/MySQL_tiles.php?tile=',
|
||||
// markers: 'http://dynmap.local/standalone/survival/MySQL_markers.php?marker='
|
||||
// },
|
||||
// build: {
|
||||
// label: 'Build',
|
||||
// configuration: 'http://dynmap.local/standalone/build/MySQL_configuration.php',
|
||||
// update: 'http://dynmap.local/standalone/build/MySQL_update.php?world={world}&ts={timestamp}',
|
||||
// sendmessage: 'http://dynmap.local/standalone/build/MySQL_sendmessage.php',
|
||||
// login: 'http://dynmap.local/standalone/build/MySQL_login.php',
|
||||
// register: 'http://dynmap.local/standalone/build/MySQL_register.php',
|
||||
// tiles: 'http://dynmap.local/standalone/build/MySQL_tiles.php?tile=',
|
||||
// markers: 'http://dynmap.local/standalone/build/MySQL_markers.php?marker='
|
||||
// }
|
||||
// }
|
||||
// Multiple servers are supported, see https://github.com/JLyne/LiveAtlas/wiki/Configuring-Multiple-Servers.
|
||||
servers: {
|
||||
creative: {
|
||||
label: 'Creative',
|
||||
url: '/map/creative',
|
||||
dynmap: {
|
||||
configuration: 'http://dynmap.local/standalone/creative/MySQL_configuration.php',
|
||||
update: 'http://dynmap.local/standalone/creative/MySQL_update.php?world={world}&ts={timestamp}',
|
||||
sendmessage: 'http://dynmap.local/standalone/creative/MySQL_sendmessage.php',
|
||||
login: 'http://dynmap.local/standalone/creative/MySQL_login.php',
|
||||
register: 'http://dynmap.local/standalone/creative/MySQL_register.php',
|
||||
tiles: 'http://dynmap.local/standalone/creative/MySQL_tiles.php?tile=',
|
||||
markers: 'http://dynmap.local/standalone/creative/MySQL_markers.php?marker='
|
||||
}
|
||||
},
|
||||
survival: {
|
||||
label: 'Survival',
|
||||
url: '/map/survival',
|
||||
dynmap: {
|
||||
configuration: 'http://dynmap.local/standalone/survival/MySQL_configuration.php',
|
||||
update: 'http://dynmap.local/standalone/survival/MySQL_update.php?world={world}&ts={timestamp}',
|
||||
sendmessage: 'http://dynmap.local/standalone/survival/MySQL_sendmessage.php',
|
||||
login: 'http://dynmap.local/standalone/survival/MySQL_login.php',
|
||||
register: 'http://dynmap.local/standalone/survival/MySQL_register.php',
|
||||
tiles: 'http://dynmap.local/standalone/survival/MySQL_tiles.php?tile=',
|
||||
markers: 'http://dynmap.local/standalone/survival/MySQL_markers.php?marker='
|
||||
}
|
||||
},
|
||||
build: {
|
||||
label: 'Build',
|
||||
url: '/map/build',
|
||||
dynmap: {
|
||||
configuration: 'http://dynmap.local/standalone/build/MySQL_configuration.php',
|
||||
update: 'http://dynmap.local/standalone/build/MySQL_update.php?world={world}&ts={timestamp}',
|
||||
sendmessage: 'http://dynmap.local/standalone/build/MySQL_sendmessage.php',
|
||||
login: 'http://dynmap.local/standalone/build/MySQL_login.php',
|
||||
register: 'http://dynmap.local/standalone/build/MySQL_register.php',
|
||||
tiles: 'http://dynmap.local/standalone/build/MySQL_tiles.php?tile=',
|
||||
markers: 'http://dynmap.local/standalone/build/MySQL_markers.php?marker='
|
||||
}
|
||||
},
|
||||
test: {
|
||||
label: 'Local Test',
|
||||
url: '/map/test',
|
||||
dynmap: {
|
||||
configuration: 'http://dynmap.local:8123/up/configuration',
|
||||
update: 'http://dynmap.local:8123/up/world/{world}/{timestamp}',
|
||||
sendmessage: 'http://dynmap.local:8123/up/sendmessage',
|
||||
login: 'http://dynmap.local:8123/up/login',
|
||||
register: 'http://dynmap.local:8123/up/register',
|
||||
tiles: 'http://dynmap.local:8123/tiles/',
|
||||
markers: 'http://dynmap.local:8123/tiles/'
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
117
src/api.ts
117
src/api.ts
@ -30,13 +30,13 @@ import {
|
||||
DynmapTileUpdate,
|
||||
DynmapUpdate,
|
||||
DynmapUpdateResponse,
|
||||
DynmapUpdates,
|
||||
DynmapUpdates, DynmapUrlConfig,
|
||||
DynmapWorld,
|
||||
DynmapWorldMap
|
||||
} from "@/dynmap";
|
||||
import {useStore} from "@/store";
|
||||
import ChatError from "@/errors/ChatError";
|
||||
import {LiveAtlasServerDefinition} from "@/index";
|
||||
import {LiveAtlasDynmapServerDefinition, LiveAtlasServerDefinition} from "@/index";
|
||||
|
||||
const titleColours = /§[0-9a-f]/ig;
|
||||
|
||||
@ -555,17 +555,8 @@ function buildUpdates(data: Array<any>): DynmapUpdates {
|
||||
return updates;
|
||||
}
|
||||
|
||||
export default {
|
||||
validateConfiguration(): Promise<Map<string, LiveAtlasServerDefinition>> {
|
||||
if (typeof window.liveAtlasConfig.servers !== 'undefined') {
|
||||
return this.validateLiveAtlasConfiguration(window.liveAtlasConfig.servers);
|
||||
}
|
||||
|
||||
return this.validateDynmapConfiguration(window.config.url as LiveAtlasServerDefinition ?? null);
|
||||
},
|
||||
|
||||
validateLiveAtlasConfiguration(config: any): Promise<Map<string, LiveAtlasServerDefinition>> {
|
||||
const check = '\nCheck your LiveAtlas configuration in index.html is correct.',
|
||||
const validateLiveAtlasConfiguration = (config: any): Promise<Map<string, LiveAtlasServerDefinition>> => {
|
||||
const check = '\nCheck your server configuration in index.html is correct.',
|
||||
result = new Map<string, LiveAtlasServerDefinition>();
|
||||
|
||||
if (!Object.keys(config).length) {
|
||||
@ -579,38 +570,57 @@ export default {
|
||||
|
||||
const serverConfig = config[server];
|
||||
|
||||
if (!serverConfig || serverConfig.constructor !== Object) {
|
||||
return Promise.reject(`Server '${server} has an invalid configuration. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.configuration) {
|
||||
return Promise.reject(`Server '${server} has no configuration URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.update) {
|
||||
return Promise.reject(`Server '${server} has no update URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.markers) {
|
||||
return Promise.reject(`Server '${server} has no markers URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.tiles) {
|
||||
return Promise.reject(`Server '${server} has no tiles URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.sendmessage) {
|
||||
return Promise.reject(`Server '${server} has no sendmessage URL. ${check}`);
|
||||
}
|
||||
|
||||
serverConfig.id = server;
|
||||
serverConfig.type = 'dynmap';
|
||||
|
||||
if (!serverConfig || serverConfig.constructor !== Object) {
|
||||
return Promise.reject(`Server '${server}' has an invalid configuration. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.dynmap || serverConfig.dynmap.constructor !== Object) {
|
||||
return Promise.reject(`Server '${server}' has an invalid configuration. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.dynmap.configuration) {
|
||||
return Promise.reject(`Server '${server}' has no dynmap configuration URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.dynmap.update) {
|
||||
return Promise.reject(`Server '${server}' has no dynmap update URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.dynmap.markers) {
|
||||
return Promise.reject(`Server '${server}' has no dynmap markers URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.dynmap.tiles) {
|
||||
return Promise.reject(`Server '${server}' has no dynmap tiles URL. ${check}`);
|
||||
}
|
||||
|
||||
if (!serverConfig.dynmap.sendmessage) {
|
||||
return Promise.reject(`Server '${server}' has no dynmap sendmessage URL. ${check}`);
|
||||
}
|
||||
|
||||
if(serverConfig.url) {
|
||||
const a = document.createElement('a');
|
||||
a.href = serverConfig.url;
|
||||
|
||||
if(a.origin !== window.location.origin) {
|
||||
return Promise.reject(`Server '${server}'s URL doesn't match LiveAtlas' origin. ${check}`);
|
||||
}
|
||||
|
||||
serverConfig.url = a.pathname;
|
||||
} else {
|
||||
serverConfig.url = serverConfig.id;
|
||||
}
|
||||
|
||||
result.set(server, serverConfig);
|
||||
}
|
||||
|
||||
return Promise.resolve(result);
|
||||
},
|
||||
};
|
||||
|
||||
validateDynmapConfiguration(config: LiveAtlasServerDefinition): Promise<Map<string, LiveAtlasServerDefinition>> {
|
||||
const validateDynmapConfiguration = (config: DynmapUrlConfig): Promise<Map<string, LiveAtlasDynmapServerDefinition>> => {
|
||||
const check = '\nCheck your standalone/config.js file exists and is being loaded correctly.';
|
||||
|
||||
if (!config) {
|
||||
@ -637,17 +647,28 @@ export default {
|
||||
return Promise.reject(`Dynmap sendmessage URL is missing. ${check}`);
|
||||
}
|
||||
|
||||
config.id = 'dynmap';
|
||||
config.label = 'Dynmap';
|
||||
|
||||
const result = new Map<string, LiveAtlasServerDefinition>();
|
||||
result.set('dynmap', config);
|
||||
const result = new Map<string, LiveAtlasDynmapServerDefinition>();
|
||||
result.set('dynmap', {
|
||||
id: 'dynmap',
|
||||
label: 'dynmap',
|
||||
type: 'dynmap',
|
||||
dynmap: config
|
||||
});
|
||||
|
||||
return Promise.resolve(result);
|
||||
};
|
||||
|
||||
export default {
|
||||
validateConfiguration(): Promise<Map<string, LiveAtlasServerDefinition>> {
|
||||
if (typeof window.liveAtlasConfig.servers !== 'undefined') {
|
||||
return validateLiveAtlasConfiguration(window.liveAtlasConfig.servers);
|
||||
}
|
||||
|
||||
return validateDynmapConfiguration(window.config.url ?? null);
|
||||
},
|
||||
|
||||
getConfiguration(): Promise<DynmapConfigurationResponse> {
|
||||
return fetch(useStore().getters.serverConfig.configuration).then(response => {
|
||||
return fetch(useStore().getters.serverConfig.dynmap.configuration).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network request failed: ' + response.statusText);
|
||||
}
|
||||
@ -671,7 +692,7 @@ export default {
|
||||
},
|
||||
|
||||
getUpdate(requestId: number, world: string, timestamp: number): Promise<DynmapUpdateResponse> {
|
||||
let url = useStore().getters.serverConfig.update;
|
||||
let url = useStore().getters.serverConfig.dynmap.update;
|
||||
url = url.replace('{world}', world);
|
||||
url = url.replace('{timestamp}', timestamp.toString());
|
||||
|
||||
@ -737,7 +758,7 @@ export default {
|
||||
},
|
||||
|
||||
getMarkerSets(world: string): Promise<Map<string, DynmapMarkerSet>> {
|
||||
const url = `${useStore().getters.serverConfig.markers}_markers_/marker_${world}.json`;
|
||||
const url = `${useStore().getters.serverConfig.dynmap.markers}_markers_/marker_${world}.json`;
|
||||
|
||||
return fetch(url).then(response => {
|
||||
if (!response.ok) {
|
||||
@ -781,7 +802,7 @@ export default {
|
||||
return Promise.reject(new ChatError("Chat is not enabled"));
|
||||
}
|
||||
|
||||
return fetch(useStore().getters.serverConfig.sendmessage, {
|
||||
return fetch(useStore().getters.serverConfig.dynmap.sendmessage, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name: null,
|
||||
|
8
src/index.d.ts
vendored
8
src/index.d.ts
vendored
@ -19,7 +19,13 @@ declare module '@vue/runtime-core' {
|
||||
}
|
||||
}
|
||||
|
||||
interface LiveAtlasServerDefinition extends DynmapUrlConfig {
|
||||
interface LiveAtlasServerDefinition {
|
||||
id: string
|
||||
label?: string
|
||||
url?: string
|
||||
}
|
||||
|
||||
interface LiveAtlasDynmapServerDefinition extends LiveAtlasServerDefinition {
|
||||
type: 'dynmap',
|
||||
dynmap: DynmapUrlConfig,
|
||||
}
|
@ -112,7 +112,7 @@ export class DynmapTileLayer extends TileLayer {
|
||||
|
||||
if (!url) {
|
||||
const path = escape(`${this._mapSettings.world.name}/${name}`);
|
||||
url = `${store.getters.serverConfig.tiles}${path}`;
|
||||
url = `${store.getters.serverConfig.dynmap.tiles}${path}`;
|
||||
|
||||
if(typeof timestamp !== 'undefined') {
|
||||
url += (url.indexOf('?') === -1 ? `?timestamp=${timestamp}` : `×tamp=${timestamp}`);
|
||||
|
@ -17,7 +17,7 @@
|
||||
import {GetterTree} from "vuex";
|
||||
import {State} from "@/store/state";
|
||||
import {getMinecraftTime} from "@/util";
|
||||
import {LiveAtlasServerDefinition} from "@/index";
|
||||
import {LiveAtlasDynmapServerDefinition} from "@/index";
|
||||
|
||||
export type Getters = {
|
||||
playerMarkersEnabled(state: State): boolean;
|
||||
@ -26,7 +26,7 @@ export type Getters = {
|
||||
night(state: State): boolean;
|
||||
mapBackground(state: State, getters: GetterTree<State, State> & Getters): string;
|
||||
url(state: State, getters: GetterTree<State, State> & Getters): string;
|
||||
serverConfig(state: State, getters: GetterTree<State, State> & Getters): LiveAtlasServerDefinition;
|
||||
serverConfig(state: State, getters: GetterTree<State, State> & Getters): LiveAtlasDynmapServerDefinition;
|
||||
}
|
||||
|
||||
export const getters: GetterTree<State, State> & Getters = {
|
||||
@ -76,11 +76,11 @@ export const getters: GetterTree<State, State> & Getters = {
|
||||
return `#${state.currentWorld.name};${state.currentMap.name};${locationString};${zoom}`;
|
||||
},
|
||||
|
||||
serverConfig(state: State): LiveAtlasServerDefinition {
|
||||
serverConfig(state: State): LiveAtlasDynmapServerDefinition {
|
||||
if(!state.currentServer) {
|
||||
throw RangeError("No current server");
|
||||
}
|
||||
|
||||
return state.servers.get(state.currentServer) as LiveAtlasServerDefinition;
|
||||
}
|
||||
return state.servers.get(state.currentServer) as LiveAtlasDynmapServerDefinition;
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user