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:
1 parent
92370c9254
commit
7b8d755cac
8 files changed
+95
-51
No files matched your search
@@ -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)
|
||||
Reference in new issue
Block a user