Dynamic SF|Extension registration, handle 000 decode

This commit is contained in:
Mo Bitar
2017-07-26 18:37:35 -05:00
parent e9092c2c78
commit 1ad0bf73d8
4 changed files with 23 additions and 13 deletions

View File

@@ -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);

View File

@@ -10,10 +10,7 @@ class SyncAdapter extends Item {
}
structureParams() {
var params = {
url: this.url,
};
var params = this.content || {};
_.merge(params, super.structureParams());
return params;
}

View File

@@ -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();

View File

@@ -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;
@@ -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;
}
}