49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
|
|
/**
|
||
|
|
* 知识库 API 服务
|
||
|
|
*/
|
||
|
|
|
||
|
|
import http from './http'
|
||
|
|
|
||
|
|
const knowledgeService = {
|
||
|
|
/**
|
||
|
|
* 上传 md 文件(单个或多个)
|
||
|
|
* @param {File[]} files - File 对象数组
|
||
|
|
*/
|
||
|
|
async uploadFiles(files) {
|
||
|
|
const formData = new FormData()
|
||
|
|
files.forEach(f => formData.append('files', f))
|
||
|
|
const resp = await http.post('/knowledge/upload', formData, {
|
||
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
||
|
|
})
|
||
|
|
return resp.data
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取知识库条目列表
|
||
|
|
* @param {string|null} sourceType - 可选,按 source_type 筛选
|
||
|
|
*/
|
||
|
|
async listItems(sourceType = null) {
|
||
|
|
const params = sourceType ? { source_type: sourceType } : {}
|
||
|
|
const resp = await http.get('/knowledge/items', { params })
|
||
|
|
return resp.data
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 删除知识库条目
|
||
|
|
* @param {number} id
|
||
|
|
*/
|
||
|
|
async deleteItem(id) {
|
||
|
|
const resp = await http.delete(`/knowledge/items/${id}`)
|
||
|
|
return resp.data
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取所有不重复的具体出处(供筛选下拉)
|
||
|
|
*/
|
||
|
|
async listSources() {
|
||
|
|
const resp = await http.get('/knowledge/sources')
|
||
|
|
return resp.data
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
export default knowledgeService
|