Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
;(async (argv) => {
let ipfs
try {
if (argv['ipfs-api']) {
// --ipfs-api option
const IPFS = require('ipfs-http-client')
const addr = multiaddr(argv['ipfs-api'])
const nodeAddress = addr.nodeAddress()
ipfs = new IPFS(nodeAddress.address, nodeAddress.port)
} else {
const IPFS = require('ipfs')
ipfs = await IPFS.create({ start: false })
}
} catch (e) {
console.error(e)
throw new Error('Please use npm to install either `ipfs` or `ipfs-http-client`.')
}
// Register new MIME type for .ambient files
mime.extensions['text/ambients'] = ['ambient']
mime.types.ambient = 'text/ambients'
const file = fs.readFileSync(argv.input).toString().trim()
let result
switch (mime.lookup(argv.input)) {
case 'application/javascript':
result = await output(ipfs, file, argv); break