Replace axios with native fetch
This commit is contained in:
parent
ac9e52ac96
commit
a0326b00d1
18
package-lock.json
generated
18
package-lock.json
generated
@ -1481,15 +1481,6 @@
|
|||||||
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
|
"integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/svg-sprite-loader": {
|
|
||||||
"version": "3.9.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/svg-sprite-loader/-/svg-sprite-loader-3.9.2.tgz",
|
|
||||||
"integrity": "sha512-J4TffGc8WeBVUmLOQSrCgujcGEnovtvmyzRtfXj5ri/f4yaayTCPY4qwNEvdk67tnHV6GnhhuPsdOn6WrnfAMw==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"@types/webpack": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@types/tapable": {
|
"@types/tapable": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.6.tgz",
|
||||||
@ -3005,15 +2996,6 @@
|
|||||||
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
|
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"axios": {
|
|
||||||
"version": "0.21.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.0.tgz",
|
|
||||||
"integrity": "sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"follow-redirects": "^1.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"babel-code-frame": {
|
"babel-code-frame": {
|
||||||
"version": "6.26.0",
|
"version": "6.26.0",
|
||||||
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
|
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
"@vue/cli-service": "~4.5.0",
|
"@vue/cli-service": "~4.5.0",
|
||||||
"@vue/compiler-sfc": "^3.0.0",
|
"@vue/compiler-sfc": "^3.0.0",
|
||||||
"@vue/eslint-config-typescript": "^5.0.2",
|
"@vue/eslint-config-typescript": "^5.0.2",
|
||||||
"axios": "^0.21.0",
|
|
||||||
"babel-eslint": "^10.1.0",
|
"babel-eslint": "^10.1.0",
|
||||||
"eslint": "^7.5.0",
|
"eslint": "^7.5.0",
|
||||||
"eslint-plugin-vue": "^7.0.0-0",
|
"eslint-plugin-vue": "^7.0.0-0",
|
||||||
|
127
src/api.ts
127
src/api.ts
@ -1,4 +1,3 @@
|
|||||||
import axios, {AxiosResponse} from 'axios';
|
|
||||||
import {
|
import {
|
||||||
DynmapArea,
|
DynmapArea,
|
||||||
DynmapCircle,
|
DynmapCircle,
|
||||||
@ -16,50 +15,45 @@ import {
|
|||||||
DynmapWorld
|
DynmapWorld
|
||||||
} from "@/dynmap";
|
} from "@/dynmap";
|
||||||
|
|
||||||
function buildServerConfig(response: AxiosResponse): DynmapServerConfig {
|
function buildServerConfig(response: any): DynmapServerConfig {
|
||||||
const data = response.data;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: data.dynmapversion || '',
|
version: response.dynmapversion || '',
|
||||||
allowChat: data.allowwebchat || false,
|
allowChat: response.allowwebchat || false,
|
||||||
chatRequiresLogin: data['webchat-requires-login'] || false,
|
chatRequiresLogin: response['webchat-requires-login'] || false,
|
||||||
chatInterval: data['webchat-interval'] || 5,
|
chatInterval: response['webchat-interval'] || 5,
|
||||||
defaultMap: data.defaultmap || undefined,
|
defaultMap: response.defaultmap || undefined,
|
||||||
defaultWorld: data.defaultworld || undefined,
|
defaultWorld: response.defaultworld || undefined,
|
||||||
defaultZoom: data.defaultzoom || 0,
|
defaultZoom: response.defaultzoom || 0,
|
||||||
followMap: data.followmap || undefined,
|
followMap: response.followmap || undefined,
|
||||||
followZoom: data.followzoom || 0,
|
followZoom: response.followzoom || 0,
|
||||||
updateInterval: data.updaterate || 3000,
|
updateInterval: response.updaterate || 3000,
|
||||||
showLayerControl: data.showlayercontrol || true,
|
showLayerControl: response.showlayercontrol || true,
|
||||||
title: data.title || 'Dynmap',
|
title: response.title || 'Dynmap',
|
||||||
loginEnabled: data['login-enabled'] || false,
|
loginEnabled: response['login-enabled'] || false,
|
||||||
loginRequired: data.loginrequired || false,
|
loginRequired: response.loginrequired || false,
|
||||||
maxPlayers: data.maxcount || 0,
|
maxPlayers: response.maxcount || 0,
|
||||||
hash: data.confighash || 0,
|
hash: response.confighash || 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMessagesConfig(response: AxiosResponse): DynmapMessageConfig {
|
function buildMessagesConfig(response: any): DynmapMessageConfig {
|
||||||
const data = response.data;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chatNotAllowed: data['msg-chatnotallowed'] || '',
|
chatNotAllowed: response['msg-chatnotallowed'] || '',
|
||||||
chatRequiresLogin: data['msg-chatrequireslogin'] || '',
|
chatRequiresLogin: response['msg-chatrequireslogin'] || '',
|
||||||
chatCooldown: data.spammessage || '',
|
chatCooldown: response.spammessage || '',
|
||||||
mapTypes: data['msg-maptypes'] || '',
|
mapTypes: response['msg-maptypes'] || '',
|
||||||
players: data['msg-players'] || '',
|
players: response['msg-players'] || '',
|
||||||
playerJoin: data.joinmessage || '',
|
playerJoin: response.joinmessage || '',
|
||||||
playerQuit: data.quitmessage || '',
|
playerQuit: response.quitmessage || '',
|
||||||
anonymousJoin: data['msg-hiddennamejoin'] || '',
|
anonymousJoin: response['msg-hiddennamejoin'] || '',
|
||||||
anonymousQuit: data['msg-hiddennamequit'] || '',
|
anonymousQuit: response['msg-hiddennamequit'] || '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildWorlds(response: AxiosResponse): Array<DynmapWorld> {
|
function buildWorlds(response: any): Array<DynmapWorld> {
|
||||||
const data = response.data,
|
const worlds: Array<DynmapWorld> = [];
|
||||||
worlds: Array<DynmapWorld> = [];
|
|
||||||
|
|
||||||
(data.worlds || []).forEach((world: any) => {
|
(response.worlds || []).forEach((world: any) => {
|
||||||
const maps: Map<string, DynmapWorldMap> = new Map();
|
const maps: Map<string, DynmapWorldMap> = new Map();
|
||||||
|
|
||||||
(world.maps || []).forEach((map: any) => {
|
(world.maps || []).forEach((map: any) => {
|
||||||
@ -102,9 +96,8 @@ function buildWorlds(response: AxiosResponse): Array<DynmapWorld> {
|
|||||||
return worlds;
|
return worlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildComponents(response: AxiosResponse): DynmapComponentConfig {
|
function buildComponents(response: any): DynmapComponentConfig {
|
||||||
const data = response.data,
|
const components: DynmapComponentConfig = {
|
||||||
components: DynmapComponentConfig = {
|
|
||||||
markers: {
|
markers: {
|
||||||
showLabels: false,
|
showLabels: false,
|
||||||
},
|
},
|
||||||
@ -115,7 +108,7 @@ function buildComponents(response: AxiosResponse): DynmapComponentConfig {
|
|||||||
logoControls: [],
|
logoControls: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
(data.components || []).forEach((component: any) => {
|
(response.components || []).forEach((component: any) => {
|
||||||
const type = component.type || "unknown";
|
const type = component.type || "unknown";
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
@ -386,7 +379,13 @@ function buildUpdates(data: Array<any>): DynmapUpdates {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
getConfiguration(): Promise<DynmapConfigurationResponse> {
|
getConfiguration(): Promise<DynmapConfigurationResponse> {
|
||||||
return axios.get(window.config.url.configuration).then((response): DynmapConfigurationResponse => {
|
return fetch(window.config.url.configuration).then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}).then((response): DynmapConfigurationResponse => {
|
||||||
return {
|
return {
|
||||||
config: buildServerConfig(response),
|
config: buildServerConfig(response),
|
||||||
messages: buildMessagesConfig(response),
|
messages: buildMessagesConfig(response),
|
||||||
@ -401,11 +400,16 @@ export default {
|
|||||||
url = url.replace('{world}', world);
|
url = url.replace('{world}', world);
|
||||||
url = url.replace('{timestamp}', timestamp.toString());
|
url = url.replace('{timestamp}', timestamp.toString());
|
||||||
|
|
||||||
return axios.get(url).then((response): DynmapUpdateResponse => {
|
return fetch(url).then(response => {
|
||||||
const data = response.data,
|
if (!response.ok) {
|
||||||
players: Set<DynmapPlayer> = new Set();
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
|
|
||||||
(data.players || []).forEach((player: any) => {
|
return response.json();
|
||||||
|
}).then((response): DynmapUpdateResponse => {
|
||||||
|
const players: Set<DynmapPlayer> = new Set();
|
||||||
|
|
||||||
|
(response.players || []).forEach((player: any) => {
|
||||||
players.add({
|
players.add({
|
||||||
account: player.account || "",
|
account: player.account || "",
|
||||||
health: player.health || 0,
|
health: player.health || 0,
|
||||||
@ -440,15 +444,15 @@ export default {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
worldState: {
|
worldState: {
|
||||||
timeOfDay: data.servertime || 0,
|
timeOfDay: response.servertime || 0,
|
||||||
thundering: data.isThundering || false,
|
thundering: response.isThundering || false,
|
||||||
raining: data.hasStorm || false,
|
raining: response.hasStorm || false,
|
||||||
},
|
},
|
||||||
playerCount: data.count || 0,
|
playerCount: response.count || 0,
|
||||||
configHash: data.configHash || 0,
|
configHash: response.configHash || 0,
|
||||||
timestamp: data.timestamp || 0,
|
timestamp: response.timestamp || 0,
|
||||||
players,
|
players,
|
||||||
updates: buildUpdates(data.updates || []),
|
updates: buildUpdates(response.updates || []),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -456,18 +460,23 @@ export default {
|
|||||||
getMarkerSets(world: string): Promise<Map<string, DynmapMarkerSet>> {
|
getMarkerSets(world: string): Promise<Map<string, DynmapMarkerSet>> {
|
||||||
const url = `${window.config.url.markers}_markers_/marker_${world}.json`;
|
const url = `${window.config.url.markers}_markers_/marker_${world}.json`;
|
||||||
|
|
||||||
return axios.get(url).then((response): Map<string, DynmapMarkerSet> => {
|
return fetch(url).then(response => {
|
||||||
const data = response.data,
|
if (!response.ok) {
|
||||||
sets: Map<string, DynmapMarkerSet> = new Map();
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
|
|
||||||
data.sets = data.sets || {};
|
return response.json();
|
||||||
|
}).then((response): Map<string, DynmapMarkerSet> => {
|
||||||
|
const sets: Map<string, DynmapMarkerSet> = new Map();
|
||||||
|
|
||||||
for(const key in data.sets) {
|
response.sets = response.sets || {};
|
||||||
if(!Object.prototype.hasOwnProperty.call(data.sets, key)) {
|
|
||||||
|
for(const key in response.sets) {
|
||||||
|
if(!Object.prototype.hasOwnProperty.call(response.sets, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const set = data.sets[key],
|
const set = response.sets[key],
|
||||||
markers = buildMarkers(set.markers || {}),
|
markers = buildMarkers(set.markers || {}),
|
||||||
circles = buildCircles(set.circles || {}),
|
circles = buildCircles(set.circles || {}),
|
||||||
areas = buildAreas(set.areas || {}),
|
areas = buildAreas(set.areas || {}),
|
||||||
|
Loading…
Reference in New Issue
Block a user