export async function downloadVideo(videoUrl, cameraName) {
try {
const link = document.createElement('a');
link.href = videoUrl;
link.download = `${cameraName || 'video'}_${new Date().getTime()}.mp4`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.error('下载失败:', error);
try {
const response = await fetch(videoUrl);
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `${cameraName || 'video'}_${new Date().getTime()}.mp4`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
} catch (fetchError) {
console.error('通过fetch下载也失败:', fetchError);
window.open(videoUrl);
}
}
}