Dynamic SF|Extension registration, handle 000 decode
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -10,10 +10,7 @@ class SyncAdapter extends Item {
|
||||
}
|
||||
|
||||
structureParams() {
|
||||
var params = {
|
||||
url: this.url,
|
||||
};
|
||||
|
||||
var params = this.content || {};
|
||||
_.merge(params, super.structureParams());
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user