Skip to content

Commit

Permalink
Switch back to using dat.archive.writeFile
Browse files Browse the repository at this point in the history
With `indexing: false` - see:

dat-ecosystem-archive/dat-node#163
  • Loading branch information
jimpick committed Dec 5, 2017
1 parent c69d215 commit 085a2d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
29 changes: 12 additions & 17 deletions lib/mpl/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ var _events = require('events');

var _events2 = _interopRequireDefault(_events);

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

var _mkdirp = require('mkdirp');

var _mkdirp2 = _interopRequireDefault(_mkdirp);

var _ipfs = require('ipfs');

var _ipfs2 = _interopRequireDefault(_ipfs);
Expand All @@ -42,6 +34,11 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var hardcodedPeers = {
'1': '81bfdf7c33048ca93fa7fd3aed04335a5c0910010ce9cdcb579aed11d0310cee',
'2': '7a76619ae6e9fe39e763180f8eb009312954af5c605e839bc5db64b6f5a28b3a'
};

var Network = function (_EventEmitter) {
_inherits(Network, _EventEmitter);

Expand Down Expand Up @@ -70,7 +67,7 @@ var Network = function (_EventEmitter) {
// process.exit(1)
}
_this.datDir = process.env.DAT_DIR;
(0, _datNode2.default)(_this.datDir, function (err, dat) {
(0, _datNode2.default)(_this.datDir, { indexing: false }, function (err, dat) {
if (err) throw err; // What is the right way to handle errors here?

_this.dat = dat;
Expand Down Expand Up @@ -151,16 +148,14 @@ var Network = function (_EventEmitter) {
_this3.room.sendTo(peer, JSON.stringify(msg));

if (_this3.dat) {
_mkdirp2.default.sync(_this3.datDir + '/' + peer);
_fs2.default.writeFileSync(_this3.datDir + '/' + peer + '/lastMessage.json', JSON.stringify(msg));
_this3.dat.importFiles();
/*
this.dat.archive.writeFile('/lastMessage.json', JSON.stringify(msg), err => {
var version = _this3.dat.archive.version;
var file = '/' + peer + '/' + (version + 1) + '.json';
var json = JSON.stringify(msg, null, 2);
_this3.dat.archive.writeFile(file, json, function (err) {
if (err) {
console.error('writeFile error', err)
console.error('writeFile error', err);
}
})
*/
});
}
});

Expand Down
19 changes: 10 additions & 9 deletions src/mpl/network.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import EventEmitter from 'events'

import fs from 'fs'
import mkdirp from 'mkdirp'
import IPFS from 'ipfs'
import Room from 'ipfs-pubsub-room'
import Dat from 'dat-node'
import Automerge from 'automerge'

const hardcodedPeers = {
'1': '81bfdf7c33048ca93fa7fd3aed04335a5c0910010ce9cdcb579aed11d0310cee',
'2': '7a76619ae6e9fe39e763180f8eb009312954af5c605e839bc5db64b6f5a28b3a'
}

export default class Network extends EventEmitter {
// TODO: reimplement
// - friendly user names
Expand All @@ -33,7 +36,7 @@ export default class Network extends EventEmitter {
// process.exit(1)
}
this.datDir = process.env.DAT_DIR
Dat(this.datDir, (err, dat) => {
Dat(this.datDir, {indexing: false}, (err, dat) => {
if (err) throw err // What is the right way to handle errors here?

this.dat = dat
Expand Down Expand Up @@ -91,16 +94,14 @@ export default class Network extends EventEmitter {
this.room.sendTo(peer, JSON.stringify(msg))

if (this.dat) {
mkdirp.sync(`${this.datDir}/${peer}`)
fs.writeFileSync(`${this.datDir}/${peer}/lastMessage.json`, JSON.stringify(msg))
this.dat.importFiles()
/*
this.dat.archive.writeFile('/lastMessage.json', JSON.stringify(msg), err => {
const version = this.dat.archive.version
const file = `/${peer}/${version + 1}.json`
const json = JSON.stringify(msg, null, 2)
this.dat.archive.writeFile(file, json, err => {
if (err) {
console.error('writeFile error', err)
}
})
*/
}

})
Expand Down

0 comments on commit 085a2d8

Please sign in to comment.