Skip to content

Commit

Permalink
Merge pull request maidsafe-archive#142 from shankar2105/for-safebrow…
Browse files Browse the repository at this point in the history
…ser-0.4.0

fix/support_latest_safe_browser: update to support latest safe browser 0.4.0
  • Loading branch information
hitman401 authored Nov 15, 2016
2 parents 75aadb4 + 5f84699 commit f78f2e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
23 changes: 13 additions & 10 deletions editable_comments_plugin/comments/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
}
return text
}

function extractHandle(res) {
return res.hasOwnProperty('handleId') ? res.handleId : res.__parsedResponseBody__.handleId;
}
//
// The Controller holds the data and is the bridge to interact with
// SAFE.
Expand Down Expand Up @@ -61,7 +65,7 @@
// Once all is linked up, this is called to start up the connection
// to save
init () {
this._authToken = window.safeAuth.getAuthToken(this._LOCAL_STORAGE_TOKEN_KEY)
// this._authToken = window.safeAuth.getAuthToken(this._LOCAL_STORAGE_TOKEN_KEY)
// check if we have a local auth token
return (this._authToken
// if so, skip ahead to load DNS
Expand Down Expand Up @@ -107,7 +111,7 @@
// create appendable dataHandleId for location
return window.safeAppendableData.create(this._authToken, this._getLocation(), false)
// remap handleID
.then((res) => res.__parsedResponseBody__.handleId)
.then(extractHandle)
.then((handleId) =>
// now put the handleID, this actually creates the appendableData
window.safeAppendableData.put(this._authToken, handleId)
Expand Down Expand Up @@ -193,15 +197,15 @@
MODULE.log('Fetch appendable data length')
return window.safeAppendableData.getMetadata(
this._authToken, this._currentPostHandleId)
.then((res) => res.__parsedResponseBody__.dataLength)
.then((res) => res.hasOwnProperty('dataLength') ? res.dataLength : res.__parsedResponseBody__.dataLength)
}

// fetch the actual appendableData
const fetchCommentsListing = (dataHandleId) => {
MODULE.log('Fetch appendable data')
return window.safeAppendableData.getHandle(
this._authToken, dataHandleId)
.then((res) => { this._currentPostHandleId = res.__parsedResponseBody__.handleId })
.then((res) => { this._currentPostHandleId = extractHandle(res) })
}

// tying it all together
Expand Down Expand Up @@ -397,7 +401,7 @@
return window.safeCipherOpts.getHandle(
this._authToken,
window.safeCipherOpts.getEncryptionTypes().SYMMETRIC)
.then(res => { this._symmetricCipherOptsHandle = res.__parsedResponseBody__.handleId })
.then(res => { this._symmetricCipherOptsHandle = extractHandle(res) })
}

//
Expand Down Expand Up @@ -435,7 +439,7 @@
(dataHandle) => window.safeStructuredData.getHandle(this._authToken, dataHandle),
// release dataHandle
(dataHandle) => window.safeDataId.dropHandle(this._authToken, dataHandle))
.then(res => res.__parsedResponseBody__.handleId)
.then(extractHandle)
.then(handleId => {
// keep the structured data handle around for later reuse
this._blockedUserStructureDataHandle = handleId
Expand Down Expand Up @@ -530,7 +534,7 @@
this._getLocation() + '_blocked_users', 500,
new Buffer(JSON.stringify(this._data.blockedUsers)).toString('base64'),
this._symmetricCipherOptsHandle)
.then(res => { this._blockedUserStructureDataHandle = res.__parsedResponseBody__.handleId })
.then(res => { this._blockedUserStructureDataHandle = extractHandle(res) })
.then(res => window.safeStructuredData.put(
this._authToken,
this._blockedUserStructureDataHandle)
Expand All @@ -546,7 +550,6 @@
MODULE.log('Fetching DNS records')
return window.safeDNS.listLongNames(this._authToken)
// convert
.then((res) => res.__parsedResponseBody__)
.then((dnsData) => {
// store dnsData on the user for later reuse
this._data.user.dns = dnsData
Expand All @@ -572,7 +575,7 @@
// convert tokeb
.then((res) => {
if (typeof res === 'object') {
return res.__parsedResponseBody__.token
return res.hasOwnProperty('token') ? res.token : res.__parsedResponseBody__.token
}
return res;
})
Expand All @@ -582,7 +585,7 @@
}
// keep token for later reus`e
this._authToken = token
window.safeAuth.setAuthToken(this._LOCAL_STORAGE_TOKEN_KEY, token)
// window.safeAuth.setAuthToken(this._LOCAL_STORAGE_TOKEN_KEY, token)
})
// then refresh the DNS
.then(() => this._getDns())
Expand Down
27 changes: 16 additions & 11 deletions permanent_comments_plugin/comments/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
}
return text
}

