<commit_before>'use strict';

const menu = require('./lib/consoleMenu');
const orbitdb = require('./lib/orbitHandler');
const fh = require('./lib/fileHandler');
const eventify = require('./lib/eventify');
const dirty = require('dirty');

let kvdb;
let evdb;
let orb;
let dbRecord;
let ipfs;
let watcher;
const start = async function start() {
	try {
		dbRecord = dirty('./localkv.db');
		let action = await menu.openingMenu();

		switch (action.type) {

			case ('launchDefaultDatabaseConnection'):
				ipfs = await orbitdb.init('myApp');
				orb = await orbitdb.initOrb();
				kvdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'kvstore');
				evdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'eventlog');
				break;

			case ('launchDatabaseConnection'):
				ipfs = await orbitdb.init(action.data);
				orb = await orbitdb.initOrb();
				kvdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'kvstore');
				evdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'eventlog');
				break;

			case ('createDatabaseConnection'):
				let newDatabaseInfo = await menu.getDatabaseInfo();
				dbRecord.set(newDatabaseInfo.name, {
					hash: newDatabaseInfo.hash
				});
				break;

			default:
				break;
		}

		//instantiate file watcher
		//should probably ask user what path they want here
		await fh.init();
		watcher = await fh.watchRoot();
	} catch (err) {
		console.log(err);
	}
};


const main = async function() {
	try {
		await start();
		watcher.on('addDir', (path) => {
			console.log(`${path} has been added (dir)`);
		});

		watcher.on('add', path => addFile(path));


		orb.events.on('data', (dbname, event) => {
			console.log('\n\nORBITDB EVENT');
			console.log(dbname, event);

			console.log('\n\n');
		});

		/*
		eventify.prmify([{
			event: orb.events,
			type: 'data'
		}], (res) => {
			console.log('FIRED');
			console.log(JSON.stringify(res, null, 2));
		});
		 */




	} catch (err) {
		console.log(err);
	}<commit_msg>added peer listing<commit_after>'use strict';

const menu = require('./lib/consoleMenu');
const orbitdb = require('./lib/orbitHandler');
const fh = require('./lib/fileHandler');
const eventify = require('./lib/eventify');
const dirty = require('dirty');

let kvdb;
let evdb;
let orb;
let dbRecord;
let ipfs;
let watcher;
const start = async function start() {
	try {
		dbRecord = dirty('./localkv.db');
		let action = await menu.openingMenu();

		switch (action.type) {

			case ('launchDefaultDatabaseConnection'):
				ipfs = await orbitdb.init('myApp');
				orb = await orbitdb.initOrb();
				kvdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'kvstore');
				evdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'eventlog');
				break;

			case ('launchDatabaseConnection'):
				ipfs = await orbitdb.init(action.data);
				orb = await orbitdb.initOrb();
				kvdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'kvstore');
				evdb = await orbitdb.mkDB([JSON.stringify(action.data), action.type], 'eventlog');
				break;

			case ('createDatabaseConnection'):
				let newDatabaseInfo = await menu.getDatabaseInfo();
				dbRecord.set(newDatabaseInfo.name, {
					hash: newDatabaseInfo.hash
				});
				break;

			default:
				break;
		}

		//instantiate file watcher
		//should probably ask user what path they want here
		await fh.init();
		watcher = await fh.watchRoot();
	} catch (err) {
		console.log(err);
	}
};


const main = async function() {
	try {
		await start();
		setInterval(async() => {
			let peers = await ipfs.swarm.peers();
			peers.map((e) => {

				console.log(String(e.addr));
			});
		}, 1000);
		watcher.on('addDir', (path) => {
			console.log(`${path} has been added (dir)`);
		});

		watcher.on('add', path => addFile(path));


		orb.events.on('data', (dbname, event) => {
			console.log('\n\nORBITDB EVENT');
			console.log(dbname, event);

			console.log('\n\n');
		});

		/*
		eventify.prmify([{
			event: orb.events,
			type: 'data'
		}], (res) => {
			console.log('FIRED');
			console.log(JSON.stringify(res, null, 2));
		});
		 */




	} catch (err) {
		console.log(err);
	}
{'fraction_non_alphanumeric': 0.17656923814087205, 'fraction_numerical': 0.0014374700527072352, 'mean_word_length': 3.5828759604829856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2590065', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1402, 'n_words': 312}