Fix examples

This commit is contained in:
haad 2016-05-18 12:50:36 +02:00
parent 4cfd5367db
commit d26c19adf4
7 changed files with 23627 additions and 11575 deletions

35126
dist/orbitdb.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
'use strict';
// const ipfsd = require('ipfsd-ctl');
const IPFS = require('ipfs')
const IPFS = require('ipfs')
const OrbitDB = require('../src/OrbitDB');
const Timer = require('./Timer');

View File

@ -32,7 +32,7 @@ try {
logger.debug(`${key} | ${result}`);
logger.debug("---------------------------------------------------")
console.log('\n');
}).catch((e) => logger.error(e));
}).catch((e) => logger.error(e.stack));
};
setInterval(query, 1000);
});

View File

@ -171665,7 +171665,7 @@
if (!ipfs) throw new Error("Ipfs instance not defined");
if (!hash) throw new Error("Invalid hash: " + hash);
return ipfs.object.get(hash, { enc: 'base58' }).then(function (res) {
console.log("RES", res);
// console.log("RES", res)
return Log.fromJson(ipfs, JSON.parse(res.toJSON().Data));
});
}
@ -171772,9 +171772,16 @@
value: function fromIpfsHash(ipfs, hash) {
if (!ipfs) throw new Error("Node requires ipfs instance");
if (!hash) throw new Error("Invalid hash: " + hash);
console.log(hash);
return ipfs.object.get(hash, { enc: 'base58' }).then(function (obj) {
var f = JSON.parse(obj.toJSON().Data);
var f = void 0;
try {
f = JSON.parse(obj.toJSON().Data);
} catch (e) {
console.log("--------------");
console.log(e);
console.log(obj.toJSON());
}
// const f = JSON.parse(obj.toJSON().Data)
return Node.create(ipfs, f.payload, f.next);
});
}
@ -171838,7 +171845,7 @@
logger.debug("---------------------------------------------------");
console.log('\n');
}).catch(function (e) {
return logger.error(e);
return logger.error(e.stack);
});
};
setInterval(query, 1000);

View File

@ -2,7 +2,8 @@
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const ipfsd = require('ipfsd-ctl');
const IPFS = require('ipfs')
// const ipfsd = require('ipfsd-ctl');
const OrbitDB = require('../src/OrbitDB');
const Timer = require('./Timer');
@ -16,10 +17,14 @@ const channelName = process.argv[3] ? process.argv[3] : 'c1';
const startIpfs = () => {
return new Promise((resolve, reject) => {
ipfsd.disposableApi((err, ipfs) => {
if(err) console.error(err);
resolve(ipfs);
});
// ipfsd.disposableApi((err, ipfs) => {
// if(err) console.error(err);
// resolve(ipfs);
// });
const ipfs = new IPFS()
ipfs.goOnline(() => {
resolve(ipfs)
})
});
};

View File

@ -6,10 +6,12 @@ const path = require('path');
const assert = require('assert');
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const ipfsd = require('ipfsd-ctl');
// const ipfsd = require('ipfsd-ctl');
const OrbitDB = require('../src/OrbitDB');
const OrbitServer = require('orbit-server/src/server');
const IPFS = require('ipfs')
// Mute logging
// require('logplease').setLogLevel('ERROR');
@ -21,10 +23,10 @@ const password = '';
const startIpfs = () => {
return new Promise((resolve, reject) => {
// OrbitServer.start();
ipfsd.disposableApi((err, ipfs) => {
if(err) console.error(err);
resolve(ipfs);
});
// ipfsd.disposableApi((err, ipfs) => {
// if(err) console.error(err);
// resolve(ipfs);
// });
// ipfsd.local((err, node) => {
// if(err) reject(err);
// node.startDaemon((err, ipfs) => {
@ -32,6 +34,10 @@ const startIpfs = () => {
// resolve(ipfs);
// });
// });
const ipfs = new IPFS();
ipfs.goOnline(() => {
resolve(ipfs)
})
});
};
@ -49,8 +55,8 @@ describe('Orbit Client', function() {
ipfs = await(startIpfs());
// const str = fs.readFileSync('./test/network.json', 'utf-8');
// const networkData = new Buffer(JSON.stringify({ Data: str }));
const networkFile = await(ipfs.add(path.resolve(process.cwd(), './test/network.json')));
assert.equal(networkFile[0].Hash, network);
// const networkFile = await(ipfs.add(path.resolve(process.cwd(), './test/network.json')));
// assert.equal(networkFile[0].Hash, network);
client = await(OrbitDB.connect(network, username, password, ipfs, { allowOffline: true }));
client2 = await(OrbitDB.connect(network, username + "2", password, ipfs, { allowOffline: true }));
} catch(e) {
@ -64,6 +70,7 @@ describe('Orbit Client', function() {
after(() => {
if(db) db.delete();
if(client) client.disconnect();
if(ipfs) ipfs.goOffline();
});
/*

View File

@ -5,9 +5,10 @@ const path = require('path');
const fs = require('fs');
const Promise = require('bluebird');
const rimraf = require('rimraf')
const ipfsd = require('ipfsd-ctl');
// const ipfsd = require('ipfsd-ctl');
const OrbitDB = require('../src/OrbitDB');
const OrbitServer = require('orbit-server/src/server');
const IPFS = require('ipfs')
// Mute logging
require('logplease').setLogLevel('ERROR');
@ -21,10 +22,10 @@ const ipfsPath = '/tmp/orbittests';
const startIpfs = () => {
return new Promise((resolve, reject) => {
OrbitServer.start();
ipfsd.disposableApi((err, ipfs) => {
if(err) reject(err);
resolve(ipfs);
});
// ipfsd.disposableApi((err, ipfs) => {
// if(err) reject(err);
// resolve(ipfs);
// });
// ipfsd.local(ipfsPath, (err, node) => {
// if(err) reject(err);
// node.startDaemon((err, ipfs) => {
@ -32,6 +33,10 @@ const startIpfs = () => {
// resolve(ipfs);
// });
// });
const ipfs = new IPFS();
ipfs.goOnline(() => {
resolve(ipfs)
})
});
};
@ -43,9 +48,9 @@ describe('CounterStore', function() {
before((done) => {
rimraf.sync('./orbit-db-cache.json')
startIpfs()
.then((ipfs) => {
return ipfs.add(path.resolve(process.cwd(), './test/network.json')).then(() => ipfs)
})
// .then((ipfs) => {
// return ipfs.add(path.resolve(process.cwd(), './test/network.json')).then(() => ipfs)
// })
.then((res) => {
ipfs = res;
return Promise.map([username, username2], (login) => {