/*IPFS Start */
document.addEventListener('DOMContentLoaded', async () => {
	const node = await Ipfs.create({ repo: 'ipfs-' + Math.random() })
	window.node = node;

	const status = node.isOnline() ? 'online' : 'offline';

	console.log(`Node status: ${status}`);

	/* You can write more code here to use it. Use methods like
	node.add, node.get. See the API docs here:
	https://github.com/ipfs/js-ipfs/tree/master/packages/interface-ipfs-core */
   
})

async function addFile (dataString) {
	const { cid } = await node.add(dataString);
	console.log('successfully stored', cid);
	return cid;
}

async function catFile (fileCID) {
	for await (const data of node.cat(fileCID)) {
		console.log(data.toString());
		return data.toString();
	}
}