541e24c6f4
- 新增 admin_users/admin_sessions 表与 adminAuth 工具(scrypt 密码 + 独立会话 Cookie) - /admin/init 初始化首个管理员,未初始化时服务端/客户端双守卫引导 - 后台鉴权改为管理员会话,前台 Casdoor 用户一律普通用户、与后台解耦 - Casdoor 配置改存 settings 表并由「统一认证」页管理,移除全部 CASDOOR 环境变量 - 侧边栏增加统一认证/管理员入口与登出;LoginModal 感知 SSO 启用状态 - 补充 adminAuth 测试,重写 casdoor 测试,全部 23 项通过
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { useRuntimeConfig } from '#imports'
|
||
|
||
/**
|
||
* 统一的应用配置读取。
|
||
*
|
||
* 所有配置均来自 Nuxt runtimeConfig(生产环境由 K8s 环境变量注入,
|
||
* 本地开发由 .env 注入),避免散落的 process.env 读取。
|
||
*
|
||
* 环境变量映射:
|
||
* SESSION_SECRET -> sessionSecret
|
||
* DB_PATH -> dbPath(默认 生产 /data/arcticnewone.db,开发 .data/arcticnewone.db)
|
||
* SMTP_HOST/PORT/USER/PASS/FROM -> smtp.*
|
||
* CONTACT_TO -> contactTo
|
||
* ADMIN_EMAILS -> adminEmails(逗号分隔)
|
||
* NUXT_PUBLIC_SITE_URL -> public.siteUrl
|
||
*/
|
||
export interface AppConfig {
|
||
dbPath: string
|
||
sessionSecret: string
|
||
smtp: {
|
||
host: string
|
||
port: number
|
||
user: string
|
||
pass: string
|
||
from: string
|
||
}
|
||
contactTo: string
|
||
/** OSS 服务(RustFS / S3 v4 兼容) */
|
||
oss: {
|
||
endpoint: string
|
||
accessKey: string
|
||
secretKey: string
|
||
bucket: string
|
||
region: string
|
||
publicBase: string
|
||
}
|
||
siteUrl: string
|
||
}
|
||
|
||
export function getConfig(): AppConfig {
|
||
const c = useRuntimeConfig()
|
||
const cfg = _buildConfig(c)
|
||
const siteUrl = String((c.public as { siteUrl?: string })?.siteUrl || '').replace(/\/$/, '')
|
||
cfg.siteUrl = siteUrl
|
||
return cfg
|
||
}
|
||
|
||
function _buildConfig(c: any): AppConfig {
|
||
return {
|
||
dbPath: (c.dbPath as string) || '.data/arcticnewone.db',
|
||
sessionSecret: (c.sessionSecret as string) || '',
|
||
smtp: {
|
||
host: (c.smtpHost as string) || '',
|
||
port: Number(c.smtpPort) || 587,
|
||
user: (c.smtpUser as string) || '',
|
||
pass: (c.smtpPass as string) || '',
|
||
from: (c.smtpFrom as string) || '',
|
||
},
|
||
contactTo: (c.contactTo as string) || '',
|
||
oss: {
|
||
endpoint: String((c.ossEndpoint as string) || '').replace(/^https?:\/\//, '').replace(/\/$/, ''),
|
||
accessKey: String((c.ossAccessKey as string) || ''),
|
||
secretKey: String((c.ossSecretKey as string) || ''),
|
||
bucket: String((c.ossBucket as string) || ''),
|
||
region: String((c.ossRegion as string) || 'us-east-1'),
|
||
publicBase: String((c.ossPublicBase as string) || '').replace(/\/$/, ''),
|
||
},
|
||
siteUrl: '',
|
||
}
|
||
}
|