fix(album): 文件夹超过 500 张直接中止并提示(不渲染、不卡界面)
validate / validate (push) Canceled after 0s

This commit is contained in:
qiqi committed 2026-11-30 10:05:31 +08:00
1 parent c2bf0d3f9d
commit 8dfc376ae0
1 file changed
+18 -1
+18 -1
View File
@@ -219,7 +219,7 @@
// v1.2.0:文件夹模式专用(手动刷新,不做自动监听)
const btnRefresh = el('button', { className: 'iwb-album-btn', title: '重新读取文件夹:新增的加入、消失的移除(尊重忽略名单)' }, '刷新')
const btnReload = el('button', { className: 'iwb-album-btn', title: '清空忽略名单并整本重新读取(会重置勾选)' }, '全部重载')
const folderNote = el('div', { className: 'iwb-album-foldernote' }, '文件夹监控:只读该目录 · 拖拽 / 粘贴 / 添加已隐藏')
const folderNote = el('div', { className: 'iwb-album-foldernote' }, '文件夹监控:只读该目录第一层 · 最多 500 张 · 拖拽 / 粘贴 / 添加已隐藏')
const folderPath = el('div', { className: 'iwb-album-folderpath' })
const seg = el('span', { className: 'iwb-album-seg' })
const segs = {}
@@ -273,6 +273,9 @@
// ── 文件夹模式(v1.2.0)──────────────────────────────────
// 只做手动刷新:不做文件监听(用户已确认,避免性能开销)。
// 宿主 listImages 的硬上限:只递归 1 层、最多 500 张。超限必须中止,
// 否则一次性渲染/引用几百张会把界面拖死(用户明确要求“超了要阻止执行”)。
const FOLDER_MAX = 500
function isFolderMode (node) { return ((node && node.data) || {}).sourceMode === 'folder' }
function folderOf (node) { const f = ((node && node.data) || {}).folder; return (f && typeof f.path === 'string') ? f.path : '' }
function skipOf (node) { const v = ((node && node.data) || {}).folderSkip; return Array.isArray(v) ? v.filter((x) => typeof x === 'string') : [] }
@@ -299,6 +302,12 @@
let files = []
try { files = await ctx.images.listImages(dir) } catch (e) { files = [] }
st.busy = ''
if (files && files.length >= FOLDER_MAX) {
st.sig = ''; sync(ctx, st, node, st.props)
st.hint.textContent = '该文件夹图片达到 ' + FOLDER_MAX + ' 张上限,已中止刷新(未改动现有条目)。请拆分目录或只放需要的图。'
st.hint.style.display = ''
return
}
if (!files || !files.length) {
st.sig = ''; sync(ctx, st, node, st.props)
st.hint.textContent = '文件夹不可用或没有图片(未改动现有条目)'
@@ -333,6 +342,7 @@
if (!dir) return
if (typeof confirm === 'function' && !confirm('将清空忽略名单并重新读取文件夹,确定?')) return
const files = await ctx.images.listImages(dir).catch(() => [])
if (files && files.length >= FOLDER_MAX) { st.hint.textContent = '该文件夹图片达到 ' + FOLDER_MAX + ' 张上限,已中止重载(未改动现有条目)'; st.hint.style.display = ''; return }
if (!files || !files.length) { st.hint.textContent = '文件夹不可用,未改动现有条目'; st.hint.style.display = ''; return }
update(st.props, node, { folderSkip: [], items: [], page: 0 }, true)
st.checkedMissing = false
@@ -859,6 +869,13 @@
for (const dir of picked) {
try { const got = await ctx.images.listImages(dir); for (const f of (got || [])) paths.push(f) } catch (e) { /* 单个目录失败不阻断 */ }
}
if (paths.length >= FOLDER_MAX) {
st.busy = ''
st.hint.textContent = '该文件夹图片达到 ' + FOLDER_MAX + ' 张上限,已中止导入(未添加任何图)'
st.hint.style.display = ''
st.sig = ''; sync(ctx, st, st.node, st.props)
return
}
} else paths = picked.slice()
if (!paths.length) { st.sig = ''; sync(ctx, st, st.node, st.props); return }
await addPaths(ctx, st, paths)