|
|
@@ -32,11 +32,13 @@ api.interceptors.response.use(
|
|
|
return Promise.reject(new Error(data.message || '请求失败'))
|
|
|
},
|
|
|
error => {
|
|
|
- if (error.response?.status === 401) {
|
|
|
+ if (error.response?.status === 401 || error.response?.status === 403) {
|
|
|
localStorage.removeItem('accessToken')
|
|
|
localStorage.removeItem('refreshToken')
|
|
|
localStorage.removeItem('username')
|
|
|
- window.location.href = '/login'
|
|
|
+ if (!window.location.pathname.includes('/login')) {
|
|
|
+ window.location.href = '/login'
|
|
|
+ }
|
|
|
}
|
|
|
const msg = error.response?.data?.message || error.message || '网络错误'
|
|
|
return Promise.reject(new Error(msg))
|
|
|
@@ -104,6 +106,10 @@ export const projectApi = {
|
|
|
|
|
|
export(id) {
|
|
|
return api.get(`/projects/${id}/export`, { responseType: 'blob' })
|
|
|
+ },
|
|
|
+
|
|
|
+ getDocContent(id) {
|
|
|
+ return api.get(`/projects/${id}/doc-content`)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -177,36 +183,29 @@ export const attachmentApi = {
|
|
|
return api.post(`/attachments/${attachmentId}/parse`)
|
|
|
},
|
|
|
|
|
|
- sort(projectId, orderedIds) {
|
|
|
- return api.put(`/projects/${projectId}/attachments/sort`, orderedIds)
|
|
|
+ saveParsedContent(attachmentId, parsedText) {
|
|
|
+ return api.put(`/attachments/${attachmentId}/parsed-content`, { parsedText })
|
|
|
},
|
|
|
|
|
|
- getDocContent(attachmentId) {
|
|
|
- return api.get(`/attachments/${attachmentId}/doc-content`)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// ==================== 实体 API ====================
|
|
|
-
|
|
|
-export const entityApi = {
|
|
|
- listByAttachment(attachmentId) {
|
|
|
- return api.get(`/attachments/${attachmentId}/entities`)
|
|
|
+ getParsedText(attachmentId) {
|
|
|
+ return api.get(`/attachments/${attachmentId}/parsed-text`)
|
|
|
},
|
|
|
|
|
|
- listByProject(projectId) {
|
|
|
- return api.get(`/projects/${projectId}/entities`)
|
|
|
- },
|
|
|
-
|
|
|
- getById(entityId) {
|
|
|
- return api.get(`/entities/${entityId}`)
|
|
|
+ parseDocx(file) {
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', file)
|
|
|
+ return api.post('/tools/parse-docx', formData, {
|
|
|
+ headers: { 'Content-Type': 'multipart/form-data' },
|
|
|
+ timeout: 120000
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- update(entityId, data) {
|
|
|
- return api.put(`/entities/${entityId}`, data)
|
|
|
+ sort(projectId, orderedIds) {
|
|
|
+ return api.put(`/projects/${projectId}/attachments/sort`, orderedIds)
|
|
|
},
|
|
|
|
|
|
- merge(targetId, sourceIds) {
|
|
|
- return api.post(`/entities/${targetId}/merge`, sourceIds)
|
|
|
+ getDocContent(attachmentId) {
|
|
|
+ return api.get(`/attachments/${attachmentId}/doc-content`)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -326,4 +325,51 @@ export const aiApi = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ==================== PDF 解析 API (外部服务) ====================
|
|
|
+
|
|
|
+const parseService = axios.create({
|
|
|
+ baseURL: 'http://47.108.80.98:4214',
|
|
|
+ timeout: 120000
|
|
|
+})
|
|
|
+
|
|
|
+export const parseApi = {
|
|
|
+ // 提交 PDF/图片解析任务
|
|
|
+ submit(file, options = {}) {
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', file)
|
|
|
+ if (options.backend) formData.append('backend', options.backend)
|
|
|
+ if (options.remove_watermark) formData.append('remove_watermark', 'true')
|
|
|
+ if (options.crop_header_footer) formData.append('crop_header_footer', 'true')
|
|
|
+ if (options.return_images) formData.append('return_images', 'true')
|
|
|
+ return parseService.post('/pdf_to_markdown', formData, {
|
|
|
+ headers: { 'Content-Type': 'multipart/form-data' }
|
|
|
+ }).then(r => r.data)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 查询任务状态
|
|
|
+ getStatus(taskId) {
|
|
|
+ return parseService.get(`/task/${taskId}`).then(r => r.data)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取解析结果 JSON { markdown, filename }
|
|
|
+ getResult(taskId) {
|
|
|
+ return parseService.get(`/task/${taskId}/json`).then(r => r.data)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 下载 markdown 文件
|
|
|
+ downloadMarkdown(taskId) {
|
|
|
+ return parseService.get(`/download/${taskId}/markdown`, { responseType: 'blob' }).then(r => r.data)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 下载 zip 包(markdown + 图片)
|
|
|
+ downloadZip(taskId) {
|
|
|
+ return parseService.get(`/download/${taskId}/zip`, { responseType: 'blob' }).then(r => r.data)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取解析任务的图片 URL 基础路径
|
|
|
+ getImageBaseUrl(taskId) {
|
|
|
+ return `http://47.108.80.98:4214/download/${taskId}/images`
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export default api
|