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( - - - - - + + + + + + + + , document.getElementById('root') diff --git a/webapp/pages/board-editor.jsx b/webapp/pages/board-editor.jsx index 07608a4..3b1bb01 100644 --- a/webapp/pages/board-editor.jsx +++ b/webapp/pages/board-editor.jsx @@ -27,14 +27,14 @@ module.exports = function (boardsAPI) { this.getBoardSettings(boards) }, getBoardSettings (boards) { - if (!this.props.params.board) return + if (!this.props.params.boardname) return this.setState({ loading: true }) - boards.getBoardSettings(boards.getMyID(), this.props.params.board, (err, s) => { + boards.getBoardSettings(boards.getMyID(), this.props.params.boardname, (err, s) => { if (err) { this.setState({ error: err, loading: false }) - } else { + } else if (this.state.loading) { this.setState({ - id: this.props.params.board, + id: this.props.params.boardname, name: s.fullname, desc: s.description, loading: false @@ -57,9 +57,9 @@ module.exports = function (boardsAPI) { save () { var boards = this.state.api var board = { - id: this.state.shortname, + id: this.state.shortname || this.props.params.boardname, fullname: this.state.name, - description: this.state.description + description: this.state.desc } this.setState({ updating: true }) boards.createBoard(board, (err) => { @@ -68,8 +68,8 @@ module.exports = function (boardsAPI) { }) }, additionalButtons () { - if (this.state.api && this.props.params.board) { - var url = '/@' + this.state.api.getMyID() + '/' + this.props.params.board + if (this.state.api && this.props.params.boardname) { + var url = '/@' + this.state.api.getMyID() + '/' + this.props.params.boardname return View @@ -85,7 +85,7 @@ module.exports = function (boardsAPI) {

Ooops

-

{this.state.error}

+

{'' + this.state.error}

@@ -93,7 +93,7 @@ module.exports = function (boardsAPI) { return
-

Fetching your current profile...

+

Fetching your current Board Settings...

@@ -117,18 +117,20 @@ module.exports = function (boardsAPI) { for your changes to be visibile. Your Boards will appear unchanged during this time.

-
- - -
-
+ {this.props.params.boardname + ?
+ :
+ + +
} +
- +
-