fix: 图+文本合并单任务;取消作废在飞结果;ready 不再回退远程
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 48s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 48s
This commit is contained in:
1 parent
189ba3b8f8
commit
8d110f285c
6 files changed
+126
-19
No files matched your search
@@ -188,16 +188,24 @@
|
||||
// 这里原来直接返回 children,把节点自己的 data.text 丢成空串 ⇒ 发出去只有图没有提示词,
|
||||
// 生图服务商报 400 INVALID_ARGUMENT。口径与上面的 prompt 分支一致:自己的文本优先,参考图取并集。
|
||||
const ownTitle = String((n.data && n.data.title) || '').trim()
|
||||
// 2026-12-03(用户):上游**全是纯图片节点**时,合并成**一个**任务(图1+图2 一起带),
|
||||
// 与内置 prompt 分支同口径;上游带文本、或来自相册等多值源时保持「一子一任务」。
|
||||
// 不能无脑把 refs 取并集再逐条塞回去:相册的一图一任务会被压平成「每个任务带全部图」。
|
||||
const allRefLeaves = children.length > 0 && children.every((t) => {
|
||||
// 2026-12-03(用户):上游是「纯图片」或「图片 + 至多一段文本」时,合并成**一个**任务
|
||||
// (图1+图2 一起带,文本用节点自己的 > 上游那段);两段以上文本、相册/批量等多值源保持一子一任务。
|
||||
const refChildren = []
|
||||
const otherChildren = []
|
||||
for (const t of children) {
|
||||
const sn = graph.byId.get(t.sourceNodeId)
|
||||
return !!(sn && sn.type === 'ref')
|
||||
})
|
||||
const base = allRefLeaves
|
||||
? [{ sourceNodeId: n.id, ownerNodeId: n.id, title: ownTitle, text: '', refNodes: dedupeTaskRefs(children.flatMap((t) => t.refNodes || [])), diagnostics: { cycles: children.flatMap((t) => (t.diagnostics && t.diagnostics.cycles) || []), disabledSources: [] } }]
|
||||
: children
|
||||
if (sn && sn.type === 'ref') refChildren.push(t)
|
||||
else otherChildren.push(t)
|
||||
}
|
||||
const mergedRefs = dedupeTaskRefs(refChildren.flatMap((t) => t.refNodes || []))
|
||||
const mergedDiag = { cycles: children.flatMap((t) => (t.diagnostics && t.diagnostics.cycles) || []), disabledSources: [] }
|
||||
let base = children
|
||||
if (refChildren.length && !otherChildren.length) {
|
||||
base = [{ sourceNodeId: n.id, ownerNodeId: n.id, title: ownTitle, text: '', refNodes: mergedRefs, diagnostics: mergedDiag }]
|
||||
} else if (refChildren.length && otherChildren.length === 1) {
|
||||
const tc = otherChildren[0]
|
||||
base = [{ ...tc, sourceNodeId: own ? n.id : (tc.sourceNodeId || n.id), ownerNodeId: n.id, title: ownTitle || tc.title || '', text: String(tc.text || ''), refNodes: dedupeTaskRefs((tc.refNodes || []).concat(mergedRefs)), diagnostics: tc.diagnostics || mergedDiag }]
|
||||
}
|
||||
return base.map((t) => ({
|
||||
...t,
|
||||
ownerNodeId: n.id,
|
||||
|
||||
+24
-5
@@ -89,6 +89,14 @@
|
||||
async function runOne (e) {
|
||||
// active 由 pump 在「决定启动」时同步 +1(见 pump):放在这里会晚一个微任务,
|
||||
// pump 的 while 就会在 active 还是 0 时把整个队列一次性放出去(2026-12-03 实测并发限制从未生效)。
|
||||
// 2026-12-03:每次运行带「运行序号 + 取消控制器」—— 取消/重下时旧请求的结果必须作废,
|
||||
// 否则回包晚到会把 link-only 覆盖成 ready,或和新一轮同时写同一条记录。
|
||||
const mySeq = (e.runSeq || 0) + 1
|
||||
e.runSeq = mySeq
|
||||
const ctrl = (typeof AbortController === 'function') ? new AbortController() : null
|
||||
e.ctrl = ctrl
|
||||
const stale = () => (e.runSeq !== mySeq || e.status !== STATE.DOWNLOADING)
|
||||
const settle = () => { active--; try { delete e.ctrl } catch (e0) { /* ignore */ } pump() }
|
||||
setStatus(e, STATE.DOWNLOADING, { lastError: '', progress: 0, receivedBytes: 0, totalBytes: 0 })
|
||||
let lastErr = ''
|
||||
// 2026-12-02:下载进度(有 content-length 才算百分比;拿不到就退回「下载中」文案)。
|
||||
@@ -107,10 +115,12 @@
|
||||
}
|
||||
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
const got = typeof d.fetchBytes === 'function' ? await d.fetchBytes(e.url, onProgress) : { ok: false, error: 'no-fetcher' }
|
||||
const got = typeof d.fetchBytes === 'function' ? await d.fetchBytes(e.url, onProgress, ctrl ? ctrl.signal : undefined) : { ok: false, error: 'no-fetcher' }
|
||||
if (stale()) { settle(); return publicView(e) }
|
||||
if (!got || !got.ok || !got.dataUrl) throw new Error((got && got.error) || 'fetch-failed')
|
||||
const ref = typeof d.writeRef === 'function' ? await d.writeRef(got.dataUrl) : null
|
||||
if (!ref) throw new Error('write-ref-failed')
|
||||
if (stale()) { settle(); return publicView(e) }
|
||||
active--
|
||||
setStatus(e, STATE.READY, {
|
||||
ref,
|
||||
@@ -126,6 +136,7 @@
|
||||
return publicView(e)
|
||||
} catch (err) {
|
||||
lastErr = (err && err.message) ? err.message : String(err)
|
||||
if (stale()) { settle(); return publicView(e) }
|
||||
if (attempt < maxRetries) {
|
||||
setStatus(e, STATE.DOWNLOADING, { retries: attempt + 1, lastError: lastErr })
|
||||
await sleep(Math.min(8000, 1000 * Math.pow(2, attempt)))
|
||||
@@ -133,7 +144,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stale()) { settle(); return publicView(e) }
|
||||
active--
|
||||
try { delete e.ctrl } catch (e1) { /* ignore */ }
|
||||
setStatus(e, STATE.FAILED, { retries: maxRetries, lastError: lastErr })
|
||||
pump()
|
||||
return publicView(e)
|
||||
@@ -182,6 +195,7 @@
|
||||
function retry (id) {
|
||||
const e = entries.get(id)
|
||||
if (!e) return null
|
||||
e.runSeq = (e.runSeq || 0) + 1 // 旧运行作废(回包晚到不覆盖新状态)
|
||||
e.retries = 0
|
||||
setStatus(e, STATE.QUEUED, { lastError: '' })
|
||||
queue.push(id)
|
||||
@@ -193,6 +207,9 @@
|
||||
function cancel (id) {
|
||||
const e = entries.get(id)
|
||||
if (!e) return null
|
||||
e.runSeq = (e.runSeq || 0) + 1
|
||||
try { if (e.ctrl && typeof e.ctrl.abort === 'function') e.ctrl.abort() } catch (eC) { /* ignore */ }
|
||||
try { delete e.ctrl } catch (eD) { /* ignore */ }
|
||||
const at = queue.indexOf(id)
|
||||
if (at >= 0) queue.splice(at, 1)
|
||||
if (e.status === STATE.QUEUED || e.status === STATE.DOWNLOADING) setStatus(e, STATE.LINK_ONLY, { lastError: 'cancelled' })
|
||||
@@ -270,8 +287,8 @@
|
||||
} catch (e) { resolve('') }
|
||||
})
|
||||
}
|
||||
async function fetchWithProgress (url, onProgress) {
|
||||
const res = await fetch(url)
|
||||
async function fetchWithProgress (url, onProgress, signal) {
|
||||
const res = await fetch(url, signal ? { signal: signal } : undefined)
|
||||
if (!res || !res.ok) throw new Error('http-' + String((res && res.status) || 'error'))
|
||||
const total = Number(res.headers && res.headers.get && res.headers.get('content-length')) || 0
|
||||
let blob = null
|
||||
@@ -300,7 +317,7 @@
|
||||
function createFetchBytes (deps) {
|
||||
const d = deps || {}
|
||||
const timeoutMs = Math.max(1000, Number(d.timeoutMs) || 300000)
|
||||
return async function fetchBytes (url, onProgress) {
|
||||
return async function fetchBytes (url, onProgress, signal) {
|
||||
// 2026-12-03(用户裁定):优先用系统网络栈(Rust reqwest)—— 不受 CORS/WebView 限制,
|
||||
// 图床/CDN 对 XHR 的限速、挂起、防盗链都不会再影响下载。拿不到再退回 WebView fetch。
|
||||
if (typeof d.rustFetch === 'function') {
|
||||
@@ -314,7 +331,9 @@
|
||||
} catch (eR) { /* 非 Tauri / 命令缺失 → 回退 WebView fetch */ }
|
||||
}
|
||||
let timer = null
|
||||
const job = fetchWithProgress(url, onProgress).catch(async () => {
|
||||
const job = fetchWithProgress(url, onProgress, signal).catch(async () => {
|
||||
// 用户取消(abort)导致的失败:不要回退再抓一次,直接按中止返回。
|
||||
if (signal && signal.aborted) return { ok: false, error: 'aborted' }
|
||||
const blob = await d.blobFromSrc(url)
|
||||
const dataUrl = blob ? await d.blobToDataUrl(blob) : ''
|
||||
return dataUrl ? { ok: true, dataUrl, mime: String((blob && blob.type) || '') } : { ok: false, error: 'empty-bytes' }
|
||||
|
||||
@@ -961,11 +961,12 @@
|
||||
var localSrc = (r && r.idb && r.data) ? r.data : ((r && r.url && outThumbCache.get(r.url)) || null)
|
||||
if (localSrc) { try { var u = wPreviewUrlOf(pick(localSrc, need)); if (u) return u } catch (eL) { /* ignore */ } }
|
||||
if (ingSt && ingSt.localUrl) return ingSt.localUrl // 缩略图还没好:先用本地原图,别等远程
|
||||
// 方案 A:新图还在排队/下载/失败时**不直连远程**(否则浏览器再下一次,等于双份流量);
|
||||
// 只有「没有落地记录」(旧数据)或「已 ready 但本地 URL 尚未解析」才允许远程兜底。
|
||||
if (r._awaitUrl) return r.url
|
||||
if (!ingSt || ingSt.status === 'ready') return r.url
|
||||
return undefined // 未落地:不设 src(React 省略属性),避免空 src 触发一次伪请求/伪错误
|
||||
// 2026-12-03(用户):只有「没有落地记录」的旧数据才允许直连远程。
|
||||
// 已 ready 但本地 URL 还没解析出来的那一小段时间里空着等本地(缩略图已在上面返回),
|
||||
// 不要退回远程 —— 否则新图会「从上往下」渐进重下一遍,看起来像没取原图。
|
||||
if (!ingSt) return r.url
|
||||
return undefined // 未落地/本地 URL 待解析:不设 src(React 省略属性),避免空 src 触发伪请求
|
||||
})(), draggable: true, style: { aspectRatio: (r.width && r.height) ? String(r.width) + ' / ' + String(r.height) : undefined }, title: r.idb && r.data ? '单击选中 · 双击查看原图 · 拖到画布作参考图' : '单击选中 · 双击放大(可左右切换)· 拖到画布作参考图', onError: (e) => {
|
||||
// 2026-12-02:多级回退 —— 本地 blob 失效 → 远程 url;远程也失败才标 is-broken
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user