760 lines
28 KiB
JavaScript
760 lines
28 KiB
JavaScript
/*
|
|
* Extracted from browser-delivered Turbopack chunk: cde068e14ffee6a8.f8b5a2ab76.js
|
|
* Module id: 111134
|
|
* For reading/searching only; this factory depends on the original Turbopack runtime.
|
|
*/
|
|
|
|
const moduleFactory = (e) => {
|
|
"use strict";
|
|
var t = e.i(358379),
|
|
i = e.i(292002),
|
|
n = e.i(777784),
|
|
r = e.i(713118),
|
|
a = e.i(182004),
|
|
o = e.i(299750),
|
|
u = e.i(192189),
|
|
l = e.i(216257),
|
|
s = e.i(929286),
|
|
d = e.i(253237),
|
|
c = e.i(820915),
|
|
m = e.i(922656),
|
|
f = e.i(881656);
|
|
function p(e) {
|
|
if ("number" == typeof e && Number.isFinite(e)) return e;
|
|
if ("string" == typeof e && "" !== e.trim()) {
|
|
let t = Number(e);
|
|
if (Number.isFinite(t)) return t;
|
|
}
|
|
return NaN;
|
|
}
|
|
let g = (e, t) => {
|
|
if (t === a.NodeType.VIDEO || t === a.NodeType.VIDEO_CLIP) {
|
|
let t = (e.videos ?? [])
|
|
.map((e) => e.videoUrl || e.previewPath)
|
|
.filter((e) => !!e);
|
|
return t.length > 0
|
|
? t
|
|
: (e.images ?? []).map((e) => e.previewPath).filter((e) => !!e);
|
|
}
|
|
let i = [];
|
|
switch (t) {
|
|
case a.NodeType.AUDIO:
|
|
i = e.audios ?? [];
|
|
break;
|
|
case a.NodeType.IMAGE:
|
|
i = e.images ?? [];
|
|
break;
|
|
default:
|
|
return [];
|
|
}
|
|
return i.map((e) => e.previewPath).filter(Boolean);
|
|
};
|
|
function v(e, t) {
|
|
return new Promise((i) => {
|
|
let n = setTimeout(() => i(void 0), t);
|
|
e.then((e) => {
|
|
clearTimeout(n), i(e);
|
|
}).catch(() => {
|
|
clearTimeout(n), i(void 0);
|
|
});
|
|
});
|
|
}
|
|
async function h(e) {
|
|
try {
|
|
let t = await fetch(e, { method: "HEAD" });
|
|
if (!t.ok) return {};
|
|
return {
|
|
mimeType: t.headers.get("content-type") ?? void 0,
|
|
byteSize: (function (e) {
|
|
if (!e) return;
|
|
let t = Number(e);
|
|
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
})(t.headers.get("content-length")),
|
|
};
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
async function $(e) {
|
|
return (
|
|
(await v(
|
|
new Promise((t, i) => {
|
|
let n = new Image();
|
|
(n.onload = () => {
|
|
t({
|
|
width:
|
|
Number.isFinite(n.naturalWidth) && n.naturalWidth > 0
|
|
? n.naturalWidth
|
|
: void 0,
|
|
height:
|
|
Number.isFinite(n.naturalHeight) && n.naturalHeight > 0
|
|
? n.naturalHeight
|
|
: void 0,
|
|
});
|
|
}),
|
|
(n.onerror = () => i(Error("image metadata probe failed"))),
|
|
(n.src = e);
|
|
}),
|
|
12e3,
|
|
)) ?? {}
|
|
);
|
|
}
|
|
async function y(e) {
|
|
return (
|
|
(await v(
|
|
new Promise((t, i) => {
|
|
let n = document.createElement("video");
|
|
(n.preload = "metadata"),
|
|
(n.crossOrigin = "anonymous"),
|
|
(n.src = e),
|
|
(n.onloadedmetadata = () => {
|
|
t({
|
|
width:
|
|
Number.isFinite(n.videoWidth) && n.videoWidth > 0
|
|
? n.videoWidth
|
|
: void 0,
|
|
height:
|
|
Number.isFinite(n.videoHeight) && n.videoHeight > 0
|
|
? n.videoHeight
|
|
: void 0,
|
|
durationSec:
|
|
Number.isFinite(n.duration) && n.duration > 0
|
|
? n.duration
|
|
: void 0,
|
|
}),
|
|
n.removeAttribute("src"),
|
|
n.load();
|
|
}),
|
|
(n.onerror = () => {
|
|
i(Error("video metadata probe failed")),
|
|
n.removeAttribute("src"),
|
|
n.load();
|
|
});
|
|
}),
|
|
12e3,
|
|
)) ?? {}
|
|
);
|
|
}
|
|
async function _(e) {
|
|
return (
|
|
(await v(
|
|
new Promise((t, i) => {
|
|
let n = document.createElement("audio");
|
|
(n.preload = "metadata"),
|
|
(n.crossOrigin = "anonymous"),
|
|
(n.src = e),
|
|
(n.onloadedmetadata = () => {
|
|
t({
|
|
durationSec:
|
|
Number.isFinite(n.duration) && n.duration > 0
|
|
? n.duration
|
|
: void 0,
|
|
}),
|
|
n.removeAttribute("src"),
|
|
n.load();
|
|
}),
|
|
(n.onerror = () => {
|
|
i(Error("audio metadata probe failed")),
|
|
n.removeAttribute("src"),
|
|
n.load();
|
|
});
|
|
}),
|
|
12e3,
|
|
)) ?? {}
|
|
);
|
|
}
|
|
function b(e, t) {
|
|
return e.length === t.length && e.every((e, i) => e === t[i]);
|
|
}
|
|
function x(e, t) {
|
|
let i =
|
|
t === a.NodeType.VIDEO
|
|
? "video"
|
|
: t === a.NodeType.IMAGE
|
|
? "image"
|
|
: void 0;
|
|
return i
|
|
? e
|
|
.map((e) => {
|
|
let t =
|
|
"number" == typeof e.width &&
|
|
Number.isFinite(e.width) &&
|
|
e.width > 0
|
|
? e.width
|
|
: void 0,
|
|
n =
|
|
"number" == typeof e.height &&
|
|
Number.isFinite(e.height) &&
|
|
e.height > 0
|
|
? e.height
|
|
: void 0;
|
|
if (null == t && null == n) return null;
|
|
let r = { kind: i };
|
|
return null != t && (r.width = t), null != n && (r.height = n), r;
|
|
})
|
|
.filter((e) => null !== e)
|
|
: [];
|
|
}
|
|
async function k(e, t) {
|
|
let i = await h(t);
|
|
if (e === a.NodeType.IMAGE) {
|
|
let e = await $(t),
|
|
n = { kind: "image" };
|
|
return (
|
|
i.mimeType && (n.mimeType = i.mimeType),
|
|
null != i.byteSize && (n.byteSize = i.byteSize),
|
|
null != e.width && (n.width = e.width),
|
|
null != e.height && (n.height = e.height),
|
|
n
|
|
);
|
|
}
|
|
if (e === a.NodeType.VIDEO) {
|
|
let e = await y(t),
|
|
n = { kind: "video" };
|
|
return (
|
|
i.mimeType && (n.mimeType = i.mimeType),
|
|
null != i.byteSize && (n.byteSize = i.byteSize),
|
|
null != e.width && (n.width = e.width),
|
|
null != e.height && (n.height = e.height),
|
|
null != e.durationSec && (n.durationSec = e.durationSec),
|
|
n
|
|
);
|
|
}
|
|
if (e === a.NodeType.AUDIO) {
|
|
let e = await _(t),
|
|
n = { kind: "audio" };
|
|
return (
|
|
i.mimeType && (n.mimeType = i.mimeType),
|
|
null != i.byteSize && (n.byteSize = i.byteSize),
|
|
null != e.durationSec && (n.durationSec = e.durationSec),
|
|
n
|
|
);
|
|
}
|
|
}
|
|
function I(e) {
|
|
let i = (0, l.useCanvasStore)((0, s.selectNodeData)(e)),
|
|
n = (0, l.useCanvasStore)((e) => e.updateNodeData),
|
|
r = i?.taskInfo ?? null,
|
|
a = r?.loading ?? !1,
|
|
o = (0, t.useRef)(r);
|
|
return (
|
|
(o.current = r),
|
|
{
|
|
taskInfo: r,
|
|
isLoading: a,
|
|
updateTaskInfo: (0, t.useCallback)(
|
|
(t) => {
|
|
let i = { taskInfo: { ...o.current, ...t } };
|
|
!0 === t.loading && (i.isStale = !1), n(e, i);
|
|
},
|
|
[e, n],
|
|
),
|
|
}
|
|
);
|
|
}
|
|
function S() {
|
|
let e = (0, t.useRef)([]),
|
|
s = (0, t.useRef)(null),
|
|
v = (0, t.useRef)(null),
|
|
h = (0, t.useRef)(!1),
|
|
$ = (0, t.useRef)(!1),
|
|
y = (0, t.useRef)(0),
|
|
_ = (0, t.useRef)(0),
|
|
I = (0, t.useRef)(!1),
|
|
S = (0, l.useCanvasStore)((e) => e.updateNodeData),
|
|
w = (0, l.useCanvasStore)((e) => e.batchUpdateNodeData),
|
|
z = (0, l.useCanvasStore)((e) => e.getNode),
|
|
Z = (0, l.useCanvasStore)((e) => e.markDownstreamStale),
|
|
U = (0, l.useCanvasStore)((e) => e.addNode),
|
|
O = (0, l.useCanvasStore)((e) => e.addEdge),
|
|
N = (0, l.useCanvasStore)((e) => e.setEditingClipNodeId),
|
|
E = (0, l.useCanvasStore)((e) => e.setCanvasLocked),
|
|
T = (0, l.useCanvasStore)((e) =>
|
|
e.nodes
|
|
.map((e) => {
|
|
let t = e.data,
|
|
i = t?.taskInfo;
|
|
return i?.taskId ? `${e.id}:${i.taskId}:${+!!i.loading}` : "";
|
|
})
|
|
.filter(Boolean)
|
|
.join("|"),
|
|
),
|
|
D = (0, t.useMemo)(
|
|
() =>
|
|
(l.stores.canvas?.nodes ?? [])
|
|
.map((e) => {
|
|
let t = e.data,
|
|
i = t?.taskInfo;
|
|
return {
|
|
nodeId: e.id,
|
|
taskId: i?.taskId ?? "",
|
|
loading: !!i?.loading,
|
|
nodeType: t?.type ?? a.NodeType.TEXT,
|
|
taskInfo: i,
|
|
};
|
|
})
|
|
.filter((e) => e.taskId),
|
|
[T],
|
|
),
|
|
j = (0, t.useMemo)(() => D.filter((e) => e.loading), [D]),
|
|
P = (0, t.useCallback)(async () => {
|
|
if (!h.current && !$.current && 0 !== e.current.length) {
|
|
h.current = !0;
|
|
try {
|
|
let t,
|
|
s = [...e.current],
|
|
v = new Map(),
|
|
h = (e) => !e.taskInfo?.taskResult;
|
|
s.filter((e) => !h(e)).forEach((e) => {
|
|
v.set(e.taskId, {
|
|
taskId: e.taskId,
|
|
status: e.taskInfo?.status ?? 2,
|
|
progressPercent: 100,
|
|
...(e.taskInfo ?? {}),
|
|
agentProcessing: !0,
|
|
});
|
|
});
|
|
let I = s.filter(h).map((e) => e.taskId);
|
|
if (I.length > 0) {
|
|
let e = await (0, o.getGenerationProgress)(I);
|
|
if (e && 0 === e.code && e.data) {
|
|
let t = e.data.progresses;
|
|
t &&
|
|
Array.isArray(t) &&
|
|
((_.current = 0),
|
|
t.forEach((e) => {
|
|
v.set(e.taskId, e);
|
|
}),
|
|
(0, c.syncVipOnTerminalProgress)(t));
|
|
}
|
|
}
|
|
if ($.current || 0 === v.size) return;
|
|
let T = !1,
|
|
D = [],
|
|
j = [],
|
|
P = [],
|
|
C = [];
|
|
for (let { nodeId: e, data: i } of (s.forEach(
|
|
({ nodeId: e, taskId: i, nodeType: o, taskInfo: s }) => {
|
|
let d = v.get(i);
|
|
if (!d) return;
|
|
let {
|
|
progressPercent: c,
|
|
taskResult: f,
|
|
failedReason: h,
|
|
delayInfo: $,
|
|
benefitTag: y,
|
|
agentProcessing: _,
|
|
} = d,
|
|
I = p(d.status);
|
|
if (Number.isNaN(I)) return;
|
|
let w = z(e);
|
|
if (!w) return;
|
|
let Z = w?.data?.taskInfo;
|
|
if (!Z || (Z.taskId && Z.taskId !== i)) return;
|
|
let U = 0 === I || 1 === I;
|
|
if (
|
|
p(Z?.status) === I &&
|
|
Z?.loading === U &&
|
|
Z?.progressPercent === c &&
|
|
Z?.delayInfo?.remainSeconds === $?.remainSeconds &&
|
|
2 !== I &&
|
|
!_
|
|
)
|
|
return;
|
|
T = !0;
|
|
let O = ((e) => {
|
|
if (e)
|
|
try {
|
|
return JSON.parse(e);
|
|
} catch {
|
|
return;
|
|
}
|
|
})(f),
|
|
N = {
|
|
taskInfo: {
|
|
taskId: i,
|
|
loading: 0 === I || 1 === I,
|
|
status: I,
|
|
progressPercent: c,
|
|
...(3 === I && h ? { failedReason: h } : void 0),
|
|
...($ ? { delayInfo: $ } : void 0),
|
|
...(Z?.acceleratePower != null
|
|
? { acceleratePower: Z.acceleratePower }
|
|
: void 0),
|
|
...(y ? { benefitTag: y } : void 0),
|
|
},
|
|
};
|
|
if (s?.taskParams && !s?.agentProcessing)
|
|
try {
|
|
let e = JSON.parse(s.taskParams),
|
|
t = w.data?.params;
|
|
(N.params = (0,
|
|
m.hydrateGeneratorParamsFromFlatTaskParams)(
|
|
e,
|
|
o,
|
|
t,
|
|
(e) => l.stores.global?.getModelSchema(e) ?? null,
|
|
)),
|
|
N.taskInfo.loading &&
|
|
((N.taskInfo.agentProcessing = !0),
|
|
(N.taskInfo.taskParams = s.taskParams));
|
|
} catch (e) {}
|
|
if (2 === I && O) {
|
|
if (o === a.NodeType.SCRIPT)
|
|
try {
|
|
let {
|
|
title: e,
|
|
rows: t,
|
|
shotColumns: i,
|
|
} = (0, u.parseStoryboardResult)(f || "");
|
|
(N.rows = t),
|
|
e && (N.title = e),
|
|
i && (N.shotColumns = i);
|
|
} catch (e) {
|
|
console.error(
|
|
"[usePollTaskInfo] 解析 SCRIPT taskResult 失败:",
|
|
e,
|
|
);
|
|
}
|
|
else if (o === a.NodeType.TEXT) N.content = O.texts ?? [];
|
|
else if (o === a.NodeType.VIDEO_CLIP) {
|
|
let t = g(O, o);
|
|
t.length > 0 &&
|
|
C.push({ nodeId: e, outputUrl: t[0], result: O });
|
|
} else {
|
|
let t = g(O, o);
|
|
if (
|
|
((N.url = t),
|
|
t.length > 0 &&
|
|
(o === a.NodeType.IMAGE
|
|
? (N.portraitAssetId = void 0)
|
|
: o === a.NodeType.VIDEO
|
|
? (N.assetVideoAssetId = void 0)
|
|
: o === a.NodeType.AUDIO &&
|
|
(N.assetAudioAssetId = void 0)),
|
|
t.length > 0 &&
|
|
[
|
|
a.NodeType.IMAGE,
|
|
a.NodeType.VIDEO,
|
|
a.NodeType.AUDIO,
|
|
].includes(o))
|
|
) {
|
|
let i =
|
|
o === a.NodeType.VIDEO
|
|
? (O.videos ?? O.images ?? [])
|
|
: o === a.NodeType.IMAGE
|
|
? (O.images ?? [])
|
|
: [],
|
|
n = x(i, o);
|
|
if (n.length === t.length) {
|
|
if (
|
|
((N.resourceMeta = { items: n }),
|
|
o === a.NodeType.IMAGE && n.length > 0)
|
|
) {
|
|
let e = n[0],
|
|
t = Number(e.width),
|
|
i = Number(e.height);
|
|
if (t > 0 && i > 0) {
|
|
let e = (0, r.computeNodeDimensionsFromNatural)(
|
|
t,
|
|
i,
|
|
);
|
|
(N.contentWidth = e.width),
|
|
(N.contentHeight = e.height);
|
|
}
|
|
}
|
|
o === a.NodeType.VIDEO &&
|
|
n.some(
|
|
(e) =>
|
|
"video" === e.kind &&
|
|
!("durationSec" in e && null != e.durationSec),
|
|
) &&
|
|
P.push(() => {
|
|
(async () => {
|
|
let i = (
|
|
await Promise.all(t.map((e) => k(o, e)))
|
|
).filter((e) => !!e);
|
|
if (0 === i.length) return;
|
|
let n = z(e),
|
|
r =
|
|
(n?.data?.url ?? []).filter(Boolean) || [];
|
|
if (!b(r, t)) return;
|
|
let a = n?.resourceMeta?.items ?? [],
|
|
u = a.map((e, t) => {
|
|
let n = i[t];
|
|
return n &&
|
|
"video" === e.kind &&
|
|
"video" === n.kind &&
|
|
null == e.durationSec
|
|
? { ...e, durationSec: n.durationSec }
|
|
: e;
|
|
});
|
|
JSON.stringify(a) !== JSON.stringify(u) &&
|
|
S(e, { resourceMeta: { items: u } });
|
|
})();
|
|
});
|
|
} else
|
|
P.push(() => {
|
|
(async () => {
|
|
let i = z(e),
|
|
n = (i?.data?.url ?? []).filter(Boolean) || [];
|
|
if (!b(n, t)) return;
|
|
let r = (
|
|
await Promise.all(t.map((e) => k(o, e)))
|
|
).filter((e) => !!e);
|
|
if (0 === r.length) return;
|
|
let a = z(e),
|
|
u = (a?.data?.url ?? []).filter(Boolean) || [];
|
|
if (!b(u, t)) return;
|
|
let l = a?.resourceMeta?.items ?? [];
|
|
JSON.stringify(l) !== JSON.stringify(r) &&
|
|
S(e, { resourceMeta: { items: r } });
|
|
})();
|
|
});
|
|
}
|
|
}
|
|
N.isStale = !1;
|
|
}
|
|
(2 === I || 3 === I) && (N.prevTaskInfo = void 0);
|
|
let E =
|
|
2 !== I &&
|
|
3 !== I &&
|
|
Z?.taskId === i &&
|
|
p(Z?.status) === I &&
|
|
Z?.loading === U &&
|
|
Z?.progressPercent !== c &&
|
|
100 !== c;
|
|
if (3 === I && 3 !== p(Z.status)) {
|
|
let e =
|
|
"string" == typeof h && "" !== h.trim()
|
|
? h.trim()
|
|
: "任务失败,请重试";
|
|
n.Notify.error(e);
|
|
}
|
|
if (
|
|
(D.push({ nodeId: e, data: N, skipSync: E }),
|
|
2 === I && (j.push(e), o === a.NodeType.IMAGE && !t))
|
|
) {
|
|
let e = g(O, a.NodeType.IMAGE);
|
|
e[0] && (t = e[0]);
|
|
}
|
|
},
|
|
),
|
|
D)) {
|
|
if (!Array.isArray(i?.url)) continue;
|
|
let t = z(e);
|
|
if (!t || t.type !== a.NodeType.IMAGE) continue;
|
|
let n = (t?.data?.url ?? []).filter(
|
|
(e) => "string" == typeof e && e.length > 0,
|
|
),
|
|
r = i.url.filter((e) => "string" == typeof e && e.length > 0);
|
|
for (let e of n) (0, f.invalidateImageCache)(e);
|
|
for (let e of r) (0, f.invalidateImageCache)(e);
|
|
}
|
|
for (let e of (D.length > 0 && w(D), j)) Z(e);
|
|
try {
|
|
j?.length > 0 &&
|
|
window.dispatchEvent(
|
|
new CustomEvent("libtv:artifact-created"),
|
|
);
|
|
} catch (e) {
|
|
console.error(
|
|
"[usePollTaskInfo] 触发 artifact-created 事件失败:",
|
|
e,
|
|
);
|
|
}
|
|
for (let { nodeId: e, outputUrl: t, result: n } of C) {
|
|
let o = z(e);
|
|
if (!o) continue;
|
|
S(e, { saveToNodeOnComplete: void 0 });
|
|
let u = [t],
|
|
s = crypto.randomUUID(),
|
|
d = o.data,
|
|
c = d?.name ?? d?.label ?? "视频合成",
|
|
m =
|
|
(n?.videos?.length ?? 0) > 0
|
|
? (n?.videos ?? [])
|
|
: (n?.images ?? []),
|
|
f = x(m, a.NodeType.VIDEO),
|
|
p = {
|
|
type: a.NodeType.VIDEO,
|
|
name: `${c} 成片`,
|
|
url: u,
|
|
poster: "",
|
|
action: a.NodeAction.VIDEO_RESOURCE,
|
|
generatorType: a.GeneratorType.DEFAULT,
|
|
};
|
|
if (f.length === u.length) {
|
|
p.resourceMeta = { items: f };
|
|
let e = f[0];
|
|
if (e?.kind === "video") {
|
|
let t = Number(e.width),
|
|
i = Number(e.height);
|
|
if (t > 0 && i > 0) {
|
|
let e = (0, r.computeNodeDimensionsFromNatural)(t, i);
|
|
(p.contentWidth = e.width), (p.contentHeight = e.height);
|
|
}
|
|
}
|
|
f.some(
|
|
(e) =>
|
|
"video" === e.kind &&
|
|
!("durationSec" in e && null != e.durationSec),
|
|
) &&
|
|
P.push(() => {
|
|
(async () => {
|
|
let e = (
|
|
await Promise.all(
|
|
u.map((e) => k(a.NodeType.VIDEO, e)),
|
|
)
|
|
).filter((e) => !!e);
|
|
if (0 === e.length) return;
|
|
let t = z(s),
|
|
i =
|
|
(t?.data?.url ?? []).filter(
|
|
(e) => "string" == typeof e && e.length > 0,
|
|
) || [];
|
|
if (!b(i, u)) return;
|
|
let n = t?.resourceMeta?.items ?? [],
|
|
r = n.map((t, i) => {
|
|
let n = e[i];
|
|
return n &&
|
|
"video" === t.kind &&
|
|
"video" === n.kind &&
|
|
null == t.durationSec
|
|
? { ...t, durationSec: n.durationSec }
|
|
: t;
|
|
});
|
|
JSON.stringify(n) !== JSON.stringify(r) &&
|
|
S(s, { resourceMeta: { items: r } });
|
|
})();
|
|
});
|
|
} else
|
|
u.length > 0 &&
|
|
P.push(() => {
|
|
(async () => {
|
|
let e = z(s),
|
|
t =
|
|
(e?.data?.url ?? []).filter(
|
|
(e) => "string" == typeof e && e.length > 0,
|
|
) || [];
|
|
if (!b(t, u)) return;
|
|
let i = (
|
|
await Promise.all(
|
|
u.map((e) => k(a.NodeType.VIDEO, e)),
|
|
)
|
|
).filter((e) => !!e);
|
|
if (0 === i.length) return;
|
|
let n = z(s),
|
|
r =
|
|
(n?.data?.url ?? []).filter(
|
|
(e) => "string" == typeof e && e.length > 0,
|
|
) || [];
|
|
if (!b(r, u)) return;
|
|
let o = n?.resourceMeta?.items ?? [];
|
|
JSON.stringify(o) !== JSON.stringify(i) &&
|
|
S(s, { resourceMeta: { items: i } });
|
|
})();
|
|
});
|
|
let g = {
|
|
id: s,
|
|
type: a.NodeType.VIDEO,
|
|
data: p,
|
|
position: {
|
|
x: o.position.x + r.NODE_WIDTH + r.NODE_GAP,
|
|
y: o.position.y,
|
|
},
|
|
sourcePosition: i.Position.Right,
|
|
targetPosition: i.Position.Left,
|
|
};
|
|
U(g),
|
|
O({
|
|
id: crypto.randomUUID(),
|
|
source: e,
|
|
sourceHandle: "source",
|
|
target: s,
|
|
targetHandle: "target",
|
|
}),
|
|
l.stores.canvas?.editingClipNodeId === e && (N(null), E(!1));
|
|
}
|
|
for (let e of P) e();
|
|
t && (0, d.trySetProjectCover)(t),
|
|
(e.current = e.current.filter(({ taskId: e }) => {
|
|
let t = v.get(e);
|
|
if (!t) return !0;
|
|
let i = p(t.status);
|
|
return 0 === i || 1 === i;
|
|
})),
|
|
T ? (y.current = 0) : (y.current = Math.min(y.current + 1, 5));
|
|
} catch (t) {
|
|
if (t instanceof Error && "AbortError" === t.name) return;
|
|
if (((_.current += 1), _.current >= 10)) {
|
|
console.error(`[usePollTaskInfo] 连续 10 次查询失败,停止轮询`);
|
|
let t = e.current.map(({ nodeId: e, taskId: t }) => ({
|
|
nodeId: e,
|
|
data: { taskInfo: { taskId: t, loading: !1, status: 3 } },
|
|
}));
|
|
t.length > 0 && w(t), (e.current = []);
|
|
}
|
|
} finally {
|
|
h.current = !1;
|
|
}
|
|
}
|
|
}, [S, w, z, Z, U, O, N, E]);
|
|
(0, t.useEffect)(() => {
|
|
let t = new Map();
|
|
j.forEach((e) => {
|
|
t.set(e.taskId, {
|
|
nodeId: e.nodeId,
|
|
taskId: e.taskId,
|
|
nodeType: e.nodeType,
|
|
taskInfo: e.taskInfo,
|
|
});
|
|
});
|
|
let i = new Set(e.current.map((e) => e.taskId)),
|
|
n = [];
|
|
t.forEach((e, t) => {
|
|
i.has(t) || n.push(e);
|
|
});
|
|
let r = e.current.filter((e) => t.has(e.taskId));
|
|
(e.current = [...r, ...n]),
|
|
n.length > 0 &&
|
|
((y.current = 0),
|
|
(_.current = 0),
|
|
v.current && clearTimeout(v.current),
|
|
(v.current = setTimeout(() => {
|
|
!$.current && e.current.length > 0 && P();
|
|
}, 100)));
|
|
}, [j, P]),
|
|
(0, t.useEffect)(() => {
|
|
I.current ||
|
|
((I.current = !0), (0, o.checkTaskProgressBatch)().catch(() => {}));
|
|
}, []),
|
|
(0, t.useEffect)(() => {
|
|
$.current = !1;
|
|
let t = () => {
|
|
$.current ||
|
|
(s.current = setTimeout(
|
|
() => {
|
|
(async () => {
|
|
e.current.length > 0 && !$.current && (await P()), t();
|
|
})();
|
|
},
|
|
Math.min(2e3 * Math.pow(2, y.current), 3e4),
|
|
));
|
|
};
|
|
return (
|
|
t(),
|
|
() => {
|
|
($.current = !0),
|
|
s.current && (clearTimeout(s.current), (s.current = null)),
|
|
v.current && (clearTimeout(v.current), (v.current = null));
|
|
}
|
|
);
|
|
}, [P]);
|
|
}
|
|
e.s(["useCreateTaskInfo", () => I, "usePollTaskInfo", () => S]);
|
|
};
|
|
|
|
export default moduleFactory;
|