mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 03:48:24 +00:00
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:
@@ -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
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user