文件下载优化
This commit is contained in:
parent
0c5365ccb1
commit
a1dfd24ab8
|
|
@ -1,6 +1,7 @@
|
|||
import styles from '@/components/SharedFilesModel/index.module.scss'
|
||||
import {
|
||||
DeleteOutlined,
|
||||
FolderOutlined,
|
||||
ProfileOutlined,
|
||||
ReloadOutlined,
|
||||
SearchOutlined,
|
||||
|
|
@ -12,6 +13,8 @@ import { DeleteRoomFile, GetRoomFile, GetRoomFileDwUrl, GetRoomUpFileurl, PostRo
|
|||
import axios from 'axios';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { storage } from '@/utils';
|
||||
const fs = require('fs').promises;
|
||||
const { exec } = require('child_process');
|
||||
|
||||
const { Column } = Table
|
||||
|
||||
|
|
@ -262,7 +265,7 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
|
|||
})
|
||||
}
|
||||
}
|
||||
}).then(() => {
|
||||
}).then(async () => {
|
||||
const fileIndex = fileList.data.findIndex((row: any) => row.id === item.id);
|
||||
let fileItem = [...fileList.data] as any;
|
||||
fileItem[fileIndex].percentComplete = 100
|
||||
|
|
@ -273,17 +276,43 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
|
|||
...fileList,
|
||||
data: fileItem,
|
||||
})
|
||||
const downloadLink = document.createElement("a");
|
||||
downloadLink.href = res.data;
|
||||
downloadLink.download = item.fileName;
|
||||
downloadLink.click();
|
||||
getRoomFile()
|
||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||
try {
|
||||
await fs.access(setting.shareFilesPath, fs.constants.F_OK)
|
||||
const response = await fetch(res.data);
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
fs.writeFile(`${setting.shareFilesPath}${fileItem[fileIndex].fileName}`, buffer, {});
|
||||
message.success(`下载成功!文件已保存至:${setting.shareFilesPath}`)
|
||||
try {
|
||||
await fs.access(setting.shareFilesPath, fs.constants.F_OK);
|
||||
if (process.platform === 'win32') {
|
||||
exec(`explorer "${setting.shareFilesPath}"`);
|
||||
} else if (process.platform === 'darwin') {
|
||||
exec(`open "${setting.shareFilesPath}"`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.code === 'ENOENT') {
|
||||
message.error('文件夹不存在!')
|
||||
} else {
|
||||
message.error(error)
|
||||
}
|
||||
}
|
||||
getRoomFile()
|
||||
} catch (error: any) {
|
||||
if (error.code === 'ENOENT') {
|
||||
message.error('文件夹不存在!')
|
||||
return
|
||||
} else {
|
||||
message.error(error)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}} />
|
||||
{/* <FolderOutlined title='文件' style={{ color: '#FFA000', cursor: 'pointer' }} /> */}
|
||||
{/* <FolderOutlined title='文件' style={{ color: '#FFA000', cursor: 'pointer', marginLeft: '10px' }} /> */}
|
||||
</>
|
||||
)} />
|
||||
</Table>
|
||||
|
|
|
|||
|
|
@ -273,7 +273,6 @@ const Meeting: React.FC = () => {
|
|||
|
||||
useEffect(() => {
|
||||
if (recorder) {
|
||||
const setting = JSON.parse(storage.getItem('setting') as string)
|
||||
recorder.start();
|
||||
recorder.ondataavailable = (event: any) => {
|
||||
const blob = new Blob([event.data], {
|
||||
|
|
@ -281,6 +280,7 @@ const Meeting: React.FC = () => {
|
|||
});
|
||||
const reader = new FileReader() as any;
|
||||
reader.onload = async () => {
|
||||
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||
const buffer = Buffer.from(reader.result);
|
||||
await fs.writeFile(`${setting.recordingFilesPath}${+new Date()}.mp4`, buffer, {});
|
||||
message.success(`录制成功!文件已保存至:${setting.recordingFilesPath}`)
|
||||
|
|
|
|||
Loading…
Reference in New Issue