feat: use production API endpoint

This commit is contained in:
2026-07-20 14:25:13 +08:00
parent 70e97ae8b9
commit 2ada52f35a
5 changed files with 185 additions and 10 deletions

View File

@@ -15,7 +15,8 @@ import type {
VoiceProcessingStatus
} from './types'
const DEFAULT_API_BASE_URL = 'http://127.0.0.1:8080'
const DEFAULT_API_BASE_URL = 'https://feedback.shay7sev.site'
const LEGACY_DEFAULT_API_BASE_URL = 'http://127.0.0.1:8080'
const API_BASE_URL_KEY = 'teaching-feedback-api-base-url-v1'
export const DEVELOPMENT_USER_ID = '5a4da7f0-d70c-465f-bcab-124c504aa9f0'
@@ -131,12 +132,24 @@ export class ApiRequestError extends Error {
}
}
function normalizeApiBaseUrl(value: string): string {
return value.trim().replace(/\/+$/, '')
}
export function getApiBaseUrl(): string {
return (wx.getStorageSync(API_BASE_URL_KEY) as string) || DEFAULT_API_BASE_URL
const storedValue = wx.getStorageSync(API_BASE_URL_KEY)
if (typeof storedValue !== 'string' || !storedValue.trim()) return DEFAULT_API_BASE_URL
const normalized = normalizeApiBaseUrl(storedValue)
if (normalized === LEGACY_DEFAULT_API_BASE_URL) {
wx.setStorageSync(API_BASE_URL_KEY, DEFAULT_API_BASE_URL)
return DEFAULT_API_BASE_URL
}
return normalized
}
export function setApiBaseUrl(value: string): string {
const normalized = value.trim().replace(/\/+$/, '')
const normalized = normalizeApiBaseUrl(value)
if (!/^https?:\/\/[^\s]+$/i.test(normalized)) {
throw new ApiRequestError('服务地址必须以 http:// 或 https:// 开头')
}