diff --git a/lib/boards-api.js b/lib/boards-api.js
index 81ecef7..055a60f 100644
--- a/lib/boards-api.js
+++ b/lib/boards-api.js
@@ -261,7 +261,10 @@ BoardsAPI.prototype.deleteComment = function (hash, parent, done) {
BoardsAPI.prototype.cat = function (path, done) {
if (this.limited) {
// Download via gateway
- if (path.indexOf('/ipfs/') !== 0) path = '/ipfs/' + path
+ if (path.indexOf('Qm') === 0) {
+ path = '/ipfs/' + path
+ }
+ console.log('Downloading via Gateway: ', path)
wreck.get(path, (err, res, payload) => {
console.log('GET:', err, res, payload)
if (payload.toString) payload = payload.toString()
@@ -291,8 +294,13 @@ BoardsAPI.prototype.backupCache = function () {
}
// Rewrote this to use event emitters. Should also add periodic rechecking
+// TODO: maybe drop this entirely? We can cat and ls IPNS names now.
BoardsAPI.prototype.resolveIPNS = function (n, handler) {
if (handler && handler.apply) this.ee.on(n, handler)
+ if (this.limited) {
+ // In limited mode, don't solve addresses
+ return this.ee.emit(n, '/ipns/' + n)
+ }
if (!this.resolvingIPNS[n]) {
this.resolvingIPNS[n] = true
this.ipfs.name.resolve(n, (err, r) => {
@@ -333,7 +341,7 @@ BoardsAPI.prototype.resolveIPNS = function (n, handler) {
BoardsAPI.prototype.isUserProfile = function (addr, done) {
if (addr === undefined) return console.log('Asked to check if undefined is a profile')
- this.ipfs.cat(addr + this.baseurl + 'ipfs-boards-version.txt', (err, r) => {
+ this.cat(addr + this.baseurl + 'ipfs-boards-version.txt', (err, r) => {
if (err) return done(false, err)
replyAsObj(r, false, (_, res) => {
if (!res || !res.trim) {
@@ -392,7 +400,7 @@ BoardsAPI.prototype.getProfile = function (userID, done) {
done(err, null)
} else {
// Download actual profile
- this.ipfs.cat(url + this.baseurl + 'profile.json', (err2, res) => {
+ this.cat(url + this.baseurl + 'profile.json', (err2, res) => {
if (err2) {
this.ee.emit('error', err2)
done(err2, null)
@@ -410,7 +418,7 @@ BoardsAPI.prototype.getProfile = function (userID, done) {
}
})
// Get other info
- this.ipfs.ls(url + this.baseurl + 'boards/', (err2, res) => {
+ this.ls(url + this.baseurl + 'boards/', (err2, res) => {
if (!err2) {
var l = res.Objects[0].Links.map(i => {
return { name: i.Name, hash: i.Hash }
@@ -438,7 +446,7 @@ BoardsAPI.prototype.getBoardSettings = function (userID, board, done) {
this.ee.emit('error', e)
} else {
var url = r + this.baseurl + 'boards/' + board + '/settings.json'
- this.ipfs.cat(url, (err, resp) => {
+ this.cat(url, (err, resp) => {
var settings
try {
settings = JSON.parse(resp.toString())
@@ -457,7 +465,7 @@ BoardsAPI.prototype.getBoardSettings = function (userID, board, done) {
if (settings.whitelist === true) {
// Get the whitelist
var url = r + this.baseurl + 'boards/' + board + '/whitelist'
- this.ipfs.cat(url, (err, res) => {
+ this.cat(url, (err, res) => {
if (err) {
this.ee.emit('error', err)
// Emit an empty whitelist.
@@ -479,7 +487,7 @@ BoardsAPI.prototype.getBoardSettings = function (userID, board, done) {
if (!settings.whitelist_only && !settings.approval_required && settings.blacklist === true) {
// Get the blacklist
var u = r + this.baseurl + 'boards/' + board + '/blacklist'
- this.ipfs.cat(u, (err, blacklist) => {
+ this.cat(u, (err, blacklist) => {
if (err) {
this.ee.emit('error', err)
} else {
@@ -510,7 +518,7 @@ BoardsAPI.prototype.downloadPost = function (hash, adminID, board, op, done) {
done = op
op = undefined
}
- this.ipfs.cat(hash, (err2, r) => {
+ this.cat(hash, (err2, r) => {
if (err2) {
this.ee.emit('error', err2)
console.log('Could not download post', hash, 'of', board + '@' + adminID)
@@ -537,7 +545,7 @@ BoardsAPI.prototype.downloadPost = function (hash, adminID, board, op, done) {
BoardsAPI.prototype.retrieveListOfApproved = function (what, addr, adminID, board) {
var a = addr + this.baseurl + 'boards/' + board + '/approved/' + what + '/'
- this.ipfs.ls(a, (err, res) => {
+ this.ls(a, (err, res) => {
if (err) {
this.ee.emit('error', err)
} else {
@@ -609,7 +617,7 @@ BoardsAPI.prototype.getUserPostListInBoard = function (user, board, done) {
this.ee.emit('error', err)
done(err)
} else {
- this.ipfs.ls(url + this.baseurl + 'posts/' + board, (e, r) => {
+ this.ls(url + this.baseurl + 'posts/' + board, (e, r) => {
if (e) {
this.ee.emit('error', e)
done(e)
@@ -634,7 +642,7 @@ BoardsAPI.prototype.downloadComment = function (hash, adminID, board, target, do
target = undefined
}
console.log('target', target)
- this.ipfs.cat(hash, (err2, r) => {
+ this.cat(hash, (err2, r) => {
if (err2) {
this.ee.emit('error', err2)
console.log('Could not download comment', hash, 'of', board + '@' + adminID)
@@ -660,7 +668,7 @@ BoardsAPI.prototype.getCommentsFor = function (parent, board, adminID, target) {
return console.log('malformed arguments:', parent, board, adminID)
}
// figure out if there's a previous version of the item
- this.ipfs.cat(parent, (err, res) => {
+ this.cat(parent, (err, res) => {
if (err) {
this.ee.emit('error', err)
} else {
@@ -706,7 +714,7 @@ BoardsAPI.prototype.getUserCommentList = function (parent, user, done) {
this.ee.emit('error', err)
done(err)
} else {
- this.ipfs.ls(url + this.baseurl + 'comments/' + parent, (e, r) => {
+ this.ls(url + this.baseurl + 'comments/' + parent, (e, r) => {
if (e) {
this.ee.emit('error', e)
done(e)
@@ -728,7 +736,7 @@ BoardsAPI.prototype.getUserCommentList = function (parent, user, done) {
BoardsAPI.prototype.isRunningFromGateway = function () {
if (!window) return false
- return window.location.pathname.indexOf('/ipfs/') === 0
+ return window.location.pathname.indexOf('/ipfs/') === 0 || window.location.pathname.indexOf('/ipns/') === 0
}
BoardsAPI.prototype.isNode = function () {
diff --git a/webapp/components/comment.jsx b/webapp/components/comment.jsx
index 2e4f193..1dddf58 100644
--- a/webapp/components/comment.jsx
+++ b/webapp/components/comment.jsx
@@ -53,29 +53,40 @@ var Comments = React.createClass({
return { comments: [] }
},
componentDidMount () {
- var boards = this.props.api
- if (boards) {
- boards.getEventEmitter().on('comment for ' + this.props.parent, cmnt => {
- if (this.isMounted()) this.setState({ comments: this.state.comments.concat(cmnt) })
- })
- if (boards.isInit && this.isMounted()) {
+ if (this.props.api) this.init(this.props.api)
+ },
+ componentWillReceiveProps (props) {
+ if (props.api) this.init(props.api)
+ },
+ init (boards) {
+ boards.getEventEmitter().on('comment for ' + this.props.parent, cmnt => {
+ if (this.isMounted()) this.setState({ comments: this.state.comments.concat(cmnt) })
+ })
+ boards.getEventEmitter().on('init', (err, limited) => {
+ if (!this.isMounted()) return
+ if (!err) {
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
}
- boards.getEventEmitter().on('init', err => {
- if (!err && this.isMounted()) {
- boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
- }
- })
+ if (limited) this.setState({ limited })
+ })
+ if (boards.isInit) {
+ boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
}
+ if (boards.limited) this.setState({ limited: true })
},
getComments () {
if (this.state.comments.length > 0) {
return this.state.comments.map(cmnt => (
Comments can't be displayed in limited mode
+Posts in a board can't be shown in limited mode. Sorry!
+