add some redirection logic to support old hash types

pull/1/head
ansuz 9 years ago
parent 600f3151e9
commit cd18075ac7

@ -34,12 +34,35 @@ define([
var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; }; var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; };
common.redirect = function (hash) {
var hostname = window.location.hostname;
// don't do anything funny unless you're on a cryptpad subdomain
if (!/cryptpad.fr/i.test(hostname)) { return; }
if (hash.length >= 56) {
// you're on the right domain
return;
}
// old.cryptpad only supports these apps, so only redirect on a match
if (['/pad/', '/p/', '/code/'].indexOf(window.location.pathname) === -1) {
return;
}
// if you make it this far then there's something wrong with your hash
// you should probably be on old.cryptpad.fr...
window.location.hostname = 'old.cryptpad.fr';
};
var getSecrets = common.getSecrets = function () { var getSecrets = common.getSecrets = function () {
var secret = {}; var secret = {};
if (!/#/.test(window.location.href)) { if (!/#/.test(window.location.href)) {
secret.key = Crypto.genKey(); secret.key = Crypto.genKey();
} else { } else {
var hash = window.location.hash.slice(1); var hash = window.location.hash.slice(1);
common.redirect(hash);
secret.channel = hash.slice(0, 32); secret.channel = hash.slice(0, 32);
secret.key = hash.slice(32); secret.key = hash.slice(32);
} }

Loading…
Cancel
Save