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