Improve migration script
This commit is contained in:
parent
96968f2076
commit
039ab83440
@ -480,6 +480,11 @@ define([
|
|||||||
var next = function () {
|
var next = function () {
|
||||||
var copy = JSON.parse(JSON.stringify(files));
|
var copy = JSON.parse(JSON.stringify(files));
|
||||||
exp.reencrypt(config.editKey, config.editKey, copy);
|
exp.reencrypt(config.editKey, config.editKey, copy);
|
||||||
|
setTimeout(function () {
|
||||||
|
if (files.version >= 2) {
|
||||||
|
// Already migrated by another user while we were re-encrypting
|
||||||
|
return void cb();
|
||||||
|
}
|
||||||
Object.keys(copy).forEach(function (k) {
|
Object.keys(copy).forEach(function (k) {
|
||||||
files[k] = copy[k];
|
files[k] = copy[k];
|
||||||
});
|
});
|
||||||
@ -487,6 +492,7 @@ define([
|
|||||||
delete files.migrateRo;
|
delete files.migrateRo;
|
||||||
|
|
||||||
onSync(cb);
|
onSync(cb);
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
onSync(next);
|
onSync(next);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -61,7 +61,7 @@ define([
|
|||||||
// Href exists and is encrypted
|
// Href exists and is encrypted
|
||||||
var d = cryptor.decrypt(pad.href);
|
var d = cryptor.decrypt(pad.href);
|
||||||
// If we can decrypt, return the decrypted value, otherwise continue and return roHref
|
// If we can decrypt, return the decrypted value, otherwise continue and return roHref
|
||||||
if (d.indexOf('#') !== -1) {
|
if (d && d.indexOf('#') !== -1) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.reencrypt = function (oldKey, newKey, obj) {
|
module.reencrypt = function (oldKey, newKey, obj) {
|
||||||
obj = obj || {};
|
if (!obj) { return void console.error("Nothing to reencrypt"); }
|
||||||
var oldCryptor = createCryptor(oldKey);
|
var oldCryptor = createCryptor(oldKey);
|
||||||
var newCryptor = createCryptor(newKey);
|
var newCryptor = createCryptor(newKey);
|
||||||
Object.keys(obj[FILES_DATA]).forEach(function (id) {
|
Object.keys(obj[FILES_DATA]).forEach(function (id) {
|
||||||
@ -78,6 +78,7 @@ define([
|
|||||||
// "&& data.roHref" is here to make sure this is not a "file"
|
// "&& data.roHref" is here to make sure this is not a "file"
|
||||||
if (data.href && data.roHref && !data.fileType) {
|
if (data.href && data.roHref && !data.fileType) {
|
||||||
var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href;
|
var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href;
|
||||||
|
if (!_href) { return; }
|
||||||
data.href = newCryptor.encrypt(_href);
|
data.href = newCryptor.encrypt(_href);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -86,6 +87,7 @@ define([
|
|||||||
// If this folder has a visible href, encrypt it
|
// If this folder has a visible href, encrypt it
|
||||||
if (data.href) {
|
if (data.href) {
|
||||||
var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href;
|
var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href;
|
||||||
|
if (!_href) { return; }
|
||||||
data.href = newCryptor.encrypt(_href);
|
data.href = newCryptor.encrypt(_href);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -94,6 +96,7 @@ define([
|
|||||||
// If this folder has a visible href, encrypt it
|
// If this folder has a visible href, encrypt it
|
||||||
if (data.href) {
|
if (data.href) {
|
||||||
var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href;
|
var _href = (data.href && data.href.indexOf('#') === -1) ? oldCryptor.decrypt(data.href) : data.href;
|
||||||
|
if (!_href) { return; }
|
||||||
data.href = newCryptor.encrypt(_href);
|
data.href = newCryptor.encrypt(_href);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user