support api proxy for amap

This commit is contained in:
MaysWind
2023-06-18 09:38:21 +08:00
parent 4f2b9d39da
commit fa68621b41
21 changed files with 289 additions and 94 deletions
+2
View File
@@ -1,5 +1,6 @@
const baseApiUrlPath = '/api';
const baseProxyUrlPath = '/proxy';
const baseAmapApiProxyUrlPath = '/_AMapService';
const googleMapJavascriptUrl = 'https://maps.googleapis.com/maps/api/js';
const baiduMapJavascriptUrl = 'https://api.map.baidu.com/api?v=3.0';
const amapJavascriptUrl = 'https://webapi.amap.com/maps?v=2.0';
@@ -7,6 +8,7 @@ const amapJavascriptUrl = 'https://webapi.amap.com/maps?v=2.0';
export default {
baseApiUrlPath: baseApiUrlPath,
baseProxyUrlPath: baseProxyUrlPath,
baseAmapApiProxyUrlPath: baseAmapApiProxyUrlPath,
googleMapJavascriptUrl: googleMapJavascriptUrl,
baiduMapJavascriptUrl: baiduMapJavascriptUrl,
amapJavascriptUrl: amapJavascriptUrl
+8 -4
View File
@@ -1,6 +1,6 @@
import { asyncLoadAssets } from "@/lib/misc.js";
import services from "@/lib/services.js";
import settings from "@/lib/settings.js";
import { asyncLoadAssets } from '@/lib/misc.js';
import services from '@/lib/services.js';
import settings from '@/lib/settings.js';
import logger from '@/lib/logger.js';
const amapHolder = {
@@ -15,7 +15,11 @@ export function loadAmapAssets() {
if (!window._AMapSecurityConfig) {
const amapSecurityConfig = {};
if (settings.getAmapSecurityVerificationMethod() === 'plain') {
if (settings.getAmapSecurityVerificationMethod() === 'internalproxy') {
amapSecurityConfig.serviceHost = services.generateAmapApiInternalProxyUrl();
} else if (settings.getAmapSecurityVerificationMethod() === 'externalproxy') {
amapSecurityConfig.serviceHost = settings.getAmapApiExternalProxyUrl();
} else if (settings.getAmapSecurityVerificationMethod() === 'plaintext') {
amapSecurityConfig.securityJsCode = settings.getAmapApplicationSecret();
}
+3
View File
@@ -423,5 +423,8 @@ export default {
},
generateAmapJavascriptUrl: (callbackFnName) => {
return `${api.amapJavascriptUrl}&key=${settings.getAmapApplicationKey()}&callback=${callbackFnName}`;
},
generateAmapApiInternalProxyUrl: () => {
return `${window.location.origin}${api.baseAmapApiProxyUrlPath}`;
}
};
+17 -4
View File
@@ -3,6 +3,8 @@ import Cookies from 'js-cookie';
import currencyConstants from '@/consts/currency.js';
import statisticsConstants from '@/consts/statistics.js';
import { base64decode } from '@/lib/common.js';
const settingsLocalStorageKey = 'ebk_app_settings';
const serverSettingsCookieKey = 'ebk_server_settings';
@@ -119,6 +121,16 @@ function getServerSetting(key) {
return undefined;
}
function getServerDecodedSetting(key) {
const value = getServerSetting(key);
if (!value) {
return value;
}
return decodeURIComponent(base64decode(value));
}
function clearSettings() {
localStorage.removeItem(settingsLocalStorageKey);
}
@@ -169,10 +181,11 @@ export default {
isDataExportingEnabled: () => getServerSetting('e') === '1',
getMapProvider: () => getServerSetting('m'),
isMapDataFetchProxyEnabled: () => getServerSetting('mp') === '1',
getGoogleMapAPIKey: () => getServerSetting('gmak'),
getBaiduMapAK: () => getServerSetting('bmak'),
getAmapApplicationKey: () => getServerSetting('amak'),
getGoogleMapAPIKey: () => getServerDecodedSetting('gmak'),
getBaiduMapAK: () => getServerDecodedSetting('bmak'),
getAmapApplicationKey: () => getServerDecodedSetting('amak'),
getAmapSecurityVerificationMethod: () => getServerSetting('amsv'),
getAmapApplicationSecret: () => getServerSetting('amas'),
getAmapApiExternalProxyUrl: () => getServerDecodedSetting('amep'),
getAmapApplicationSecret: () => getServerDecodedSetting('amas'),
clearSettings: clearSettings
};