feat: 完善系统配置、安全增强与知识库功能
- .env.example: API基础路径改为相对路径 /api/v1,支持代理转发 - README.md: 完善项目结构与启动说明文档 - docker-compose.yml: 新增Docker编排配置,支持容器化部署 - docker/: 新增Docker部署相关文档与配置 - server_start.sh: 重构启动脚本,添加容器环境检测、隔离虚拟环境路径、环境变量覆盖机制 - deps.py: 完善API依赖注入,增强权限验证逻辑 - admin_secret.py: 优化管理员密钥加密存储与验证 - config.py: 扩展配置管理,支持多环境变量绑定 - security.py: 增强安全模块,完善加密与认证机制 - db/base.py: 优化数据库基础架构与连接管理 - main.py: 更新应用入口,整合新模块路由 - models/: 完善系统模型配置,支持模型设置持久化 - repositories/settings.py: 优化设置仓储层,增强数据持久化 - services/settings.py: 重构设置服务,精简代码结构 - router.py: 更新API路由配置 - endpoints/knowledge.py: 新增知识库API端点 - schemas/knowledge.py: 新增知识库数据模型 - services/knowledge.py: 新增知识库业务逻辑 - storage/knowledge/.index.json: 知识库索引存储 - api.js: 完善API服务层,增强错误处理 - bootstrap.js: 优化前端初始化与引导流程 - useSetupView.js / useSystemState.js: 重构组合式函数 - TopBar.vue: 优化顶部导航栏组件 - SettingsView.vue: 重构设置页面UI,增强用户体验 - SetupView.vue / SetupRouteView.vue: 完善引导流程页面 - PoliciesView.vue: 优化策略视图组件 - vite.config.js: 更新Vite构建配置 - web_start.sh: 完善前端启动脚本 - views/scripts/: 优化各业务视图JS逻辑 - settings-view.css: 重构设置页面样式 - setup-view.css: 完善引导页样式 - policies-view.css: 优化策略页样式 - test_auth_service.py: 完善认证服务测试 - test_settings_persistence.py: 增强设置持久化测试 - document/: 新增开发文档与工作日志
This commit is contained in:
176
web/src/services/bootstrap.js
vendored
176
web/src/services/bootstrap.js
vendored
@@ -1,88 +1,88 @@
|
||||
const SETUP_API_BASE = '/__setup'
|
||||
|
||||
function formatValidationErrors(detail) {
|
||||
if (!Array.isArray(detail)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return detail
|
||||
.map((item) => {
|
||||
const field = Array.isArray(item.loc) ? item.loc[item.loc.length - 1] : 'field'
|
||||
return `${field}: ${item.msg}`
|
||||
})
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
async function request(path, options = {}) {
|
||||
let response
|
||||
|
||||
try {
|
||||
response = await fetch(`${SETUP_API_BASE}${path}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers || {})
|
||||
},
|
||||
...options
|
||||
})
|
||||
} catch {
|
||||
throw new Error('无法连接初始化服务,请确认本地配置桥已启动。')
|
||||
}
|
||||
|
||||
let data = null
|
||||
|
||||
try {
|
||||
data = await response.json()
|
||||
} catch {
|
||||
data = null
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const validationMessage = formatValidationErrors(data?.detail)
|
||||
const message = validationMessage || data?.detail || '初始化请求失败,请稍后重试。'
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export function fetchBootstrapState() {
|
||||
return request('/bootstrap')
|
||||
}
|
||||
|
||||
export function saveBootstrapConfig(payload) {
|
||||
return request('/bootstrap', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
export function startBootstrapBackend() {
|
||||
return request('/bootstrap/backend', {
|
||||
method: 'POST'
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchBootstrapBackendStatus() {
|
||||
return request('/bootstrap/backend')
|
||||
}
|
||||
|
||||
export function testBootstrapRuntime(payload) {
|
||||
return request('/bootstrap/runtime', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
export function testBootstrapDatabase(payload) {
|
||||
return request('/bootstrap/database', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
export function loginBootstrapAdmin(payload) {
|
||||
return request('/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
const SETUP_API_BASE = '/__setup'
|
||||
|
||||
function formatValidationErrors(detail) {
|
||||
if (!Array.isArray(detail)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return detail
|
||||
.map((item) => {
|
||||
const field = Array.isArray(item.loc) ? item.loc[item.loc.length - 1] : 'field'
|
||||
return `${field}: ${item.msg}`
|
||||
})
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
async function request(path, options = {}) {
|
||||
let response
|
||||
|
||||
try {
|
||||
response = await fetch(`${SETUP_API_BASE}${path}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers || {})
|
||||
},
|
||||
...options
|
||||
})
|
||||
} catch {
|
||||
throw new Error('无法连接初始化服务,请确认本地配置桥已启动。')
|
||||
}
|
||||
|
||||
let data = null
|
||||
|
||||
try {
|
||||
data = await response.json()
|
||||
} catch {
|
||||
data = null
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const validationMessage = formatValidationErrors(data?.detail)
|
||||
const message = validationMessage || data?.detail || '初始化请求失败,请稍后重试。'
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export function fetchBootstrapState() {
|
||||
return request('/bootstrap')
|
||||
}
|
||||
|
||||
export function saveBootstrapConfig(payload) {
|
||||
return request('/bootstrap', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
export function startBootstrapBackend() {
|
||||
return request('/bootstrap/backend', {
|
||||
method: 'POST'
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchBootstrapBackendStatus() {
|
||||
return request('/bootstrap/backend')
|
||||
}
|
||||
|
||||
export function testBootstrapRuntime(payload) {
|
||||
return request('/bootstrap/runtime', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
export function testBootstrapDatabase(payload) {
|
||||
return request('/bootstrap/database', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
export function loginBootstrapAdmin(payload) {
|
||||
return request('/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
33
web/src/services/knowledge.js
Normal file
33
web/src/services/knowledge.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { apiRequest } from './api.js'
|
||||
|
||||
export function fetchKnowledgeLibrary() {
|
||||
return apiRequest('/knowledge/library')
|
||||
}
|
||||
|
||||
export function fetchKnowledgeDocument(documentId) {
|
||||
return apiRequest(`/knowledge/documents/${documentId}`)
|
||||
}
|
||||
|
||||
export function uploadKnowledgeDocument({ folder, file }) {
|
||||
return apiRequest(
|
||||
`/knowledge/documents?folder=${encodeURIComponent(folder)}&filename=${encodeURIComponent(file.name)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: file,
|
||||
contentType: file.type || 'application/octet-stream'
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteKnowledgeDocument(documentId) {
|
||||
return apiRequest(`/knowledge/documents/${documentId}`, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchKnowledgeDocumentBlob(documentId, disposition = 'inline') {
|
||||
return apiRequest(`/knowledge/documents/${documentId}/content?disposition=${disposition}`, {
|
||||
responseType: 'blob',
|
||||
contentType: null
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user