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, " ")); 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); angular.module('app.frontend').controller('BaseCtrl', BaseCtrl);

View File

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

View File

@@ -120,7 +120,8 @@ class GlobalExtensionsMenu {
} }
$scope.handleSyncAdapterLink = function(link, completion) { $scope.handleSyncAdapterLink = function(link, completion) {
var ext = new SyncAdapter({url: link}); var params = parametersFromURL(link);
var ext = new SyncAdapter({content: params});
ext.setDirty(true); ext.setDirty(true);
modelManager.addItem(ext); modelManager.addItem(ext);
syncManager.sync(); syncManager.sync();

View File

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