import flow OK

This commit is contained in:
STEINNI
2026-03-30 19:57:21 +00:00
parent 334cce8af3
commit 158e9c4044
3 changed files with 36 additions and 9 deletions

View File

@@ -99,20 +99,32 @@ class BZgraflow extends Buildoz{
}
error(msg, err){
this.innerHTML = `<div style="background:red;color:black;margin: auto;width: fit-content;">${msg}</div>`
this.querySelector('.graflow-error')?.remove()
const errorEl = document.createElement('div')
errorEl.classList.add('graflow-error')
errorEl.innerHTML = `${msg}`
this.appendChild(errorEl)
if(err) console.error(msg, err)
else console.error(msg)
}
async loadFlow(url){
const res = await fetch(url+'?'+crypto.randomUUID())
const buf = await res.text()
async loadFlow(source){
let buf
if(source instanceof Blob){
buf = await source.text()
} else {
const url = source
const fetchUrl = (typeof url === 'string' && !url.startsWith('blob:') && !url.startsWith('data:'))
? (url + '?' + crypto.randomUUID())
: url
const res = await fetch(fetchUrl)
buf = await res.text()
}
let flowObj
try{
flowObj = JSON.parse(buf)
} catch(err){
this.error('Could not parse flow JSON!?', err)
return
}
if(!flowObj.nodesFile){
@@ -122,7 +134,7 @@ class BZgraflow extends Buildoz{
await this.loadNodes(flowObj.nodesFile)
this.flow = flowObj.flow
this.refresh()
this.fireEvent('flowLoaded', { url: url })
this.fireEvent('flowLoaded', { url: source instanceof Blob ? null : source, blob: source instanceof Blob ? source : null })
}
initFlow(){