graflow: loadNodes is triple modes now: url, blob or object

This commit is contained in:
STEINNI
2026-04-10 13:31:39 +00:00
parent 90f45c2c8d
commit 511562c502
+18 -11
View File
@@ -109,24 +109,32 @@ class BZgraflow extends Buildoz{
} }
async loadFlow(source){ async loadFlow(source){
let buf let buf, flowObj
if(source instanceof Blob){ if(source instanceof Blob){
buf = await source.text() 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{ try{
flowObj = JSON.parse(buf) flowObj = JSON.parse(buf)
} catch(err){ } catch(err){
this.error('Could not parse flow JSON!?', err) this.error('Could not parse flow JSON!?', err)
return return
} }
} else if(typeof source == 'string') {
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()
try{
flowObj = JSON.parse(buf)
} catch(err){
this.error('Could not parse flow JSON!?', err)
return
}
} else if(typeof source == 'object') {
flowObj = source
}
if(!flowObj.nodesFile){ if(!flowObj.nodesFile){
this.error('No nodesFile in JSON!?') this.error('No nodesFile in JSON!?')
return return
@@ -450,7 +458,6 @@ class BZgraflow extends Buildoz{
else this.currentOrientation = 'vertical' else this.currentOrientation = 'vertical'
} }
} }
console.log('forceAutoplace', forceAutoplace, this.currentOrientation)
if(forceAutoplace) this.autoPlace(this.currentOrientation, parseInt(this.getBZAttribute('gapx')) || 80, parseInt(this.getBZAttribute('gapy')) || 80) if(forceAutoplace) this.autoPlace(this.currentOrientation, parseInt(this.getBZAttribute('gapx')) || 80, parseInt(this.getBZAttribute('gapy')) || 80)
this.fireEvent('refreshed', { }) this.fireEvent('refreshed', { })
} }