chore: freeze guide and explain update
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
export type DataSourceMode = 'static' | 'api' | 'sdk'
|
||||
export type GuideContentDataSourceMode = 'static' | 'remote' | 'mock'
|
||||
|
||||
const allowedModes = new Set<DataSourceMode>(['static', 'api', 'sdk'])
|
||||
const allowedGuideContentModes = new Set<GuideContentDataSourceMode>(['static', 'remote', 'mock'])
|
||||
const defaultSdkScriptUrl = '/static/sgs-map-sdk/index.global.js'
|
||||
const defaultSgsEngineUrl = '/h5-sdk'
|
||||
const defaultSdkTimeoutMs = 5000
|
||||
const defaultGuideStaticDataBaseUrl = '/static/guide-data'
|
||||
const defaultAudioApiBaseUrl = '/yudao-server'
|
||||
|
||||
const normalizeMode = (mode: string | undefined): DataSourceMode => {
|
||||
if (mode && allowedModes.has(mode as DataSourceMode)) {
|
||||
@@ -13,6 +17,14 @@ const normalizeMode = (mode: string | undefined): DataSourceMode => {
|
||||
return 'static'
|
||||
}
|
||||
|
||||
const normalizeGuideContentMode = (mode: string | undefined): GuideContentDataSourceMode => {
|
||||
if (mode && allowedGuideContentModes.has(mode as GuideContentDataSourceMode)) {
|
||||
return mode as GuideContentDataSourceMode
|
||||
}
|
||||
|
||||
return 'static'
|
||||
}
|
||||
|
||||
const normalizeUrl = (url: string | undefined, fallback: string) => {
|
||||
const normalized = url?.trim()
|
||||
return normalized || fallback
|
||||
@@ -35,6 +47,17 @@ const inferOrigin = (url: string) => {
|
||||
|
||||
export const dataSourceConfig = {
|
||||
mode: normalizeMode(import.meta.env.VITE_DATA_SOURCE_MODE),
|
||||
guideContentMode: normalizeGuideContentMode(import.meta.env.VITE_GUIDE_CONTENT_SOURCE_MODE),
|
||||
guideStaticDataBaseUrl: normalizeUrl(
|
||||
import.meta.env.VITE_GUIDE_STATIC_DATA_BASE_URL,
|
||||
defaultGuideStaticDataBaseUrl
|
||||
),
|
||||
apiBaseUrl: import.meta.env.VITE_API_BASE_URL?.trim() || '',
|
||||
audioApiBaseUrl: normalizeUrl(
|
||||
import.meta.env.VITE_AUDIO_API_BASE_URL || import.meta.env.VITE_API_BASE_URL,
|
||||
defaultAudioApiBaseUrl
|
||||
),
|
||||
audioLanguage: import.meta.env.VITE_AUDIO_LANGUAGE === 'en-US' ? 'en-US' : 'zh-CN',
|
||||
sgsSdkScriptUrl: normalizeUrl(import.meta.env.VITE_SGS_SDK_SCRIPT_URL, defaultSdkScriptUrl),
|
||||
sgsMapEngineUrl: normalizeUrl(import.meta.env.VITE_SGS_H5_ENGINE_URL, defaultSgsEngineUrl),
|
||||
sgsSdkTargetOrigin: import.meta.env.VITE_SGS_SDK_ORIGIN?.trim() || '',
|
||||
@@ -42,6 +65,9 @@ export const dataSourceConfig = {
|
||||
}
|
||||
|
||||
export const isSgsSdkMode = () => dataSourceConfig.mode === 'sdk'
|
||||
export const isGuideContentStaticMode = () => dataSourceConfig.guideContentMode === 'static'
|
||||
export const isGuideContentRemoteMode = () => dataSourceConfig.guideContentMode === 'remote'
|
||||
export const isGuideContentMockMode = () => dataSourceConfig.guideContentMode === 'mock' && import.meta.env.DEV
|
||||
|
||||
export const getSgsMapTargetOrigin = () => (
|
||||
dataSourceConfig.sgsSdkTargetOrigin || inferOrigin(dataSourceConfig.sgsMapEngineUrl)
|
||||
|
||||
Reference in New Issue
Block a user