107 lines
2.1 KiB
JavaScript
107 lines
2.1 KiB
JavaScript
|
|
/**
|
|||
|
|
* 文件系统相关 API
|
|||
|
|
*/
|
|||
|
|
import request from '@/utils/request'
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取项目目录树
|
|||
|
|
*/
|
|||
|
|
export function getProjectTree(projectId) {
|
|||
|
|
return request({
|
|||
|
|
url: `/files/${projectId}/tree`,
|
|||
|
|
method: 'get',
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取文件内容
|
|||
|
|
*/
|
|||
|
|
export function getFileContent(projectId, path) {
|
|||
|
|
// 直接在 URL 中拼接参数,避免 axios 自动编码
|
|||
|
|
// 手动编码一次,确保不会双重编码
|
|||
|
|
const encodedPath = encodeURIComponent(path)
|
|||
|
|
|
|||
|
|
return request({
|
|||
|
|
url: `/files/${projectId}/file?path=${encodedPath}`,
|
|||
|
|
method: 'get',
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 保存文件内容
|
|||
|
|
*/
|
|||
|
|
export function saveFile(projectId, data) {
|
|||
|
|
return request({
|
|||
|
|
url: `/files/${projectId}/file`,
|
|||
|
|
method: 'post',
|
|||
|
|
data,
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 文件操作(重命名/删除/创建)
|
|||
|
|
*/
|
|||
|
|
export function operateFile(projectId, data) {
|
|||
|
|
return request({
|
|||
|
|
url: `/files/${projectId}/file/operate`,
|
|||
|
|
method: 'post',
|
|||
|
|
data,
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 上传文件
|
|||
|
|
*/
|
|||
|
|
export function uploadFile(projectId, file, subfolder = 'images') {
|
|||
|
|
const formData = new FormData()
|
|||
|
|
formData.append('file', file)
|
|||
|
|
|
|||
|
|
return request({
|
|||
|
|
url: `/files/${projectId}/upload?subfolder=${subfolder}`,
|
|||
|
|
method: 'post',
|
|||
|
|
data: formData,
|
|||
|
|
headers: {
|
|||
|
|
'Content-Type': 'multipart/form-data',
|
|||
|
|
},
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取资源文件 URL(公开访问,支持分享)
|
|||
|
|
*/
|
|||
|
|
export function getAssetUrl(projectId, subfolder, filename) {
|
|||
|
|
return `/api/v1/files/${projectId}/assets/${subfolder}/${filename}`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 批量导入Markdown文档
|
|||
|
|
*/
|
|||
|
|
export function importDocuments(projectId, files, targetPath = '') {
|
|||
|
|
const formData = new FormData()
|
|||
|
|
files.forEach((file) => {
|
|||
|
|
formData.append('files', file)
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
return request({
|
|||
|
|
url: `/files/${projectId}/import-documents?target_path=${targetPath}`,
|
|||
|
|
method: 'post',
|
|||
|
|
data: formData,
|
|||
|
|
headers: {
|
|||
|
|
'Content-Type': 'multipart/form-data',
|
|||
|
|
},
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 导出目录为ZIP
|
|||
|
|
*/
|
|||
|
|
export function exportDirectory(projectId, directoryPath = '') {
|
|||
|
|
return request({
|
|||
|
|
url: `/files/${projectId}/export-directory`,
|
|||
|
|
method: 'get',
|
|||
|
|
params: { directory_path: directoryPath },
|
|||
|
|
responseType: 'blob',
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|