Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
// Load model from public
nsfwjs.load('/model/').then(model => {
this.setState({
model,
titleMessage: dragMessage,
message: 'Ready to Classify',
loading: false
})
})
}
async function nsfw () {
const model = await require('nsfwjs').load(chrome.extension.getURL('assets/nsfw/'))
Message.listen('nsfw', async (pl, sdr, res) => {
const image = new Image()
image.src = pl
try {
await new Promise((onload, onerror) => Object.assign(image, { onload, onerror })) // eslint-disable-line promise/param-names
res(await model.classify(image))
} catch (e) {
res(null)
}
})
}
nsfw()
async init () {
this.model = await nsfwjs.load()
}
}