FastGPT
FastGPT copied to clipboard
批量启用禁用数据集
例行检查
- [x] 我已确认目前没有类似 features
- [x] 我已确认我已升级到最新版本
- [x] 我已完整查看过项目 README,已确定现有版本无法满足需求
- [x] 我理解并愿意跟进此 features,协助测试和提供反馈
- [x] 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 features 可能会被无视或直接关闭
功能描述 批量启用禁用数据集
应用场景 方便不用一个按钮按钮点
相关示例
写了个在控制台可执行的脚本方便一键禁用某个文件夹内的文件
// 获取当前页面的URL参数
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
// 从当前URL中提取datasetId和parentId
const datasetId = getQueryParam('datasetId');
const parentId = getQueryParam('parentId');
// 获取总页数
let totalPages = 1;
// 发送请求获取数据
function fetchPageData(pageNum) {
return fetch("/api/core/dataset/collection/list", {
"headers": {
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"content-type": "application/json",
"priority": "u=1, i",
"sec-ch-ua": "\"Not)A;Brand\";v=\"99\", \"Microsoft Edge\";v=\"127\", \"Chromium\";v=\"127\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrer": window.location.href,
"referrerPolicy": "strict-origin-when-cross-origin",
"body": JSON.stringify({
"pageNum": pageNum,
"pageSize": 30,
"datasetId": datasetId,
"parentId": parentId,
"searchText": "",
"filterTags": []
}),
"method": "POST",
"mode": "cors",
"credentials": "include"
}).then(response => response.json());
}
// 更新文件状态
function updateFileStatus(fileId) {
return fetch("/api/core/dataset/collection/update", {
"headers": {
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"content-type": "application/json",
"priority": "u=1, i",
"sec-ch-ua": "\"Not)A;Brand\";v=\"99\", \"Microsoft Edge\";v=\"127\", \"Chromium\";v=\"127\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrer": window.location.href,
"referrerPolicy": "strict-origin-when-cross-origin",
"body": JSON.stringify({
"id": fileId,
"forbid": true
}),
"method": "POST",
"mode": "cors",
"credentials": "include"
});
}
// 处理所有页面的数据
async function processAllPages() {
for (let pageNum = 1; pageNum <= totalPages; pageNum++) {
const data = await fetchPageData(pageNum);
totalPages = Math.ceil(data.data.total / data.data.pageSize);
const files = data.data.data;
const updatePromises = files.filter(file => !file.forbid).map(file => updateFileStatus(file._id));
await Promise.all(updatePromises);
console.log(`第 ${pageNum} 页的未被禁止的文件已更新为禁止状态`);
}
console.log("所有页面的未被禁止的文件已更新为禁止状态");
}
// 开始处理
processAllPages().catch(error => console.error("处理过程中出错:", error));