Thanks @Bruce Bullis ; with your help I was able to achieve my goal!
There were a couple of gotchas, like remembering to enable Node.js in the manifest:
<CEFCommandLine>
<Parameter>--enable-nodejs</Parameter>
<Parameter>--mixed-context</Parameter>
</CEFCommandLine>
or using
const fs = cep_node.require('fs')
instead of just
const fs = require('fs')
In the end, here is what I came up with, in case it helps anyone in the future:
export const importInPremiere = async ({ url, name }) => {
/**
* Initialize CSInterface
*/
const { CSInterface } = require('@cep/csinterface')
const csInterface = new CSInterface()
/**
* Create temporary directory
*/
const tempFolder = '/tmp/adobe_cep_panel'
window.cep.fs.makedir(tempFolder)
const filePath = `${tempFolder}/${name}`
/**
* Open file
*/
const fs = window.cep_node.require('fs')
const file = fs.createWriteStream(filePath)
/**
* Fetch ressource as stream
*/
const response = await fetch(url)
const reader = response.body.getReader()
while (true) {
/**
* Read stream chunks
*/
const { value, done } = await reader.read()
if (done) {
/**
* Close file
*/
file.end()
/**
* Send file path to JSX for import into Premiere
*/
csInterface.evalScript(`importFile("${filePath}")`)
break
}
/**
* Write stream chunks to file
*/
file.write(value)
}
}