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, }; }