Skip to content

Commit

Permalink
Dynamic SF|Extension registration, handle 000 decode
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Jul 26, 2017
1 parent e9092c2 commit 1ad0bf7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
9 changes: 9 additions & 0 deletions app/assets/javascripts/app/frontend/controllers/_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ function getParameterByName(name, url) {
return decodeURIComponent(results[2].replace(/\+/g, " "));
}

function parametersFromURL(url) {
url = url.split("?").slice(-1)[0];
var obj = {};
url.replace(/([^=&]+)=([^&]*)/g, function(m, key, value) {
obj[decodeURIComponent(key)] = decodeURIComponent(value);
});
return obj;
}

angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class SyncAdapter extends Item {
}

structureParams() {
var params = {
url: this.url,
};

var params = this.content || {};
_.merge(params, super.structureParams());
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class GlobalExtensionsMenu {
}

$scope.handleSyncAdapterLink = function(link, completion) {
var ext = new SyncAdapter({url: link});
var params = parametersFromURL(link);
var ext = new SyncAdapter({content: params});
ext.setDirty(true);
modelManager.addItem(ext);
syncManager.sync();
Expand Down
19 changes: 11 additions & 8 deletions app/assets/javascripts/app/services/helpers/encryptionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ class EncryptionHelper {
}

static decryptItem(item, keys) {

if((item.content.startsWith("001") || item.content.startsWith("002")) && item.enc_item_key) {
// is encrypted, continue to below
} else {
// is base64 encoded
item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length))
return;
}

// decrypt encrypted key
var encryptedItemKey = item.enc_item_key;
var requiresAuth = true;
Expand Down Expand Up @@ -123,19 +132,13 @@ class EncryptionHelper {
var isString = typeof item.content === 'string' || item.content instanceof String;
if(isString) {
try {
if((item.content.startsWith("001") || item.content.startsWith("002")) && item.enc_item_key) {
// is encrypted
this.decryptItem(item, keys);
} else {
// is base64 encoded
item.content = Neeto.crypto.base64Decode(item.content.substring(3, item.content.length))
}
this.decryptItem(item, keys);
} catch (e) {
item.errorDecrypting = true;
if(throws) {
throw e;
}
console.log("Error decrypting item", item, e);
console.error("Error decrypting item", item, e);
continue;
}
}
Expand Down

0 comments on commit 1ad0bf7

Please sign in to comment.