feat: deliver AI drama production demo
This commit is contained in:
36
lib/normalize.mjs
Normal file
36
lib/normalize.mjs
Normal file
@@ -0,0 +1,36 @@
|
||||
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";
|
||||
}
|
||||
Reference in New Issue
Block a user