speakingApiConfig.ts 1.2 KB

123456789101112131415161718192021222324
  1. export const FALLBACK_SPEAKING_API_HOST = 'https://ppt-english-speaking-api.cocorobo.cn'
  2. const ENV_SPEAKING_API_HOST = import.meta.env.VITE_SPEAKING_API_HOST?.trim()
  3. const SPEAKING_API_HOST = (ENV_SPEAKING_API_HOST || FALLBACK_SPEAKING_API_HOST).replace(/\/+$/, '')
  4. export const SPEAKING_DIALOGUE_API_BASE_URL = `${SPEAKING_API_HOST}/api/speaking/dialogue`
  5. export const SPEAKING_CONFIG_API_BASE_URL = `${SPEAKING_API_HOST}/api/speaking/config`
  6. export const SPEAKING_ARTICLE_API_BASE_URL = `${SPEAKING_API_HOST}/api/speaking/article`
  7. export type SpeakTransport = 'websocket' | 'http'
  8. const ENV_SPEAKING_TRANSPORT = import.meta.env.VITE_SPEAKING_TRANSPORT?.trim().toLowerCase()
  9. export const SPEAKING_TRANSPORT: SpeakTransport = ENV_SPEAKING_TRANSPORT === 'http' ? 'http' : 'websocket'
  10. export function buildSpeakingWsUrl(path: string): string {
  11. const normalizedPath = path.startsWith('/') ? path : `/${path}`
  12. return `${SPEAKING_DIALOGUE_API_BASE_URL.replace(/^http/, 'ws')}${normalizedPath}`
  13. }
  14. export function buildArticleWsUrl(path: string): string {
  15. const normalizedPath = path.startsWith('/') ? path : `/${path}`
  16. return `${SPEAKING_ARTICLE_API_BASE_URL.replace(/^http/, 'ws')}${normalizedPath}`
  17. }