cb9d836227
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
import i18next from 'i18next';
|
|
|
|
const SUCCESS_STATUSES = new Set(['success', 'completed', 'succeeded']);
|
|
const FAILURE_STATUSES = new Set([
|
|
'failure',
|
|
'failed',
|
|
'canceled',
|
|
'cancelled',
|
|
]);
|
|
|
|
export function normalizeVideoTaskStatus(status) {
|
|
const normalized = String(status || '')
|
|
.trim()
|
|
.toLowerCase();
|
|
if (SUCCESS_STATUSES.has(normalized)) return 'success';
|
|
if (FAILURE_STATUSES.has(normalized)) return 'failure';
|
|
if (normalized === 'in_progress' || normalized === 'processing') {
|
|
return 'in_progress';
|
|
}
|
|
if (
|
|
normalized === 'queued' ||
|
|
normalized === 'submitted' ||
|
|
normalized === 'not_start'
|
|
) {
|
|
return 'queued';
|
|
}
|
|
return normalized || 'unknown';
|
|
}
|
|
|
|
export function getVideoURLFromDetail(detail) {
|
|
const value = detail?.data?.video_url;
|
|
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
}
|
|
|
|
export function canCancelVideoTask(task) {
|
|
const status = normalizeVideoTaskStatus(task?.status);
|
|
return (
|
|
task?.cancel_supported === true &&
|
|
(status === 'queued' || status === 'in_progress')
|
|
);
|
|
}
|
|
|
|
export function canRegenerateVideoTask(task) {
|
|
return task?.regenerate_supported === true;
|
|
}
|
|
|
|
export function normalizeExperienceVideoError(
|
|
error,
|
|
fallback = i18next.t('请求失败'),
|
|
) {
|
|
const payload = error?.response?.data || error?.data || error;
|
|
return {
|
|
code: payload?.code || 'video_generation_failed',
|
|
message: payload?.message || error?.message || fallback,
|
|
};
|
|
}
|