90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
/**
|
|
* 應用配置工具類
|
|
* 用於管理環境變量和應用設置
|
|
*/
|
|
|
|
// 資料庫配置
|
|
export const dbConfig = {
|
|
host: process.env.DB_HOST || 'mysql.theaken.com',
|
|
port: parseInt(process.env.DB_PORT || '33306'),
|
|
user: process.env.DB_USER || 'root',
|
|
password: process.env.DB_PASSWORD || 'zh6161168',
|
|
database: process.env.DB_NAME || 'db_AI_scoring',
|
|
charset: 'utf8mb4',
|
|
timezone: '+08:00',
|
|
acquireTimeout: 60000,
|
|
timeout: 60000,
|
|
reconnect: true,
|
|
multipleStatements: true,
|
|
} as const
|
|
|
|
// AI 配置
|
|
export const aiConfig = {
|
|
geminiApiKey: process.env.GEMINI_API_KEY || 'AIzaSyAN3pEJr_Vn2xkCidGZAq9eQqsMVvpj8g4',
|
|
modelName: process.env.GEMINI_MODEL || 'gemini-1.5-pro',
|
|
maxTokens: parseInt(process.env.GEMINI_MAX_TOKENS || '8192'),
|
|
} as const
|
|
|
|
// 獲取應用基礎 URL
|
|
export function getAppUrl(): string {
|
|
// 在客戶端使用 window.location.origin
|
|
if (typeof window !== 'undefined') {
|
|
return window.location.origin
|
|
}
|
|
|
|
// 在服務端使用環境變量,如果沒有設置則使用 localhost:12024
|
|
return process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:12024'
|
|
}
|
|
|
|
// 獲取應用名稱
|
|
export function getAppName(): string {
|
|
return process.env.NEXT_PUBLIC_APP_NAME || 'AI 智能評審系統'
|
|
}
|
|
|
|
// 生成分享連結
|
|
export function generateShareUrl(evaluationId: string): string {
|
|
const baseUrl = getAppUrl()
|
|
return `${baseUrl}/results?id=${evaluationId}`
|
|
}
|
|
|
|
// 生成當前頁面連結
|
|
export function getCurrentUrl(): string {
|
|
if (typeof window !== 'undefined') {
|
|
return window.location.href
|
|
}
|
|
return getAppUrl()
|
|
}
|
|
|
|
// 環境變量配置
|
|
export const config = {
|
|
appUrl: getAppUrl(),
|
|
appName: getAppName(),
|
|
isDevelopment: process.env.NODE_ENV === 'development',
|
|
isProduction: process.env.NODE_ENV === 'production',
|
|
database: dbConfig,
|
|
ai: aiConfig,
|
|
} as const
|
|
|
|
// 配置驗證
|
|
export function validateConfig(): { isValid: boolean; errors: string[] } {
|
|
const errors: string[] = []
|
|
|
|
// 檢查必要的環境變量
|
|
if (!process.env.GEMINI_API_KEY) {
|
|
errors.push('GEMINI_API_KEY 環境變量未設置')
|
|
}
|
|
|
|
if (!process.env.DB_HOST) {
|
|
errors.push('DB_HOST 環境變量未設置')
|
|
}
|
|
|
|
if (!process.env.DB_NAME) {
|
|
errors.push('DB_NAME 環境變量未設置')
|
|
}
|
|
|
|
return {
|
|
isValid: errors.length === 0,
|
|
errors
|
|
}
|
|
}
|