37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
export function normalizeAssetReference(item = {}) {
|
|
const direct = item.asset_url || item.AssetURL || item.assetUrl;
|
|
if (typeof direct === "string" && /^asset:\/\//i.test(direct)) {
|
|
return `asset://${direct.slice(direct.indexOf("//") + 2)}`;
|
|
}
|
|
|
|
const id = item.downstream_asset_id || item.asset_id || item.Id || item.id;
|
|
return id ? `asset://${id}` : "";
|
|
}
|
|
|
|
export function extractVideoTaskId(payload = {}) {
|
|
return payload.task_id || payload.id || payload.data?.task_id || payload.data?.id || "";
|
|
}
|
|
|
|
export function extractVideoUrl(payload = {}) {
|
|
const candidates = [
|
|
payload.video_url,
|
|
payload.url,
|
|
payload.output?.video_url,
|
|
payload.output?.url,
|
|
payload.data?.video_url,
|
|
payload.data?.url,
|
|
payload.result?.video_url,
|
|
payload.result?.url,
|
|
payload.content?.video_url,
|
|
payload.content?.url,
|
|
];
|
|
return candidates.find((value) => typeof value === "string" && /^https?:\/\//.test(value)) || "";
|
|
}
|
|
|
|
export function normalizeVideoStatus(payload = {}) {
|
|
const value = String(payload.status || payload.data?.status || "").toLowerCase();
|
|
if (["succeeded", "success", "completed", "done"].includes(value)) return "completed";
|
|
if (["failed", "error", "cancelled", "canceled"].includes(value)) return "failed";
|
|
return value || "processing";
|
|
}
|