fix(plugins): pluginFilePut 解包 dataURL 取 bytes 字段(封面文件化生效)+ promptlib 1.6.4
This commit is contained in:
1 parent
61597deb2b
commit
8e19e7322f
5 files changed
+38
-8
No files matched your search
+2
-2
@@ -46,8 +46,8 @@
|
||||
"style": "styles.css",
|
||||
"version": "1.5.0",
|
||||
"files": {
|
||||
"main.js": "4a22ff6ddcd0b6bbc9e412d2b6c8ff8aaf3e6cd747086aa348f96bb0b3e0dacd",
|
||||
"styles.css": "f43fa0e8fca78281616de8ea574422bccc7a2dba3951f648edad021aa6730a0b"
|
||||
"main.js": "b3a51ab93f1993c014bd1f3571c371b1eab3b5079624934203eb1ad316dab50c",
|
||||
"styles.css": "271787ac71d8adcac862b8e65ae9f69002eb72c81d2d8b2abc941a3d93c356dc"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"提示词"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "4a22ff6ddcd0b6bbc9e412d2b6c8ff8aaf3e6cd747086aa348f96bb0b3e0dacd",
|
||||
"styles.css": "f43fa0e8fca78281616de8ea574422bccc7a2dba3951f648edad021aa6730a0b"
|
||||
"main.js": "b3a51ab93f1993c014bd1f3571c371b1eab3b5079624934203eb1ad316dab50c",
|
||||
"styles.css": "271787ac71d8adcac862b8e65ae9f69002eb72c81d2d8b2abc941a3d93c356dc"
|
||||
}
|
||||
}
|
||||
@@ -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}
|
||||
+2
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user