清理/jingrow/开头的无效api
This commit is contained in:
parent
d3b7cdb229
commit
59041b57d0
@ -51,37 +51,7 @@ export const loginApi = async (username: string, password: string): Promise<void
|
||||
// 登录状态通过 cookie 判断
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
export const getUserInfoApi = async (): Promise<UserInfo> => {
|
||||
const response = await fetch(`/jingrow/user-info`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'include'
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
// 401或403表示cookie过期或未授权
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
const error = new Error('Cookie已过期,请重新登录')
|
||||
// @ts-ignore
|
||||
error.status = response.status
|
||||
throw error
|
||||
}
|
||||
const errorData = await response.json().catch(() => ({}))
|
||||
throw new Error(errorData.detail || errorData.message || '获取用户信息失败')
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success && data.user_info) {
|
||||
return data.user_info
|
||||
} else {
|
||||
throw new Error(data.message || data.detail || '获取用户信息失败')
|
||||
}
|
||||
}
|
||||
// 获取用户信息 - 已删除,使用 cookie 中的 user_id 判断登录状态
|
||||
|
||||
// 登出
|
||||
export const logoutApi = async (): Promise<void> => {
|
||||
@ -100,83 +70,7 @@ export const logoutApi = async (): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
// 注册接口
|
||||
export interface SignupRequest {
|
||||
username: string
|
||||
password: string
|
||||
email?: string
|
||||
phone_number?: string
|
||||
}
|
||||
|
||||
export interface SignupResponse {
|
||||
success: boolean
|
||||
message?: string
|
||||
error?: string
|
||||
user?: UserInfo
|
||||
}
|
||||
|
||||
export const signupApi = async (data: SignupRequest): Promise<SignupResponse> => {
|
||||
try {
|
||||
const response = await fetch(`/jingrow/signup`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
|
||||
// 先克隆响应,以便可以多次读取(如果需要)
|
||||
const responseClone = response.clone()
|
||||
|
||||
let result: any = {}
|
||||
|
||||
// 尝试解析响应体
|
||||
try {
|
||||
result = await response.json()
|
||||
} catch (e) {
|
||||
// 如果JSON解析失败,尝试读取文本
|
||||
try {
|
||||
const text = await responseClone.text()
|
||||
return {
|
||||
success: false,
|
||||
error: text || `注册请求失败 (HTTP ${response.status})`
|
||||
}
|
||||
} catch (textError) {
|
||||
return {
|
||||
success: false,
|
||||
error: `注册请求失败 (HTTP ${response.status})`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果响应不成功,提取错误消息
|
||||
if (!response.ok) {
|
||||
// FastAPI HTTPException 返回格式: {"detail": "错误消息"}
|
||||
const errorMsg = result.detail || `注册请求失败 (HTTP ${response.status})`
|
||||
return { success: false, error: errorMsg }
|
||||
}
|
||||
|
||||
// 检查业务逻辑错误(success 为 false)
|
||||
if (result.success === false) {
|
||||
const errorMsg = result.error || result.message || '注册失败'
|
||||
return { success: false, error: errorMsg }
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: result.message || '注册成功',
|
||||
user: result.user || undefined
|
||||
}
|
||||
} catch (error: any) {
|
||||
// 处理网络错误或其他异常
|
||||
return {
|
||||
success: false,
|
||||
error: error.message || '网络错误,请检查网络连接后重试'
|
||||
}
|
||||
}
|
||||
}
|
||||
// 注册接口 - 已删除,/jingrow/signup API 无效
|
||||
|
||||
// 仅使用会话Cookie的最小鉴权头部(不影响现有API Key逻辑)
|
||||
export function get_session_api_headers() {
|
||||
|
||||
@ -3,37 +3,10 @@ import { get_session_api_headers } from './auth'
|
||||
|
||||
// 统一使用相对路径,通过 Vite 代理转发到后端
|
||||
|
||||
// 删除记录的通用函数
|
||||
// 删除记录的通用函数 - /jingrow/bulk-delete API 已删除
|
||||
export const deleteRecords = async (pagetype: string, names: string[]): Promise<{ success: boolean; message?: string }> => {
|
||||
try {
|
||||
if (!names || names.length === 0) {
|
||||
return { success: false, message: '未提供要删除的记录' }
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`/jingrow/bulk-delete`,
|
||||
{
|
||||
pagetype: pagetype,
|
||||
names: names
|
||||
},
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true,
|
||||
validateStatus: (status) => status === 200 || status === 207 // 允许207状态码
|
||||
}
|
||||
)
|
||||
|
||||
const result = response.data
|
||||
// 207 状态码表示部分成功
|
||||
const isPartialSuccess = response.status === 207
|
||||
|
||||
return {
|
||||
success: !isPartialSuccess,
|
||||
message: result?.message || (isPartialSuccess ? '部分删除成功' : '删除完成')
|
||||
}
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.response?.data?.detail || error.message || '删除失败' }
|
||||
}
|
||||
// 批量删除功能已移除,/jingrow/bulk-delete API 无效
|
||||
return { success: false, message: '批量删除功能已移除' }
|
||||
}
|
||||
|
||||
// 创建记录的通用函数
|
||||
@ -113,40 +86,15 @@ export const getRecordAttachments = async (pagetype: string, name: string): Prom
|
||||
}
|
||||
}
|
||||
|
||||
// 上传附件
|
||||
// 上传附件 - /jingrow/upload_file API 已删除
|
||||
export const uploadAttachment = async (
|
||||
file: File,
|
||||
pagetype: string,
|
||||
docname: string,
|
||||
isPrivate: boolean = false
|
||||
): Promise<{ success: boolean; data?: any; message?: string }> => {
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('pagetype', pagetype)
|
||||
formData.append('docname', docname)
|
||||
formData.append('is_private', isPrivate ? '1' : '0')
|
||||
formData.append('folder', 'Home')
|
||||
|
||||
const response = await axios.post(
|
||||
`/jingrow/upload_file`,
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
...get_session_api_headers(),
|
||||
'Content-Type': 'multipart/form-data'
|
||||
},
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
return { success: true, data: response.data.message }
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || '上传附件失败'
|
||||
}
|
||||
}
|
||||
// 上传附件功能已移除,/jingrow/upload_file API 无效
|
||||
return { success: false, message: '上传附件功能已移除' }
|
||||
}
|
||||
|
||||
// 删除附件
|
||||
@ -170,56 +118,22 @@ export const getWorkspace = async (name: string): Promise<{ success: boolean; da
|
||||
return getRecord('Workspace', name)
|
||||
}
|
||||
|
||||
// 获取记录总数的通用函数
|
||||
// 获取记录总数的通用函数 - /jingrow/get-count API 已删除
|
||||
export const getCount = async (pagetype: string): Promise<{ success: boolean; count?: number; message?: string }> => {
|
||||
// 获取记录总数功能已移除,/jingrow/get-count API 无效
|
||||
// 可以通过 getRecords 获取总数
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`/jingrow/get-count`,
|
||||
null,
|
||||
{
|
||||
params: {
|
||||
pagetype: pagetype
|
||||
},
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
const count = response.data?.message
|
||||
return { success: true, count: count || 0 }
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
count: 0,
|
||||
message: error.response?.data?.detail || error.response?.data?.message || error.message || '获取记录总数失败'
|
||||
}
|
||||
const result = await getRecords(pagetype, [], [], 'modified desc', 0, 1)
|
||||
return { success: true, count: result.total || 0 }
|
||||
} catch {
|
||||
return { success: false, count: 0, message: '获取记录总数失败' }
|
||||
}
|
||||
}
|
||||
|
||||
// 获取Local Job总数的专用函数 - 通过专用端点获取
|
||||
// 获取Local Job总数的专用函数 - /jingrow/local-job-count API 已删除
|
||||
export const getLocalJobCount = async (): Promise<{ success: boolean; count?: number; message?: string }> => {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`/jingrow/local-job-count`,
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
const count = response.data?.count || 0
|
||||
return {
|
||||
success: true,
|
||||
count: count,
|
||||
message: '获取Local Job总数成功'
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
count: 0,
|
||||
message: error.response?.data?.detail || error.response?.data?.message || error.message || '获取Local Job总数失败'
|
||||
}
|
||||
}
|
||||
// 通过 getRecords 获取 Local Job 总数
|
||||
return getCount('Local Job')
|
||||
}
|
||||
|
||||
// 获取记录列表的通用函数
|
||||
@ -297,75 +211,14 @@ export const downloadImageToLocal = async (
|
||||
}
|
||||
}
|
||||
|
||||
// 上传文件到 Jingrow 服务器
|
||||
// 上传文件到 Jingrow 服务器 - /jingrow/upload_file API 已删除
|
||||
export const uploadFileToJingrow = async (
|
||||
file: File,
|
||||
attachedToPagetype?: string,
|
||||
attachedToName?: string,
|
||||
attachedToField?: string
|
||||
): Promise<{ success: boolean; file_url?: string; file_name?: string; local_path?: string; error?: string }> => {
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
formData.append('file_name', file.name)
|
||||
formData.append('is_private', '0')
|
||||
|
||||
// 如果有关联记录,添加到请求数据中
|
||||
if (attachedToPagetype && attachedToName) {
|
||||
formData.append('pagetype', attachedToPagetype)
|
||||
formData.append('docname', attachedToName)
|
||||
}
|
||||
|
||||
if (attachedToField) {
|
||||
formData.append('fieldname', attachedToField)
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`/jingrow/upload_file`,
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
...get_session_api_headers(),
|
||||
'Content-Type': 'multipart/form-data'
|
||||
},
|
||||
withCredentials: true,
|
||||
timeout: 30000
|
||||
}
|
||||
)
|
||||
|
||||
if (response.status === 200) {
|
||||
const result = response.data
|
||||
|
||||
// 检查session是否过期
|
||||
if (result.session_expired) {
|
||||
return { success: false, error: 'Session已过期,请重新登录' }
|
||||
}
|
||||
|
||||
if (result.message) {
|
||||
const uploadResult: { success: boolean; file_url: string; file_name: string; local_path?: string } = {
|
||||
success: true,
|
||||
file_url: result.message.file_url,
|
||||
file_name: result.message.file_name
|
||||
}
|
||||
|
||||
// 上传成功后,自动下载图片到本地
|
||||
const downloadResult = await downloadImageToLocal(result.message.file_url, result.message.file_name)
|
||||
if (downloadResult.success) {
|
||||
uploadResult.local_path = downloadResult.local_path
|
||||
}
|
||||
|
||||
return uploadResult
|
||||
} else {
|
||||
return { success: false, error: 'API响应格式错误' }
|
||||
}
|
||||
} else {
|
||||
return { success: false, error: `API请求失败 (HTTP ${response.status}): ${response.statusText}` }
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.response?.data?.message || error.message || '上传文件失败'
|
||||
}
|
||||
}
|
||||
// 上传文件功能已移除,/jingrow/upload_file API 无效
|
||||
return { success: false, error: '上传文件功能已移除' }
|
||||
}
|
||||
|
||||
|
||||
@ -1,63 +1,26 @@
|
||||
import axios from 'axios'
|
||||
import { get_session_api_headers } from './auth'
|
||||
|
||||
// 内部函数:调用文本转向量API
|
||||
// 内部函数:调用文本转向量API - /jingrow/embedding/batch API 已删除
|
||||
const callEmbeddingApi = async (texts: string[]) => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`/jingrow/embedding/batch`,
|
||||
{ texts },
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: response.data?.data || []
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('调用 Embedding API 异常:', error)
|
||||
console.warn('callEmbeddingApi: /jingrow/embedding/batch API 已删除')
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.detail || error.message || '调用API失败'
|
||||
}
|
||||
message: 'Embedding API 已移除'
|
||||
}
|
||||
}
|
||||
|
||||
// 内部函数:向量搜索
|
||||
// 内部函数:向量搜索 - /jingrow/embedding/search API 已删除
|
||||
const searchVectors = async (
|
||||
queryVector: number[],
|
||||
collectionName: string = 'knowledge_base',
|
||||
limit: number = 10,
|
||||
scoreThreshold: number = 0.7
|
||||
) => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`/jingrow/embedding/search`,
|
||||
{
|
||||
collection_name: collectionName,
|
||||
query_vector: queryVector,
|
||||
limit,
|
||||
score_threshold: scoreThreshold
|
||||
},
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: response.data?.data || []
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('向量搜索失败:', error)
|
||||
console.warn('searchVectors: /jingrow/embedding/search API 已删除')
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.detail || error.message || '搜索失败'
|
||||
}
|
||||
message: '向量搜索 API 已移除'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,75 +3,27 @@ import { get_session_api_headers } from './auth'
|
||||
|
||||
// 统一使用相对路径,通过 Vite 代理转发到后端
|
||||
|
||||
// 获取节点Schema字段
|
||||
// 所有 /jingrow/node/* API 已删除,以下函数已失效
|
||||
|
||||
// 获取节点Schema字段 - /jingrow/node/schema-fields API 已删除
|
||||
export const getNodeSchemaFields = async (nodeType: string): Promise<any[]> => {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`/jingrow/node/schema-fields/${encodeURIComponent(nodeType)}`,
|
||||
{ headers: get_session_api_headers(), withCredentials: true }
|
||||
)
|
||||
return response.data?.fields || []
|
||||
} catch (error) {
|
||||
console.error('获取节点Schema字段失败:', error)
|
||||
console.warn('getNodeSchemaFields: /jingrow/node/schema-fields API 已删除')
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 一键导入本地节点(由后端扫描并创建)
|
||||
// 一键导入本地节点 - /jingrow/node/import-local API 已删除
|
||||
export const importLocalNodes = async (): Promise<{ success: boolean; matched: number; imported: number; skipped_existing: number; errors?: string[] }> => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`/jingrow/node/import-local`,
|
||||
{},
|
||||
{ headers: get_session_api_headers(), withCredentials: true }
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.error('导入本地节点失败:', error)
|
||||
throw error
|
||||
}
|
||||
console.warn('importLocalNodes: /jingrow/node/import-local API 已删除')
|
||||
throw new Error('导入本地节点功能已移除')
|
||||
}
|
||||
|
||||
// 打包节点为zip文件
|
||||
// 打包节点为zip文件 - /jingrow/node/package API 已删除
|
||||
export const packageNode = async (nodeType: string): Promise<{ blob: Blob; filename: string }> => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`/jingrow/node/package/${encodeURIComponent(nodeType)}`,
|
||||
{},
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true,
|
||||
responseType: 'blob'
|
||||
}
|
||||
)
|
||||
|
||||
// 从 Content-Disposition header 中提取文件名
|
||||
let filename = `${nodeType}.zip`
|
||||
const contentDisposition = response.headers['content-disposition']
|
||||
if (contentDisposition) {
|
||||
const filenameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/)
|
||||
if (filenameMatch && filenameMatch[1]) {
|
||||
filename = filenameMatch[1].replace(/['"]/g, '')
|
||||
// 处理 URL 编码的文件名
|
||||
try {
|
||||
filename = decodeURIComponent(filename)
|
||||
} catch {
|
||||
// 如果解码失败,使用原始值
|
||||
}
|
||||
}
|
||||
console.warn('packageNode: /jingrow/node/package API 已删除')
|
||||
throw new Error('打包节点功能已移除')
|
||||
}
|
||||
|
||||
return {
|
||||
blob: response.data,
|
||||
filename
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('打包节点失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 发布节点到节点市场
|
||||
// 发布节点到节点市场 - /jingrow/node/publish API 已删除
|
||||
export const publishNodeToMarketplace = async (data: {
|
||||
node_type: string
|
||||
title: string
|
||||
@ -81,31 +33,7 @@ export const publishNodeToMarketplace = async (data: {
|
||||
repository_url?: string
|
||||
node_image?: string
|
||||
}): Promise<{ success: boolean; message?: string }> => {
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('node_type', data.node_type)
|
||||
formData.append('title', data.title)
|
||||
if (data.subtitle) formData.append('subtitle', data.subtitle)
|
||||
if (data.description) formData.append('description', data.description)
|
||||
formData.append('file_url', data.file_url)
|
||||
if (data.repository_url) formData.append('repository_url', data.repository_url)
|
||||
if (data.node_image) formData.append('node_image', data.node_image)
|
||||
|
||||
const response = await axios.post(
|
||||
`/jingrow/node/publish`,
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
...get_session_api_headers(),
|
||||
'Content-Type': 'multipart/form-data'
|
||||
},
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
return response.data
|
||||
} catch (error: any) {
|
||||
console.error('发布节点失败:', error)
|
||||
throw error
|
||||
}
|
||||
console.warn('publishNodeToMarketplace: /jingrow/node/publish API 已删除')
|
||||
return { success: false, message: '发布节点功能已移除' }
|
||||
}
|
||||
|
||||
|
||||
@ -1,110 +0,0 @@
|
||||
import axios from 'axios'
|
||||
import { get_session_api_headers } from './auth'
|
||||
|
||||
export interface EnvironmentConfig {
|
||||
jingrow_server_url: string
|
||||
jingrow_api_key: string
|
||||
jingrow_api_secret: string
|
||||
jingrow_cloud_url: string
|
||||
jingrow_cloud_api_url: string
|
||||
jingrow_cloud_api_key: string
|
||||
jingrow_cloud_api_secret: string
|
||||
jingrow_db_host: string
|
||||
jingrow_db_port: string
|
||||
jingrow_db_name: string
|
||||
jingrow_db_user: string
|
||||
jingrow_db_password: string
|
||||
jingrow_db_type: string
|
||||
qdrant_host: string
|
||||
qdrant_port: number
|
||||
run_mode: string
|
||||
environment: string
|
||||
log_level: string
|
||||
backend_host: string
|
||||
backend_port: number
|
||||
backend_reload: boolean
|
||||
worker_processes: number
|
||||
worker_threads: number
|
||||
watch: boolean
|
||||
}
|
||||
|
||||
// 获取环境配置
|
||||
export const getEnvironmentConfig = async (): Promise<{ success: boolean; data?: EnvironmentConfig; message?: string }> => {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`/jingrow/system/environment-config`,
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
if (response.data?.success) {
|
||||
return { success: true, data: response.data.data }
|
||||
}
|
||||
return { success: false, message: response.data?.message || '获取环境配置失败' }
|
||||
} catch (error: any) {
|
||||
if (error.response?.status === 403) {
|
||||
return { success: false, message: '仅系统管理员可以访问此功能' }
|
||||
}
|
||||
if (error.response?.status === 401) {
|
||||
return { success: false, message: '认证失败,请重新登录' }
|
||||
}
|
||||
return { success: false, message: error.response?.data?.detail || error.message || '获取环境配置失败' }
|
||||
}
|
||||
}
|
||||
|
||||
// 更新环境配置
|
||||
export const updateEnvironmentConfig = async (config: Partial<EnvironmentConfig>): Promise<{ success: boolean; message?: string }> => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`/jingrow/system/environment-config`,
|
||||
config,
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
if (response.data?.success) {
|
||||
return { success: true, message: response.data.message || '环境配置已更新' }
|
||||
}
|
||||
return { success: false, message: response.data?.message || '更新环境配置失败' }
|
||||
} catch (error: any) {
|
||||
if (error.response?.status === 403) {
|
||||
return { success: false, message: '仅系统管理员可以访问此功能' }
|
||||
}
|
||||
if (error.response?.status === 401) {
|
||||
return { success: false, message: '认证失败,请重新登录' }
|
||||
}
|
||||
return { success: false, message: error.response?.data?.detail || error.message || '更新环境配置失败' }
|
||||
}
|
||||
}
|
||||
|
||||
// 重启环境
|
||||
export const restartEnvironment = async (): Promise<{ success: boolean; message?: string }> => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`/jingrow/system/restart-environment`,
|
||||
{},
|
||||
{
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
|
||||
if (response.data?.success) {
|
||||
return { success: true, message: response.data.message || '环境重启请求已提交' }
|
||||
}
|
||||
return { success: false, message: response.data?.message || '重启环境失败' }
|
||||
} catch (error: any) {
|
||||
if (error.response?.status === 403) {
|
||||
return { success: false, message: '仅系统管理员可以访问此功能' }
|
||||
}
|
||||
if (error.response?.status === 401) {
|
||||
return { success: false, message: '认证失败,请重新登录' }
|
||||
}
|
||||
return { success: false, message: error.response?.data?.detail || error.message || '重启环境失败' }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import router from '../../app/router'
|
||||
import { loginApi, getUserInfoApi, logoutApi, isCookieExpired } from '../api/auth'
|
||||
import { loginApi, logoutApi } from '../api/auth'
|
||||
|
||||
export interface User {
|
||||
id: string
|
||||
@ -123,17 +123,14 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
}
|
||||
|
||||
const updateUserInfo = async () => {
|
||||
if (!isLoggedIn.value) return
|
||||
|
||||
// 用户信息从 cookie 获取,不需要更新
|
||||
// 如果需要更新,可以从 localStorage 读取
|
||||
const savedUser = localStorage.getItem('jingrow_user')
|
||||
if (savedUser) {
|
||||
try {
|
||||
const userInfo = await getUserInfoApi()
|
||||
user.value = userInfo
|
||||
localStorage.setItem('jingrow_user', JSON.stringify(userInfo))
|
||||
} catch (error: any) {
|
||||
console.error('更新用户信息失败:', error)
|
||||
// 如果是401/403错误,说明cookie已过期
|
||||
if (error.status === 401 || error.status === 403 || error.message?.includes('过期')) {
|
||||
await logout()
|
||||
user.value = JSON.parse(savedUser)
|
||||
} catch {
|
||||
// 解析失败,忽略
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,23 +133,8 @@ onMounted(async () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查服务器配置,判断是否显示注册链接
|
||||
try {
|
||||
const response = await fetch('/jingrow/server-config')
|
||||
if (response.ok) {
|
||||
// 检查 Content-Type 是否为 JSON
|
||||
const contentType = response.headers.get('content-type')
|
||||
if (contentType && contentType.includes('application/json')) {
|
||||
const data = await response.json()
|
||||
if (data.success && data.jingrow_server_url === 'https://cloud.jingrow.com') {
|
||||
showSignupLink.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// 静默处理错误,不影响登录流程
|
||||
// console.error('Failed to get server config:', error)
|
||||
}
|
||||
// 服务器配置检查已移除,/jingrow/server-config API 无效
|
||||
// 默认不显示注册链接
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@ -113,7 +113,7 @@ import { NForm, NFormItem, NInput, NButton, NText, useMessage } from 'naive-ui'
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { useAuthStore } from '../../shared/stores/auth'
|
||||
import { t, getCurrentLocale } from '../../shared/i18n'
|
||||
import { signupApi } from '../../shared/api/auth'
|
||||
// signupApi 已删除,/jingrow/signup API 无效
|
||||
|
||||
const router = useRouter()
|
||||
const message = useMessage()
|
||||
@ -218,12 +218,17 @@ const handleSignup = async () => {
|
||||
await formRef.value?.validate()
|
||||
loading.value = true
|
||||
|
||||
// signupApi 已删除,/jingrow/signup API 无效
|
||||
message.error(t('注册功能已移除,/jingrow/signup API 无效'))
|
||||
return
|
||||
/* 原代码已删除
|
||||
const result = await signupApi({
|
||||
username: formData.username,
|
||||
password: formData.password,
|
||||
email: formData.email || undefined,
|
||||
phone_number: isEnglish.value ? (formData.phoneNumber || undefined) : formData.phoneNumber
|
||||
})
|
||||
*/
|
||||
|
||||
if (result.success) {
|
||||
message.success(t('Sign up successful'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user