How to filter jsreport.documentStore.collection by asset path in order to check asset exist in before render script?
-
Hi sir,
i have found below script which check asset (image) exist, if asset not exist then an alternate image will be used. But in my case i have to check whether an asset exist in particular path.But i dont know how to filter document store using asset path?const jsreport = require('jsreport-proxy')
async function beforeRender(req, res) {
const logoAsset = await jsreport.documentStore.collection('assets').findOne({ name: 'logo.png' })
if (logoAsset) {
req.data.logoAsest = 'logo.png'
} else {
req.data.logoAsest = 'another.png'
}
}Could you please reply with an example?
-
here you go https://playground.jsreport.net/w/anon/BT8c5wg4
async function beforeRender (req, res) { const jsreport = require('jsreport-proxy') const searchResult = await jsreport.folders.resolveEntityFromPath('/myasset.txt', 'assets') if (searchResult) { req.template.content = searchResult.entity.content.toString() } }