feat(ref): 上传图库移到气泡(图标 ref);移除气泡改名;本地图隐藏 URL 行
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 54s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 54s
This commit is contained in:
1 parent
87bb2f9c19
commit
719b810091
12 files changed
+78
-57
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/* ref-upload.js —— 参考图节点「上传到图库」动作(2026-12-04)
|
||||
*
|
||||
* 从 app.js 的节点气泡里抽出:气泡是装配层,逻辑放模块里(app.js 行数棘轮)。
|
||||
* 依赖全部注入:fetchBlob(Rust 优先)/ blobToDataUrl / uploadRef / config / updateNode / notice。
|
||||
*/
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
function create (deps) {
|
||||
const d = deps || {}
|
||||
const uploading = new Set()
|
||||
const run = async (node, opts) => {
|
||||
if (!node || node.type !== 'ref' || uploading.has(node.id)) return false
|
||||
const data = node.data || {}
|
||||
const hasLocal = !!(data.data || data.localRef)
|
||||
const hasUrl = typeof data.url === 'string' && data.url
|
||||
if (!hasLocal && !hasUrl) return false
|
||||
const o = opts || {}
|
||||
uploading.add(node.id)
|
||||
try {
|
||||
let payload = data.data || data.localRef || null
|
||||
if (!payload) {
|
||||
let blob = await d.fetchBlob(data.url)
|
||||
if (!blob || !blob.size) {
|
||||
try { const r = await d.fetch(data.url, { credentials: 'same-origin' }); if (r && r.ok) blob = await r.blob() } catch (e) { /* ignore */ }
|
||||
}
|
||||
if (!blob || !blob.size) throw new Error('图片下载失败')
|
||||
payload = await d.blobToDataUrl(blob)
|
||||
}
|
||||
if (typeof o.notice === 'function') o.notice('正在上传到图库…')
|
||||
const url = await d.uploadRef(payload, d.config(), data.name)
|
||||
if (typeof o.updateNode === 'function') o.updateNode(node.id, { url: url, data: null, localRef: null, localName: null, name: String(url).split('/').pop() || '在线图片' })
|
||||
if (typeof o.notice === 'function') o.notice('已上传到图库并填入链接')
|
||||
return true
|
||||
} catch (e) {
|
||||
if (typeof o.notice === 'function') o.notice('上传失败:' + String((e && e.message) || e), 'err')
|
||||
return false
|
||||
} finally { uploading.delete(node.id) }
|
||||
}
|
||||
return { run: run, isUploading: (id) => uploading.has(id) }
|
||||
}
|
||||
global.IWBRefUpload = { create: create }
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
Reference in new issue
Block a user