forked from 77media/video-flow
Merge branch 'dev' of https://git.qikongjian.com/77media/video-flow into dev
This commit is contained in:
commit
ab4e43ba90
@ -1,6 +1,7 @@
|
|||||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, AxiosHeaders } from 'axios';
|
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, AxiosHeaders } from 'axios';
|
||||||
import { BASE_URL } from './constants'
|
import { BASE_URL } from './constants'
|
||||||
import { errorHandle } from './errorHandle';
|
import { errorHandle } from './errorHandle';
|
||||||
|
import { showInsufficientPointsNotification } from '../utils/notifications';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一的错误处理函数
|
* 统一的错误处理函数
|
||||||
@ -11,23 +12,12 @@ const handleRequestError = (error: any, defaultMessage: string = '请求失败')
|
|||||||
if (error.response) {
|
if (error.response) {
|
||||||
const { status, data } = error.response;
|
const { status, data } = error.response;
|
||||||
const errorMessage = data?.message || data?.detail?.message || defaultMessage;
|
const errorMessage = data?.message || data?.detail?.message || defaultMessage;
|
||||||
|
|
||||||
// 处理 402 状态码的特殊情况
|
|
||||||
if (status === 402 && data?.detail) {
|
|
||||||
// 只显示通知,不调用 errorHandle
|
|
||||||
import('../utils/notifications').then(({ showInsufficientPointsNotification }) => {
|
|
||||||
showInsufficientPointsNotification(data.detail);
|
|
||||||
});
|
|
||||||
return; // 直接返回,不再抛出错误
|
|
||||||
}
|
|
||||||
|
|
||||||
errorHandle(status, errorMessage);
|
errorHandle(status, errorMessage);
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
errorHandle(0);
|
errorHandle(0);
|
||||||
} else {
|
} else {
|
||||||
errorHandle(0, error.message || defaultMessage);
|
errorHandle(0, error.message || defaultMessage);
|
||||||
}
|
}
|
||||||
return Promise.reject(error); // 将 reject 移到这里,避免 402 时重复处理
|
|
||||||
};
|
};
|
||||||
// 创建 axios 实例
|
// 创建 axios 实例
|
||||||
const request: AxiosInstance = axios.create({
|
const request: AxiosInstance = axios.create({
|
||||||
@ -81,6 +71,19 @@ request.interceptors.response.use(
|
|||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
// 处理 402 错误
|
||||||
|
if (error.response?.status === 402 && error.response?.data?.detail) {
|
||||||
|
// 使用动态导入并确保在下一个事件循环中执行
|
||||||
|
setTimeout(() => {
|
||||||
|
import('../utils/notifications').then(({ showInsufficientPointsNotification }) => {
|
||||||
|
showInsufficientPointsNotification(error.response.data.detail);
|
||||||
|
});
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
return Promise.reject(new Error('Insufficient points'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他错误走通用处理
|
||||||
handleRequestError(error);
|
handleRequestError(error);
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -202,8 +202,8 @@ export function useWorkflowData({ onEditPlanGenerated }: UseWorkflowDataProps =
|
|||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
notification.destroy(notificationKey);
|
notification.destroy(notificationKey);
|
||||||
|
setIsLoadingGenerateEditPlan(false);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
setIsLoadingGenerateEditPlan(false);
|
|
||||||
}
|
}
|
||||||
}, [episodeId, onEditPlanGenerated, notificationKey]);
|
}, [episodeId, onEditPlanGenerated, notificationKey]);
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ export function useWorkflowData({ onEditPlanGenerated }: UseWorkflowDataProps =
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 主动触发剪辑
|
// 主动触发剪辑
|
||||||
if (canGoToCut && taskObject.currentStage === 'video') {
|
if (canGoToCut && taskObject.currentStage === 'video') {
|
||||||
generateEditPlan(retryCount);
|
generateEditPlan(retryCount - 1);
|
||||||
}
|
}
|
||||||
}, [canGoToCut, taskObject.currentStage, retryCount]);
|
}, [canGoToCut, taskObject.currentStage, retryCount]);
|
||||||
|
|
||||||
|
|||||||
@ -58,16 +58,21 @@ const btnStyle = {
|
|||||||
* 显示积分不足通知
|
* 显示积分不足通知
|
||||||
* @description 在右上角显示一个带有充值链接的积分不足提醒
|
* @description 在右上角显示一个带有充值链接的积分不足提醒
|
||||||
*/
|
*/
|
||||||
|
const INSUFFICIENT_POINTS_KEY = 'insufficient-points-notification';
|
||||||
|
|
||||||
export const showInsufficientPointsNotification = (detail?: {
|
export const showInsufficientPointsNotification = (detail?: {
|
||||||
current_balance?: number;
|
current_balance?: number;
|
||||||
required_tokens?: number;
|
required_tokens?: number;
|
||||||
message?: string;
|
message?: string;
|
||||||
}) => {
|
}) => {
|
||||||
// 生成唯一的 key
|
// 先关闭现有的通知
|
||||||
const key = `insufficient-points-${Date.now()}`;
|
notification.destroy(INSUFFICIENT_POINTS_KEY);
|
||||||
|
|
||||||
|
// 每次都生成新的 key
|
||||||
|
const uniqueKey = `${INSUFFICIENT_POINTS_KEY}-${Date.now()}`;
|
||||||
|
|
||||||
notification.warning({
|
notification.warning({
|
||||||
key, // 添加唯一的 key
|
key: uniqueKey,
|
||||||
message: null,
|
message: null,
|
||||||
description: (
|
description: (
|
||||||
<div data-alt="insufficient-points-notification" style={{ minWidth: '280px' }}>
|
<div data-alt="insufficient-points-notification" style={{ minWidth: '280px' }}>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user