function extractHandle(res) {
return res.hasOwnProperty('handleId') ? res.handleId : res.__parsedResponseBody__.handleId;
}

//
// The Controller holds the data and is the bridge to interact with
// SAFE.
Expand Down Expand Up @@ -61,7 +66,7 @@
// Once all is linked up, this is called to start up the connection
// to save
init () {
this._authToken = window.safeAuth.getAuthToken(this._LOCAL_STORAGE_TOKEN_KEY)
// this._authToken = window.safeAuth.getAuthToken(this._LOCAL_STORAGE_TOKEN_KEY)
// check if we have a local auth token
return (this._authToken
// if so, skip ahead to load DNS
Expand Down Expand Up @@ -107,7 +112,7 @@
// create appendable dataHandleId for location
return window.safeAppendableData.create(this._authToken, this._getLocation(), false)
// remap handleID
.then((res) => res.__parsedResponseBody__.handleId)
.then(extractHandle)
.then((handleId) =>
// now put the handleID, this actually creates the appendableData
window.safeAppendableData.put(this._authToken, handleId)
Expand Down Expand Up @@ -154,15 +159,15 @@
MODULE.log('Fetch appendable data length')
return window.safeAppendableData.getMetadata(
this._authToken, this._currentPostHandleId)
.then((res) => res.__parsedResponseBody__.dataLength)
.then((res) => (res.hasOwnProperty('dataLength') ? res.dataLength : res.__parsedResponseBody__.dataLength))
}

// fetch the actual appendableData
const fetchCommentsListing = (dataHandleId) => {
MODULE.log('Fetch appendable data')
return window.safeAppendableData.getHandle(
this._authToken, dataHandleId)
.then((res) => { this._currentPostHandleId = res.__parsedResponseBody__.handleId })
.then((res) => { this._currentPostHandleId = extractHandle(res) })
}

// tying it all together
Expand Down Expand Up @@ -325,7 +330,7 @@
return window.safeCipherOpts.getHandle(
this._authToken,
window.safeCipherOpts.getEncryptionTypes().SYMMETRIC)
.then(res => { this._symmetricCipherOptsHandle = res.__parsedResponseBody__.handleId })
.then(res => { this._symmetricCipherOptsHandle = extractHandle(res) })
}

//
Expand All @@ -336,7 +341,7 @@
//
_autoRelease (promise, fn, release) {
return promise
.then(res => res.__parsedResponseBody__ ? res.__parsedResponseBody__.handleId : res)
.then(extractHandle)
.then(handleId => fn(handleId)
.then((r) => release(handleId).then(() => r),
(e) => release(handleId).then(() => Promise.reject(e)
Expand All @@ -353,7 +358,7 @@
(dataHandle) => window.safeStructuredData.getHandle(this._authToken, dataHandle),
// release dataHandle
(dataHandle) => window.safeDataId.dropHandle(this._authToken, dataHandle))
.then(res => res.__parsedResponseBody__.handleId)
.then(extractHandle)
.then(handleId => {
// keep the structured data handle around for later reuse
this._blockedUserStructureDataHandle = handleId
Expand Down Expand Up @@ -444,7 +449,7 @@
this._getLocation() + '_blocked_users', 500,
new Buffer(JSON.stringify(this._data.blockedUsers)).toString('base64'),
this._symmetricCipherOptsHandle)
.then(res => { this._blockedUserStructureDataHandle = res.__parsedResponseBody__.handleId })
.then(res => { this._blockedUserStructureDataHandle = extractHandle(res) })
.then(res => window.safeStructuredData.put(
this._authToken,
this._blockedUserStructureDataHandle)
Expand All @@ -459,7 +464,7 @@
MODULE.log('Fetching DNS records')
return window.safeDNS.listLongNames(this._authToken)
// convert
.then((res) => res.__parsedResponseBody__)
.then((res) => (res.hasOwnProperty('__parsedResponseBody__') ? res.__parsedResponseBody__ : res))
.then((dnsData) => {
// store dnsData on the user for later reuse
this._data.user.dns = dnsData
Expand All @@ -486,7 +491,7 @@
// convert tokeb
.then((res) => {
if (typeof res === 'object') {
return res.__parsedResponseBody__.token
return res.hasOwnProperty('token') ? res.token : res.__parsedResponseBody__.token
}
return res;
})
Expand All @@ -496,7 +501,7 @@
}
// keep token for later reus`e
this._authToken = token
window.safeAuth.setAuthToken(this._LOCAL_STORAGE_TOKEN_KEY, token)
// window.safeAuth.setAuthToken(this._LOCAL_STORAGE_TOKEN_KEY, token)
})
// then refresh the DNS
.then(() => this._getDns())
Expand Down

0 comments on commit f78f2e9

Please sign in to comment.