84 lines
2.5 KiB
JavaScript
84 lines
2.5 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
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 buildVideoRegenerateRequest(snapshot, selectedModel) {
|
|
const model =
|
|
typeof selectedModel === 'object'
|
|
? selectedModel?.model_name || selectedModel?.id
|
|
: selectedModel;
|
|
return {
|
|
...snapshot,
|
|
model: model || snapshot?.model || '',
|
|
image: snapshot?.image || '',
|
|
seed: snapshot?.seed ?? null,
|
|
};
|
|
}
|
|
|
|
export function normalizeExperienceVideoError(error, fallback = '请求失败') {
|
|
const payload = error?.response?.data || error?.data || error;
|
|
return {
|
|
code: payload?.code || 'video_generation_failed',
|
|
message: payload?.message || error?.message || fallback,
|
|
};
|
|
}
|