fix(download): 出图不再弹「另存为」;自动下载改为从图库原图复制 v3.25.33

① 删除 runtime-workbench-logic 里遗留的逐张自动下载(默认开、无 UI 开关),
   它走交互式 downloadUrl:写失败回退 dialog.save(默认路径是旧目录)→ 每张都弹框;
   四级兜底最后一级 openExternal → 弹出浏览器、落到浏览器下载目录。
② wSaveBlobNative 弹框只由「有没有导出目录」决定:有目录静默写,失败先 grant_dir
   重授权重试,仍失败只 toast;没目录才弹一次选位置。
③ archiveGenerationResults 改为「归档 → 刷新 → 自动下载」串行;wAddOutputs 新增
   awaitArchive 等本批原图落盘;resolveSrc 按 url 回查图库索引取 out_orig_ 原图,
   本地命中不碰图床;dataURL 直接解码 Blob。
④ 删除死代码 wSaveGenImageToDir。

app.js 行数 8947(守门上限内)。verify: build/check-dist/lint/typecheck/test:unit 全过。
This commit is contained in:
qiqi committed 2026-11-19 16:46:35 +08:00
1 parent 92370c9254
commit 7b8d755cac
8 files changed
+95 -51

No files matched your search

+31 -4
View File
@@ -17,6 +17,7 @@
* getDir() → 当前下载目录(空串表示未设置)
* isOn() → 自动下载开关
* resolveSrc(item) → Promise<dataURL|url>(本地归档优先)
* toBlob(src) → Promise<Blob|null>(可选:dataURL 直接解码,返回 null 表示交给 fetch)
* write(dir, name, blob) → Promise<boolean>
* toast(msg, type) → void
*/
@@ -25,6 +26,7 @@
const getDir = typeof d.getDir === 'function' ? d.getDir : function () { return '' }
const isOn = typeof d.isOn === 'function' ? d.isOn : function () { return false }
const resolveSrc = typeof d.resolveSrc === 'function' ? d.resolveSrc : null
const toBlob = typeof d.toBlob === 'function' ? d.toBlob : null
const write = typeof d.write === 'function' ? d.write : null
const toast = typeof d.toast === 'function' ? d.toast : function () {}
@@ -47,9 +49,14 @@
try {
const src = await resolveSrc(item)
if (!src) { failed++; continue }
const resp = await fetch(src)
if (!resp || !resp.ok) { failed++; continue }
const blob = await resp.blob()
// 本地原图(dataURL)直接解码成 Blob,不再 fetch(dataURL);远程 URL 才走 fetch
let blob = null
if (toBlob) { try { blob = await toBlob(src) } catch (e) { blob = null } }
if (!blob) {
const resp = await fetch(src)
if (!resp || !resp.ok) { failed++; continue }
blob = await resp.blob()
}
const name = genName()
const ok = await write(getDir(), name, blob)
if (ok) saved++
@@ -64,5 +71,25 @@
}
}
g.IWBDownloadAuto = Object.freeze({ create })
/**
* 本地优先解析(v3.25.33):出图结果条目自身没有 origIdb(图库条目才有),
* 按 url 回查图库索引取「已落盘的原图」;本地命中就完全不碰图床,
* 图床 CORS/超时/403 不再影响自动保存。
* deps: resolveDirect(item) / listFiles() / readIdb(key)
*/
async function resolveLocalFirst (item, deps) {
if (!item) return ''
const d = deps || {}
const direct = d.resolveDirect ? await d.resolveDirect(item) : ''
if (direct && String(direct).indexOf('data:') === 0) return direct
try {
const files = d.listFiles ? await d.listFiles() : []
const hit = (files || []).find((x) => x && item.url && String(x.url) === String(item.url))
if (hit && hit.origIdb && d.readIdb) { const v = await d.readIdb(hit.origIdb); if (v) return v }
if (hit && hit.data) return hit.data
} catch (e) { /* 回查失败退回 direct */ }
return direct
}
g.IWBDownloadAuto = Object.freeze({ create, resolveLocalFirst })
})(typeof window !== 'undefined' ? window : globalThis)
+8 -9
View File
@@ -18,7 +18,7 @@
const React = global.React || {}
// ── app.js 模块级依赖(inject 一次性注入)─────────────────────────
let GEN_HARD_TIMEOUT_MIN, GEN_HARD_TIMEOUT_MS, GEN_TIMEOUT_MS, NODE_W, RuntimeExecutionContext, RuntimeRunContext, api, apiErrorMessage, archiveGenerationResults, bcNotify, buildGenerationTasks, classifyErr, createGenerationJobs, createGenerationResultEntry, createGenerationSnapshot, deriveGenerationRunStatus, downloadUrl, expandPromptVars, generationConcurrency, generationRunCleanupKeys, iwError, iwErrorFrom, iwbDebugCounter, normalizeGenerationResult, playDoneSound, prepareBrowserNotifications, resumeVariantPlan, runGenerationJobs, runWithConcurrency, sizeCheck, standardSizeOf, upsertGenerationEntry, wLog, wRawCfg, wResolveRefArgs, DEFAULTS, NODE_TYPES, buildLayerPrompt, isImageProducer, layerImageValue, layerInputsOf, layerPriceOf, layerSizeParam, nodeTypeH, nodeWidth, notifyBrowserGenerationDone, uiZoom, uid, wImgRefDataUrl, ImageFormat, wBlobFromSrc, wImgBlobToDataUrl, CrashLog, StorageMigrations
let GEN_HARD_TIMEOUT_MIN, GEN_HARD_TIMEOUT_MS, GEN_TIMEOUT_MS, NODE_W, RuntimeExecutionContext, RuntimeRunContext, api, apiErrorMessage, archiveGenerationResults, bcNotify, buildGenerationTasks, classifyErr, createGenerationJobs, createGenerationResultEntry, createGenerationSnapshot, deriveGenerationRunStatus, expandPromptVars, generationConcurrency, generationRunCleanupKeys, iwError, iwErrorFrom, iwbDebugCounter, normalizeGenerationResult, playDoneSound, prepareBrowserNotifications, resumeVariantPlan, runGenerationJobs, runWithConcurrency, sizeCheck, standardSizeOf, upsertGenerationEntry, wLog, wRawCfg, wResolveRefArgs, DEFAULTS, NODE_TYPES, buildLayerPrompt, isImageProducer, layerImageValue, layerInputsOf, layerPriceOf, layerSizeParam, nodeTypeH, nodeWidth, notifyBrowserGenerationDone, uiZoom, uid, wImgRefDataUrl, ImageFormat, wBlobFromSrc, wImgBlobToDataUrl, CrashLog, StorageMigrations
// 唯一的可变模块级状态:getter/setter 注入(模块内 1 读 1 写)
/** @type {{ get: () => number, set: (v: number) => void }} */
let selfSaveAt = { get: () => 0, set: () => {} }
@@ -40,7 +40,6 @@
createGenerationResultEntry = D.createGenerationResultEntry
createGenerationSnapshot = D.createGenerationSnapshot
deriveGenerationRunStatus = D.deriveGenerationRunStatus
downloadUrl = D.downloadUrl
expandPromptVars = D.expandPromptVars
generationConcurrency = D.generationConcurrency
generationRunCleanupKeys = D.generationRunCleanupKeys
@@ -371,14 +370,14 @@
const snapshot = createGenerationSnapshot(j, node.data, runWorkspaceId, nodeId)
const entry = createGenerationResultEntry(j, res, snapshot)
results[idx0] = entry
// 流式展示与自动保存都逐张执行,不等待整个批次。
// 流式展示逐张执行,不等待整个批次。
liveUpsert(j.t.id, j.i, entry)
if (!(refs.config && refs.config.canvas && refs.config.canvas.autoSaveImages === false)) {
const okImgs = (entry.items || []).filter((r) => r && r.ok && r.url)
// 自动下载并发上限 3:原来每张各自 setTimeout 发起,批量出图时会同时抓取数十张原图 → 内存尖峰
const dl = okImgs.map((r, i) => ({ url: r.url, name: 'gen_' + String(j.t.id || 'task').replace(/[^a-zA-Z0-9_-]/g, '_') + '_' + (j.i + i + 1) + '.png' }))
if (dl.length) runWithConcurrency(dl, 3, (x) => downloadUrl(x.url, x.name)).catch(() => {})
}
// 出图后的自动保存统一由 archiveGenerationResults → wAutoSaver 负责:先等图库归档完成,
// 再从本地原图字节(images/gallery 的 out_orig_)复制到导出目录。
// 这里过去调用交互式 downloadUrl(),导致两个线上问题:
// ① 没设导出目录或目录写失败 → 每张图都弹系统「另存为」框(且默认路径是旧目录);
// ② 图床 CORS/超时导致取字节全失败 → 兜底④ 调 openExternal 弹出浏览器,落到浏览器下载目录。
// 交互式下载只保留给用户主动点「下载」。
scheduledEntries[idx0] = entry
return entry
}