修改
This commit is contained in:
@@ -254,8 +254,20 @@ const AIChatPage: React.FC = () => {
|
||||
// 设置5秒轮询
|
||||
pollingRef.current = window.setInterval(() => {
|
||||
getgen_list(Pagebreak).then((data: any) => {
|
||||
setGen_list(data.items);
|
||||
setTotalnumber(data.total)
|
||||
// 只更新正在生成的任务,不影响其他已加载的数据
|
||||
setGen_list((prevList: any[]) => {
|
||||
return prevList.map((prevItem: any) => {
|
||||
// 只更新正在生成的任务
|
||||
if (prevItem.status === 'generating') {
|
||||
const newItem = data.items.find((item: any) => item.id === prevItem.id);
|
||||
// 如果找到了对应的新数据,使用新数据;否则保持旧数据
|
||||
return newItem || prevItem;
|
||||
}
|
||||
// 非生成中的任务保持不变
|
||||
return prevItem;
|
||||
});
|
||||
});
|
||||
setTotalnumber(data.total);
|
||||
}).catch((error) => {
|
||||
});
|
||||
}, 5000);
|
||||
@@ -574,10 +586,12 @@ const AIChatPage: React.FC = () => {
|
||||
setPreviewUrl('');
|
||||
};
|
||||
|
||||
const handleDownload = () => {
|
||||
const handleDownload = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!previewUrl) return;
|
||||
const link = document.createElement('a');
|
||||
link.href = previewUrl;
|
||||
link.href = `${import.meta.env.VITE_API_BASE || "http://localhost:8000"}${previewUrl}`;
|
||||
link.download = previewType === 'image' ? 'image.png' : 'video.mp4';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
@@ -28,6 +28,45 @@ const GeneratedRecord: React.FC = () => {
|
||||
const [previewVisible, setPreviewVisible] = useState(false);
|
||||
const [previewItem, setPreviewItem] = useState<any>(null);
|
||||
const videoRef = React.createRef<HTMLVideoElement>();
|
||||
|
||||
// 从URL中提取exp时间戳(支持相对路径和完整URL)
|
||||
const extractExpTimestamp = (url: string): number | null => {
|
||||
if (!url) return null;
|
||||
|
||||
try {
|
||||
// 尝试作为完整URL解析
|
||||
const urlObj = new URL(url);
|
||||
const expStr = urlObj.searchParams.get('exp');
|
||||
if (expStr) {
|
||||
return parseInt(expStr, 10);
|
||||
}
|
||||
return null;
|
||||
} catch {
|
||||
// 如果完整URL解析失败,尝试解析相对路径中的查询参数
|
||||
try {
|
||||
const queryStart = url.indexOf('?');
|
||||
if (queryStart !== -1) {
|
||||
const queryString = url.substring(queryStart + 1);
|
||||
const params = new URLSearchParams(queryString);
|
||||
const expStr = params.get('exp');
|
||||
if (expStr) {
|
||||
return parseInt(expStr, 10);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 检查媒体是否过期
|
||||
const isMediaExpired = (url: string): boolean => {
|
||||
const expTimestamp = extractExpTimestamp(url);
|
||||
if (!expTimestamp) return false;
|
||||
const currentTimestamp = Math.floor(Date.now() / 1000);
|
||||
return currentTimestamp > expTimestamp;
|
||||
};
|
||||
|
||||
// 下载文件
|
||||
const handleDownload = (item: any) => {
|
||||
@@ -689,8 +728,9 @@ const GeneratedRecord: React.FC = () => {
|
||||
window.open(url, '_blank');
|
||||
}}
|
||||
style={{ flex: 1, borderRadius: 8 }}
|
||||
disabled={isMediaExpired(previewItem.videoUrl || previewItem.imageUrl)}
|
||||
>
|
||||
下载
|
||||
{isMediaExpired(previewItem.videoUrl || previewItem.imageUrl) ? '资源已过期' : '下载'}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleClosePreview}
|
||||
|
||||
Reference in New Issue
Block a user