Fix: websync doc and export dataset ux (#1225)

* Revert "lafAccount add pat & re request when token invalid (#76)" (#77)

This reverts commit 83d85dfe37adcaef4833385ea52ee79fd84720be.

* perf: workflow ux

* system config

* perf: export data

* doc

* update doc

* fix: whisper
This commit is contained in:
Archer
2024-04-18 12:03:30 +08:00
committed by GitHub
parent 78d50e157f
commit bc0ac6d26b
7 changed files with 131 additions and 21 deletions

View File

@@ -71,7 +71,6 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
cursor.on('end', () => {
cursor.close();
res.end();
updateExportDatasetLimit(teamId);
});
cursor.on('error', (err) => {
@@ -79,6 +78,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
res.status(500);
res.end();
});
updateExportDatasetLimit(teamId);
} catch (err) {
res.status(500);
addLog.error(`export dataset error`, err);

View File

@@ -92,11 +92,17 @@ const Kb = () => {
setLoading(true);
await checkTeamExportDatasetLimit(dataset._id);
xmlDownloadFetch({
await xmlDownloadFetch({
url: `/api/core/dataset/exportAll?datasetId=${dataset._id}`,
filename: `${dataset.name}.csv`
});
},
onSuccess() {
toast({
status: 'success',
title: t('core.dataset.Start export')
});
},
onSettled() {
setLoading(false);
},

View File

@@ -1,20 +1,31 @@
import { getToken } from '@/web/support/user/auth';
import { hasHttps } from '@fastgpt/web/common/system/utils';
export const xmlDownloadFetch = ({ url, filename }: { url: string; filename: string }) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.setRequestHeader('token', getToken());
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
const blob = this.response;
const a = document.createElement('a');
const url = URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
}
};
xhr.send();
export const xmlDownloadFetch = async ({ url, filename }: { url: string; filename: string }) => {
if (hasHttps()) {
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
const response = await fetch(url, {
headers: {
token: `${getToken()}`
}
});
if (!response.ok) throw new Error('Network response was not ok.');
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none'; // 隐藏<a>元素
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click(); // 模拟用户点击
document.body.removeChild(a);
window.URL.revokeObjectURL(downloadUrl); // 清理生成的URL
}
};