fix: 解决备份文件过大导致下载超时问题 (#1199)

Refs https://github.com/1Panel-dev/1Panel/issues/1191
pull/1203/head
zhengkunwang223 2023-05-31 14:01:01 +08:00 committed by GitHub
parent 824051e89e
commit 8dfba82a70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 16 deletions

View File

@ -49,7 +49,7 @@
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { dateFormat } from '@/utils/util';
import { dateFormat, downloadFile } from '@/utils/util';
import { useDeleteData } from '@/hooks/use-delete-data';
import { handleBackup, handleRecover } from '@/api/modules/setting';
import i18n from '@/lang';
@ -57,7 +57,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue';
import { deleteBackupRecord, downloadBackupRecord, searchBackupRecords } from '@/api/modules/setting';
import { Backup } from '@/api/interface/backup';
import { MsgSuccess } from '@/utils/message';
import { DownloadByPath } from '@/api/modules/files';
// import { DownloadByPath } from '@/api/modules/files';
const selects = ref<any>([]);
const loading = ref();
@ -147,14 +147,7 @@ const onDownload = async (row: Backup.RecordInfo) => {
fileName: row.fileName,
};
await downloadBackupRecord(params).then(async (res) => {
const file = await DownloadByPath(res.data);
const downloadUrl = window.URL.createObjectURL(new Blob([file]));
const a = document.createElement('a');
a.style.display = 'none';
a.href = downloadUrl;
a.download = row.fileName;
const event = new MouseEvent('click');
a.dispatchEvent(event);
downloadFile(res.data);
});
};

View File

@ -236,3 +236,8 @@ export function isJson(str: string) {
export function toLowerCase(str: string) {
return str.toLowerCase();
}
export function downloadFile(filePath: string) {
let url = `${import.meta.env.VITE_API_URL as string}/files/download?`;
window.open(url + 'path=' + filePath, '_blank');
}

View File

@ -183,7 +183,7 @@
<script setup lang="ts">
import { nextTick, onMounted, reactive, ref } from '@vue/runtime-core';
import { GetFilesList, DeleteFile, GetFileContent, ComputeDirSize } from '@/api/modules/files';
import { computeSize, dateFormat, getIcon, getRandomStr } from '@/utils/util';
import { computeSize, dateFormat, downloadFile, getIcon, getRandomStr } from '@/utils/util';
import { File } from '@/api/interface/file';
import { useDeleteData } from '@/hooks/use-delete-data';
import i18n from '@/lang';
@ -207,8 +207,6 @@ import { MsgSuccess, MsgWarning } from '@/utils/message';
import { ElMessageBox } from 'element-plus';
import { useSearchable } from './hooks/searchable';
import { ResultData } from '@/api/interface';
// import streamSaver from 'streamsaver';
// import axios from 'axios';
interface FilePaths {
url: string;
@ -245,7 +243,6 @@ const fileRename = reactive({ path: '', oldName: '' });
const fileWget = reactive({ path: '' });
const fileMove = reactive({ oldPaths: [''], type: '', path: '' });
const processPage = reactive({ open: false });
// const fileDownload = reactive({ path: '', name: '' });
const createRef = ref();
const roleRef = ref();
@ -573,8 +570,7 @@ const openPaste = () => {
};
const openDownload = (file: File.File) => {
let url = `${import.meta.env.VITE_API_URL as string}/files/download?`;
window.open(url + 'path=' + file.path, '_blank');
downloadFile(file.path);
};
const openDetail = (row: File.File) => {

View File

@ -323,6 +323,7 @@ const submitDate = (row: any) => {
remark: row.remark,
webSiteGroupId: row.webSiteGroupId,
expireDate: reqDate,
IPV6: row.IPV6,
};
UpdateWebsite(req).then(() => {