From 8e19e7322f34e34e254435d6e464cee47826b3aa Mon Sep 17 00:00:00 2001 From: qiqi Date: Sun, 22 Nov 2026 19:40:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(plugins):=20pluginFilePut=20=E8=A7=A3?= =?UTF-8?q?=E5=8C=85=20dataURL=20=E5=8F=96=20bytes=20=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=88=E5=B0=81=E9=9D=A2=E6=96=87=E4=BB=B6=E5=8C=96=E7=94=9F?= =?UTF-8?q?=E6=95=88=EF=BC=89+=20promptlib=201.6.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/index.json | 4 ++-- plugins/promptlib/main.js | 31 ++++++++++++++++++++++++++++--- plugins/promptlib/manifest.json | 4 ++-- plugins/promptlib/styles.css | 4 ++++ src/storage-file.js | 3 ++- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/plugins/index.json b/plugins/index.json index a0cdbab..99ad960 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -46,8 +46,8 @@ "style": "styles.css", "version": "1.5.0", "files": { - "main.js": "4a22ff6ddcd0b6bbc9e412d2b6c8ff8aaf3e6cd747086aa348f96bb0b3e0dacd", - "styles.css": "f43fa0e8fca78281616de8ea574422bccc7a2dba3951f648edad021aa6730a0b" + "main.js": "b3a51ab93f1993c014bd1f3571c371b1eab3b5079624934203eb1ad316dab50c", + "styles.css": "271787ac71d8adcac862b8e65ae9f69002eb72c81d2d8b2abc941a3d93c356dc" } }, { diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index 97e7b35..bc9acf9 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.js @@ -405,7 +405,10 @@ // 失败就等 1.5s 重试(最多 6 次);只有全部成功才落盘,避免把 dataURL 又写回去。 function convertInlineCovers (attempt) { attempt = attempt || 0 - if (!FILEAPI) return + if (!FILEAPI) { + if (attempt === 0) notify('封面迁移:文件能力不可用(ctx.promptlib.filePut=' + (ctx.promptlib && typeof ctx.promptlib.filePut) + ')', 'err') + return + } var need = prompts.filter(function (p) { return p && typeof p.cover === 'string' && p.cover.indexOf('data:') === 0 }) if (!need.length) return var failed = 0 @@ -417,13 +420,18 @@ return Promise.resolve(FILEAPI.put(name, c)).then(function (r) { if (r && r.ok) return { id: p.id, item: Object.assign({}, p, { cover: { img: name } }) } failed++ - return { id: p.id, item: p } - }).catch(function () { failed++; return { id: p.id, item: p } }) + return { id: p.id, item: p, err: (r && r.error) || '' } + }).catch(function (e) { failed++; return { id: p.id, item: p, err: String((e && e.message) || e) } }) })).then(function (rows) { if (failed && attempt < 6) { setTimeout(function () { convertInlineCovers(attempt + 1) }, 1500) return } + if (failed) { + var err = '' + rows.some(function (x) { if (x && x.err) { err = x.err; return true } return false }) + notify('封面转文件失败 ' + failed + ' 张:' + (err || '未知原因') + '(不影响使用)', 'err') + } if (!failed) { var map = {} rows.forEach(function (x) { map[x.id] = x.item }) @@ -1289,7 +1297,24 @@ if (syncTimer) clearTimeout(syncTimer) syncTimer = setTimeout(function () { varEd.sync(textIn.value) }, 200) }) + // v1.6.2:正文上方「插入变量」——在光标处插入 {变量} 并选中变量名,直接打字即可替换 + var insVarBtn = el('button', { class: 'iwb-btn iwb-btn-sm iwb-plp-insvar', title: '在光标处插入 {变量}', text: '+ 插入变量' }) + insVarBtn.addEventListener('click', function () { + var v = textIn.value + var s = (typeof textIn.selectionStart === 'number') ? textIn.selectionStart : v.length + var e = (typeof textIn.selectionEnd === 'number') ? textIn.selectionEnd : v.length + var name = s !== e ? String(v.slice(s, e)).replace(/\s+/g, '').slice(0, 24) : '新变量' + if (!name) name = '新变量' + var ins = '{' + name + '}' + textIn.value = v.slice(0, s) + ins + v.slice(e) + textIn.selectionStart = s + 1 + textIn.selectionEnd = s + 1 + name.length + textIn.focus() + dirty = true + varEd.sync(textIn.value) + }) var mid = el('div', { class: 'iwb-plp-emid' }) + mid.appendChild(el('div', { class: 'iwb-plp-etool' }, insVarBtn, el('span', { class: 'iwb-hint', text: '在光标处插入 {变量},并自动聚焦变量名' }))) mid.appendChild(textIn) mid.appendChild(varEd.node) bodyEl.appendChild(left); bodyEl.appendChild(mid) diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index c3f9525..4acb98b 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -13,7 +13,7 @@ "提示词" ], "files": { - "main.js": "4a22ff6ddcd0b6bbc9e412d2b6c8ff8aaf3e6cd747086aa348f96bb0b3e0dacd", - "styles.css": "f43fa0e8fca78281616de8ea574422bccc7a2dba3951f648edad021aa6730a0b" + "main.js": "b3a51ab93f1993c014bd1f3571c371b1eab3b5079624934203eb1ad316dab50c", + "styles.css": "271787ac71d8adcac862b8e65ae9f69002eb72c81d2d8b2abc941a3d93c356dc" } } diff --git a/plugins/promptlib/styles.css b/plugins/promptlib/styles.css index 9c1bd69..d059a6c 100644 --- a/plugins/promptlib/styles.css +++ b/plugins/promptlib/styles.css @@ -189,3 +189,7 @@ .iwb-plp-sbtns{display:flex;gap:8px;align-items:center} .iwb-plp-sopt{display:flex;gap:8px;align-items:center;font-size:12px;color:var(--iwb-text2,#4d5668)} .iwb-plp-settings{max-height:calc(100vh - 230px);overflow:auto;padding-right:4px} + +/* v1.6.2:正文上方工具行 */ +.iwb-plp-etool{display:flex;align-items:center;gap:8px} +.iwb-plp-insvar{border:1px solid var(--iwb-plp-accent,#d9d3ff);background:color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 8%,transparent);color:var(--iwb-plp-accent,#5a4bd0);font-weight:600} diff --git a/src/storage-file.js b/src/storage-file.js index c8de92e..585cbcf 100644 --- a/src/storage-file.js +++ b/src/storage-file.js @@ -594,7 +594,8 @@ async function pluginFilePut (id, name, dataUrl) { try { if (!pluginFileNameOk(name)) return { ok: false, error: '非法文件名(只允许小写字母/数字/-/_ + jpg/png/webp)' } - const bytes = dataUrlToBytes(String(dataUrl || '')) + const decoded = dataUrlToBytes(String(dataUrl || '')) + const bytes = decoded && decoded.bytes if (!bytes || !bytes.length) return { ok: false, error: '图片数据为空' } const stat = await pluginFileStat(id) const existing = stat.files.find((f) => f.name === name)