第一次打包失败
This commit is contained in:
@@ -520,37 +520,146 @@ export const getWorkspaceFileURL = (token, workspacesId, path) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 上传文件到工作区(手机弃用,仅支持pc本地前缀)
|
||||
// export const workspaceUploadFile = (workspacesId,file,path) => {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// uni.request({
|
||||
// url: `${BASE_URL}/workspace/file/upload`,
|
||||
// method: "POST",
|
||||
// header: {
|
||||
// 'Content-Type': 'application/json'
|
||||
// },
|
||||
// data: {
|
||||
// workspaces_id: workspacesId,
|
||||
// file: file,
|
||||
// file_path: path,
|
||||
// overwrite: true
|
||||
// },
|
||||
// success: (res) => {
|
||||
// if(res.statusCode === 200){
|
||||
// const respond = res.data
|
||||
// if (respond.success) {
|
||||
// resolve(respond)Z
|
||||
// } else {
|
||||
// const msg = respond?.error || '上传文件到工作区出错啦'
|
||||
// reject(msg)
|
||||
// }
|
||||
// }else {
|
||||
// reject(`上传文件到工作区失败:${res.statusCode}`)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
// 上传文件(通过url)到工作区
|
||||
export const workspaceUploadFileByURL = (token, workspacesId, urls, dirPath) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// urls 支持字符串或数组
|
||||
const urlList = Array.isArray(urls) ? urls : (urls ? [urls] : []);
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/phone/workspace/upload`,
|
||||
method: "POST",
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: {
|
||||
"access_token": token,
|
||||
"workspaces_id": workspacesId,
|
||||
"dir_path": dirPath || '/',
|
||||
"urls": urlList
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
const respond = res.data;
|
||||
// 接口返回: { success, total_files, success_count, failed_count, results: [{ url, success, error }], summary }
|
||||
if (respond.success) {
|
||||
resolve(respond);
|
||||
} else {
|
||||
// 部分/全部失败时,收集失败信息
|
||||
const failedItems = (respond.results || [])
|
||||
.filter(r => !r.success)
|
||||
.map(r => r.error || '未知错误');
|
||||
const msg = failedItems.length > 0
|
||||
? `上传失败 ${respond.failed_count}/${respond.total_files}:${failedItems[0]}`
|
||||
: (respond.summary || respond?.error || '上传文件到工作区出错啦');
|
||||
reject(msg);
|
||||
}
|
||||
} else {
|
||||
reject(`上传文件到工作区失败:${res.statusCode}`);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
const msg = err.errMsg || '网络错误';
|
||||
reject(msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 上传文件(到短存云端)获取URL
|
||||
// files: 文件数组,每个元素为 { path, name } 或字符串路径
|
||||
// 返回格式: [{ url: "https://...", success: true }]
|
||||
export const uploadFileToShortStorage = (workspacesId, files, filePath) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 统一转为文件数组
|
||||
const fileList = Array.isArray(files) ? files : [files];
|
||||
|
||||
// 构建 files 数组供 uni.uploadFile 使用
|
||||
const uploadFiles = fileList.map((file) => {
|
||||
const fileUri = typeof file === 'string' ? file : (file.tempFilePath || file.path || file);
|
||||
return {
|
||||
name: 'files',
|
||||
uri: fileUri
|
||||
};
|
||||
});
|
||||
|
||||
console.log('uploadFileToShortStorage 参数:', { workspacesId, fileCount: uploadFiles.length, filePath });
|
||||
|
||||
uni.uploadFile({
|
||||
url: `${BASE_URL}/cloud_api/file/temp/upload`,
|
||||
method: "POST",
|
||||
formData: {
|
||||
workspaces_id: workspacesId,
|
||||
file_path: filePath || '/',
|
||||
overwrite: 'true'
|
||||
},
|
||||
files: uploadFiles,
|
||||
success: (res) => {
|
||||
console.log('uploadFileToShortStorage 响应状态:', res.statusCode, '数据:', res.data);
|
||||
if (res.statusCode === 200) {
|
||||
try {
|
||||
const respond = JSON.parse(res.data);
|
||||
// 接口返回 [{ url, success }] 数组
|
||||
if (Array.isArray(respond) && respond.length > 0) {
|
||||
// 返回完整的 results 数组,调用方可遍历
|
||||
resolve(respond);
|
||||
} else if (respond.success) {
|
||||
// 兼容 { success: true, url: "..." } 格式
|
||||
resolve([{ url: respond.url || respond.message, success: true }]);
|
||||
} else {
|
||||
const msg = respond?.error || respond?.message || '上传文件(到短存云端)获取URL出错啦';
|
||||
reject(msg);
|
||||
}
|
||||
} catch (e) {
|
||||
reject('接口返回数据格式异常: ' + res.data);
|
||||
}
|
||||
} else {
|
||||
reject(`上传文件(到短存云端)获取URL失败:${res.statusCode} - ${res.data}`);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
const msg = err.errMsg || '网络错误';
|
||||
reject(msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 重命名工作区文件/文件夹(电脑端)
|
||||
export const updateWorkspaceFileName = (token, workspacesId, oldPath, newName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${BASE_URL}/workspace/file/rename`,
|
||||
method: "POST",
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: {
|
||||
"workspaces_id": workspacesId,
|
||||
"file_path": oldPath,
|
||||
"new_name": newName
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
const respond = res.data;
|
||||
if (respond.success) {
|
||||
resolve(respond.message || respond);
|
||||
} else {
|
||||
const msg = respond?.error || '重命名工作区文件出错啦';
|
||||
reject(msg);
|
||||
}
|
||||
} else {
|
||||
reject(`重命名工作区文件失败:${res.statusCode}`);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
const msg = err.errMsg || '网络错误';
|
||||
reject(msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 上传用户头像
|
||||
export const uploadUserAvatar = (token, userId, username, email, avatarURL) => {
|
||||
@@ -1113,23 +1222,31 @@ export const createCloudDb = (token, databaseName) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 上传db
|
||||
export const uploadCloudDbFile = (token, file) => {
|
||||
// 上传db文件(.db / .sqlite 等数据库文件)
|
||||
export const uploadCloudDbFile = (token, filePath) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// filePath 可能是字符串路径或 { tempFilePath, name } 对象
|
||||
const fileUri = typeof filePath === 'string' ? filePath : (filePath.tempFilePath || filePath.path ||
|
||||
filePath);
|
||||
const fileName = typeof filePath === 'string' ?
|
||||
filePath.split('/').pop() || 'database.db' :
|
||||
(filePath.name || 'database.db');
|
||||
|
||||
uni.uploadFile({
|
||||
url: `${BASE_URL}/cloud_api/database/upload/db`,
|
||||
method: "POST",
|
||||
// 不要手动设置 Content-Type,浏览器自动生成 multipart/form-data
|
||||
header: {
|
||||
// 如果后端把token放header就写这里,放表单里就写到formData
|
||||
},
|
||||
// 普通文本参数(对应form-data里的文本项)
|
||||
header: {},
|
||||
formData: {
|
||||
access_token: token
|
||||
},
|
||||
// 多文件:每个文件name都叫files,和Postman保持一致
|
||||
file: files,
|
||||
file: {
|
||||
name: fileName,
|
||||
uri: fileUri
|
||||
},
|
||||
files: [{
|
||||
name: 'file',
|
||||
uri: fileUri
|
||||
}],
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
try {
|
||||
@@ -1168,7 +1285,7 @@ export const deleteCloudDb = (token, databaseId) => {
|
||||
},
|
||||
data: {
|
||||
"access_token": token,
|
||||
"database_id": databaseName
|
||||
"database_id": databaseId
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
@@ -1195,7 +1312,7 @@ export const deleteCloudDb = (token, databaseId) => {
|
||||
export const getCloudDbTables = (token, databaseId, isDetail) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/database/list`,
|
||||
url: `${BASE_URL}/cloud_api/database/tables`,
|
||||
method: "POST",
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -1226,16 +1343,54 @@ export const getCloudDbTables = (token, databaseId, isDetail) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 获取表数据
|
||||
export const getCloudDbTableData = (token, databaseId, tableName, limit = "20", offset = "0") => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/database/table/data`,
|
||||
method: "POST",
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: {
|
||||
"access_token": token,
|
||||
"database_id": databaseId,
|
||||
"table_name": tableName,
|
||||
"limit": limit,
|
||||
"offset": offset
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
const respond = res.data
|
||||
if (respond.success) {
|
||||
resolve(respond.data)
|
||||
} else {
|
||||
const msg = respond?.error || '获取表数据出错啦'
|
||||
reject(msg)
|
||||
}
|
||||
} else {
|
||||
reject(`获取表数据失败:${res.statusCode}`)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
const msg = err.errMsg || '网络错误'
|
||||
reject(msg)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 删除数据库中的表
|
||||
export const deleteCloudDbTable = async (token, databaseId, tableName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${BASE_URL}/delete_conversation`,
|
||||
url: `${BASE_URL}/cloud_api/database/table/drop`,
|
||||
method: "POST",
|
||||
data: {
|
||||
"access_token": token,
|
||||
"database_id": databaseId,
|
||||
"table_name": table_name
|
||||
"table_name": tableName
|
||||
},
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -1246,7 +1401,7 @@ export const deleteCloudDbTable = async (token, databaseId, tableName) => {
|
||||
if (respond?.success) {
|
||||
resolve(respond.message)
|
||||
} else {
|
||||
const msg = respond.failed_ids.error || '删除数据库中的表出错啦'
|
||||
const msg = respond.error || '删除数据库中的表出错啦'
|
||||
reject(msg)
|
||||
}
|
||||
} else {
|
||||
@@ -1262,7 +1417,7 @@ export const deleteCloudDbTable = async (token, databaseId, tableName) => {
|
||||
}
|
||||
|
||||
// 更新表数据
|
||||
export const updateCloudDbTableData = async (token, databaseId, tableName, whereData, updateData) => {
|
||||
export const updateCloudDbTableData = (token, databaseId, tableName, whereData, updateData) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/database/table/update/by/id`,
|
||||
@@ -1270,13 +1425,9 @@ export const updateCloudDbTableData = async (token, databaseId, tableName, where
|
||||
data: {
|
||||
"access_token": token,
|
||||
"database_id": databaseId,
|
||||
"table_name": table_name,
|
||||
"where_data": {
|
||||
"_row_id": 2
|
||||
},
|
||||
"update_data": {
|
||||
"问题": "《水土保持监理规范2344444》制定的目的是什么"
|
||||
}
|
||||
"table_name": tableName,
|
||||
"where_data": whereData,
|
||||
"update_data": updateData
|
||||
},
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -1287,7 +1438,7 @@ export const updateCloudDbTableData = async (token, databaseId, tableName, where
|
||||
if (respond?.success) {
|
||||
resolve(respond.message)
|
||||
} else {
|
||||
const msg = respond.failed_ids.error || '更新表数据出错啦'
|
||||
const msg = respond.error || '更新表数据出错啦'
|
||||
reject(msg)
|
||||
}
|
||||
} else {
|
||||
@@ -1304,24 +1455,35 @@ export const updateCloudDbTableData = async (token, databaseId, tableName, where
|
||||
|
||||
|
||||
// 导入文件到数据库
|
||||
export const importFileToCloudDb = (token, forceOverwrite, databaseId, file, tableName) => {
|
||||
export const importFileToCloudDb = (token, forceOverwrite, databaseId, filePath, tableName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// filePath 可能是字符串路径或 { tempFilePath, name } 对象
|
||||
const fileUri = typeof filePath === 'string' ? filePath : (filePath.tempFilePath || filePath.path ||
|
||||
filePath);
|
||||
const fileName = typeof filePath === 'string' ?
|
||||
filePath.split('/').pop() || 'file' :
|
||||
(filePath.name || 'file');
|
||||
|
||||
uni.uploadFile({
|
||||
url: `${BASE_URL}/cloud_api/file/upload`,
|
||||
url: `${BASE_URL}/cloud_api/database/import`,
|
||||
method: "POST",
|
||||
// 不要手动设置 Content-Type,浏览器自动生成 multipart/form-data
|
||||
header: {
|
||||
// 如果后端把token放header就写这里,放表单里就写到formData
|
||||
},
|
||||
// 普通文本参数(对应form-data里的文本项)
|
||||
header: {},
|
||||
formData: {
|
||||
access_token: token,
|
||||
force_overwrite: forceOverwrite,
|
||||
database_id: databaseId,
|
||||
team_id: teamIdStr,
|
||||
table_name: tableName
|
||||
},
|
||||
file: file,
|
||||
// uni.uploadFile 的 file 参数需要是对象格式:{ name, uri }
|
||||
file: {
|
||||
name: fileName,
|
||||
uri: fileUri
|
||||
},
|
||||
// 同时用 files 方式兜底
|
||||
files: [{
|
||||
name: 'file',
|
||||
uri: fileUri
|
||||
}],
|
||||
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
@@ -1349,18 +1511,23 @@ export const importFileToCloudDb = (token, forceOverwrite, databaseId, file, tab
|
||||
};
|
||||
|
||||
// 查看 个人/团队 数据库权限信息
|
||||
export const getCloudDbPermission = async (token, databaseId, type, Id) => {
|
||||
export const getCloudDbPermission = (token, databaseId, type, id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestData = {
|
||||
"access_token": token,
|
||||
"database_id": databaseId
|
||||
};
|
||||
// type 只能是 user_id 或 team_id
|
||||
if (type === 'user_id') {
|
||||
requestData.user_id = id;
|
||||
} else if (type === 'team_id') {
|
||||
requestData.team_id = id;
|
||||
}
|
||||
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/database/permission/info`,
|
||||
method: "POST",
|
||||
data: {
|
||||
"access_token": token,
|
||||
"database_id": databaseId,
|
||||
type: Id
|
||||
// "team_id": "6a02f6f0d99a03faefd1f437",
|
||||
// "user_id": "690c72a6b8ffa329af2d5607",
|
||||
},
|
||||
data: requestData,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -1368,9 +1535,13 @@ export const getCloudDbPermission = async (token, databaseId, type, Id) => {
|
||||
if (res.statusCode === 200) {
|
||||
const respond = res.data
|
||||
if (respond?.success) {
|
||||
resolve(respond.message)
|
||||
// team_id 格式: { success: true, data: [...] }
|
||||
resolve(respond.data)
|
||||
} else if (Array.isArray(respond)) {
|
||||
// user_id 格式: 直接返回数组 [...]
|
||||
resolve(respond)
|
||||
} else {
|
||||
const msg = respond.failed_ids.error || '查看 个人/团队 数据库权限信息出错啦'
|
||||
const msg = respond?.error || '查看 个人/团队 数据库权限信息出错啦'
|
||||
reject(msg)
|
||||
}
|
||||
} else {
|
||||
@@ -1386,18 +1557,22 @@ export const getCloudDbPermission = async (token, databaseId, type, Id) => {
|
||||
}
|
||||
|
||||
// 删除 团队/用户 对数据库权限
|
||||
export const deleteCloudDbPermission = async (token, databaseId, type, Id) => {
|
||||
export const deleteCloudDbPermission = (token, databaseId, type, id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestData = {
|
||||
"access_token": token,
|
||||
"database_id": databaseId
|
||||
};
|
||||
if (type === 'user_id') {
|
||||
requestData.user_id = id;
|
||||
} else if (type === 'team_id') {
|
||||
requestData.team_id = id;
|
||||
}
|
||||
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/database/permission/delete`,
|
||||
method: "POST",
|
||||
data: {
|
||||
"access_token": token,
|
||||
"database_id": databaseId,
|
||||
type: Id
|
||||
// "team_id": "6a02f6f0d99a03faefd1f437",
|
||||
// "user_id": "690c72a6b8ffa329af2d5607",
|
||||
},
|
||||
data: requestData,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -1407,7 +1582,7 @@ export const deleteCloudDbPermission = async (token, databaseId, type, Id) => {
|
||||
if (respond?.success) {
|
||||
resolve(respond.message)
|
||||
} else {
|
||||
const msg = respond.failed_ids.error || '删除 团队/用户 对数据库权限出错啦'
|
||||
const msg = respond.error || '删除 团队/用户 对数据库权限出错啦'
|
||||
reject(msg)
|
||||
}
|
||||
} else {
|
||||
@@ -1423,19 +1598,23 @@ export const deleteCloudDbPermission = async (token, databaseId, type, Id) => {
|
||||
}
|
||||
|
||||
// 修改/增加 团队/用户 对数据库权限
|
||||
export const updateCloudDbPermission = async (token, databaseId, type, Id, level) => {
|
||||
export const updateCloudDbPermission = (token, databaseId, type, id, level) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestData = {
|
||||
"access_token": token,
|
||||
"database_id": databaseId,
|
||||
"access_level": level
|
||||
};
|
||||
if (type === 'user_id') {
|
||||
requestData.user_id = id;
|
||||
} else if (type === 'team_id') {
|
||||
requestData.team_id = id;
|
||||
}
|
||||
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/database/permission/update`,
|
||||
method: "POST",
|
||||
data: {
|
||||
"access_token": token,
|
||||
"database_id": databaseId,
|
||||
"access_level": "3",
|
||||
type: Id,
|
||||
// "team_id": "6a02f6f0d99a03faefd1f437",
|
||||
// "user_id": "690c72a6b8ffa329af2d5607",
|
||||
},
|
||||
data: requestData,
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -1445,7 +1624,7 @@ export const updateCloudDbPermission = async (token, databaseId, type, Id, level
|
||||
if (respond?.success) {
|
||||
resolve(respond.message)
|
||||
} else {
|
||||
const msg = respond.failed_ids.error || '修改/增加 团队/用户 对数据库权限出错啦'
|
||||
const msg = respond.error || '修改/增加 团队/用户 对数据库权限出错啦'
|
||||
reject(msg)
|
||||
}
|
||||
} else {
|
||||
@@ -1461,7 +1640,7 @@ export const updateCloudDbPermission = async (token, databaseId, type, Id, level
|
||||
}
|
||||
|
||||
// 个人数据库移交团队
|
||||
export const dbTransferToTeam = async (token, databaseId,teamId) => {
|
||||
export const dbTransferToTeam = async (token, databaseId, teamId) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${BASE_URL}/cloud_api/database/transfer_to_team`,
|
||||
@@ -1480,7 +1659,7 @@ export const dbTransferToTeam = async (token, databaseId,teamId) => {
|
||||
if (respond?.success) {
|
||||
resolve(respond.message)
|
||||
} else {
|
||||
const msg = respond.failed_ids.error || '个人数据库移交团队出错啦'
|
||||
const msg = respond.error || '个人数据库移交团队出错啦'
|
||||
reject(msg)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user