diff --git a/lib/boards-api.js b/lib/boards-api.js
index d908936..fc6537d 100644
--- a/lib/boards-api.js
+++ b/lib/boards-api.js
@@ -131,7 +131,38 @@ BoardsAPI.prototype.createProfile = function (profile, done) {
}
BoardsAPI.prototype.createBoard = function (board, done) {
-
+ console.log('Generating board:', board)
+ try {
+ var settings_str = JSON.stringify(board)
+ } catch (e) {
+ console.log('Error, invalid Board Settings:', e)
+ return done(e)
+ }
+ var dest = '/ipfs-boards-profile/boards/' + board.id + '/settings.json'
+ asyncjs.waterfall([
+ // Create required directories
+ cb => this.ipfs.files.mkdir('/ipfs-boards-profile/boards/' + board.id + '/', { p: true }, cb),
+ (e, cb) => {
+ // Remove old board files if present
+ this.ipfs.files.rm(dest, { r: true }, res => cb())
+ },
+ (cb) => {
+ // Serialize Board Settings and add to IPFS
+ this.ipfs.add(new Buffer(settings_str), cb)
+ },
+ (res, cb) => {
+ // Move Board into mfs
+ console.log('added Board Settings to IPFS:', res.Hash)
+ var spath = '/ipfs/' + res.Hash
+ this.ipfs.files.cp([spath, dest], cb)
+ },
+ (e, cb) => this.ipfs.files.stat('/', cb),
+ (res, cb) => {
+ var profile_hash = res.Hash
+ console.log('Publishing profile...')
+ this.ipfs.name.publish(profile_hash, cb)
+ }
+ ], done)
}
BoardsAPI.prototype.backupCache = function () {
@@ -248,8 +279,14 @@ BoardsAPI.prototype.getProfile = function (userID, done) {
this.ee.emit('error', err2)
done(err2, null)
} else {
- // TODO: JSON parse error handling
- var p = JSON.parse(res.toString())
+ var p
+ try {
+ p = JSON.parse(res.toString())
+ } catch (e) {
+ this.ee.emit('error', e)
+ if (done && done.apply) done(e)
+ return
+ }
this.ee.emit('profile for ' + userID, p)
done(null, p)
}
@@ -284,8 +321,14 @@ BoardsAPI.prototype.getBoardSettings = function (userID, board, done) {
} else {
var url = r + this.baseurl + 'boards/' + board + '/settings.json'
this.ipfs.cat(url, (err, resp) => {
- // TODO: error handling json conversion
- var settings = JSON.parse(resp.toString())
+ var settings
+ try {
+ settings = JSON.parse(resp.toString())
+ } catch (e) {
+ this.ee.emit('error', e)
+ if (done && done.apply) done(e)
+ return
+ }
if (err) {
this.ee.emit('error', err)
if (done && done.apply) done(err)
@@ -405,8 +448,7 @@ BoardsAPI.prototype.getPostsInBoard = function (adminID, board) {
// download posts for each user in whitelist
whitelist.forEach(item => {
this.getUserPostListInBoard(item, board, (err, postList) => {
- if (err) return
- postList.forEach(i => this.downloadPost(i.hash, adminID, board, item))
+ if (!err) postList.forEach(i => this.downloadPost(i.hash, adminID, board, item))
})
})
})
@@ -414,9 +456,7 @@ BoardsAPI.prototype.getPostsInBoard = function (adminID, board) {
this.getAllowedContentProducers(adminID, board, { posts: true })
// Get the admin's posts
this.getUserPostListInBoard(adminID, board, (err, res) => {
- if (err) {
- console.log(err)
- } else res.forEach(item => this.downloadPost(item.hash, adminID, board, adminID))
+ if (!err) res.forEach(item => this.downloadPost(item.hash, adminID, board, adminID))
})
} else {
// TODO: Download all posts in board from everyone
diff --git a/webapp/app.jsx b/webapp/app.jsx
index 4ad0185..ea31e16 100644
--- a/webapp/app.jsx
+++ b/webapp/app.jsx
@@ -26,6 +26,7 @@ var Board = require('board.jsx')(boards)
var PostPage = require('postpage.jsx')(boards)
var CommentPage = require('commentpage.jsx')(boards)
var ProfileEditor = require('profile-editor.jsx')(boards)
+var BoardEditor = require('board-editor.jsx')(boards)
// Define Main Components
@@ -90,11 +91,14 @@ ReactDOM.render(
- {this.state.error} {'' + this.state.error}Ooops
- Fetching your current profile...
+ Fetching your current Board Settings...
{this.state.error}
+{'' + this.state.error}