Remove the domain from the href in store
This commit is contained in:
parent
a9c9d19212
commit
5e69b78334
@ -194,10 +194,10 @@ define([
|
|||||||
// Creating a new anon drive: import anon pads from localStorage
|
// Creating a new anon drive: import anon pads from localStorage
|
||||||
if (!drive[Cryptpad.storageKey] || !Cryptpad.isArray(drive[Cryptpad.storageKey])) {
|
if (!drive[Cryptpad.storageKey] || !Cryptpad.isArray(drive[Cryptpad.storageKey])) {
|
||||||
var oldStore = Cryptpad.getStore(true);
|
var oldStore = Cryptpad.getStore(true);
|
||||||
oldStore.get(Cryptpad.storageKey, function (err, s) {
|
Cryptpad.getRecentPads(function (err, s) {
|
||||||
drive[Cryptpad.storageKey] = s;
|
drive[Cryptpad.storageKey] = s;
|
||||||
onReady(f, rt.proxy, Cryptpad.storageKey);
|
onReady(f, rt.proxy, Cryptpad.storageKey);
|
||||||
});
|
}, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onReady(f, rt.proxy, Cryptpad.storageKey);
|
onReady(f, rt.proxy, Cryptpad.storageKey);
|
||||||
|
|||||||
@ -337,8 +337,9 @@ define([
|
|||||||
pad.title = hash.slice(0,8);
|
pad.title = hash.slice(0,8);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
pad.href = pad.href.replace(/^https:\/\/beta\.cryptpad\.fr/,
|
if (/^https*:\/\//.test(pad.href)) {
|
||||||
'https://cryptpad.fr');
|
pad.href = common.getRelativeHref(pad.href);
|
||||||
|
}
|
||||||
return pad;
|
return pad;
|
||||||
} else {
|
} else {
|
||||||
console.error("[Cryptpad.migrateRecentPads] pad had unexpected value");
|
console.error("[Cryptpad.migrateRecentPads] pad had unexpected value");
|
||||||
@ -352,10 +353,23 @@ define([
|
|||||||
return window.location.hash.slice(1);
|
return window.location.hash.slice(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getRelativeHref = common.getRelativeHref = function (href) {
|
||||||
|
var parsed = common.parsePadUrl(href);
|
||||||
|
return '/' + parsed.type + '/#' + parsed.hash;
|
||||||
|
};
|
||||||
|
|
||||||
var parsePadUrl = common.parsePadUrl = function (href) {
|
var parsePadUrl = common.parsePadUrl = function (href) {
|
||||||
var patt = /^https*:\/\/([^\/]*)\/(.*?)\//i;
|
var patt = /^https*:\/\/([^\/]*)\/(.*?)\//i;
|
||||||
|
|
||||||
var ret = {};
|
var ret = {};
|
||||||
|
|
||||||
|
if (!/^https*:\/\//.test(href)) {
|
||||||
|
var idx = href.indexOf('/#');
|
||||||
|
ret.type = href.slice(1, idx);
|
||||||
|
ret.hash = href.slice(idx + 2);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
var hash = href.replace(patt, function (a, domain, type, hash) {
|
var hash = href.replace(patt, function (a, domain, type, hash) {
|
||||||
ret.domain = domain;
|
ret.domain = domain;
|
||||||
ret.type = type;
|
ret.type = type;
|
||||||
@ -456,7 +470,11 @@ define([
|
|||||||
// STORAGE
|
// STORAGE
|
||||||
/* fetch and migrate your pad history from localStorage */
|
/* fetch and migrate your pad history from localStorage */
|
||||||
var getRecentPads = common.getRecentPads = function (cb, legacy) {
|
var getRecentPads = common.getRecentPads = function (cb, legacy) {
|
||||||
getStore(legacy).getDrive(storageKey, function (err, recentPads) {
|
var sstore = getStore(legacy);
|
||||||
|
if (legacy) {
|
||||||
|
sstore.getDrive = sstore.get;
|
||||||
|
}
|
||||||
|
sstore.getDrive(storageKey, function (err, recentPads) {
|
||||||
if (isArray(recentPads)) {
|
if (isArray(recentPads)) {
|
||||||
cb(void 0, migrateRecentPads(recentPads));
|
cb(void 0, migrateRecentPads(recentPads));
|
||||||
return;
|
return;
|
||||||
@ -468,7 +486,11 @@ define([
|
|||||||
// STORAGE
|
// STORAGE
|
||||||
/* commit a list of pads to localStorage */
|
/* commit a list of pads to localStorage */
|
||||||
var setRecentPads = common.setRecentPads = function (pads, cb, legacy) {
|
var setRecentPads = common.setRecentPads = function (pads, cb, legacy) {
|
||||||
getStore(legacy).setDrive(storageKey, pads, function (err, data) {
|
var sstore = getStore(legacy);
|
||||||
|
if (legacy) {
|
||||||
|
sstore.setDrive = sstore.set;
|
||||||
|
}
|
||||||
|
sstore.setDrive(storageKey, pads, function (err, data) {
|
||||||
cb(err, data);
|
cb(err, data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -535,6 +557,7 @@ define([
|
|||||||
var setPadTitle = common.setPadTitle = function (name, cb) {
|
var setPadTitle = common.setPadTitle = function (name, cb) {
|
||||||
var href = window.location.href;
|
var href = window.location.href;
|
||||||
var parsed = parsePadUrl(href);
|
var parsed = parsePadUrl(href);
|
||||||
|
href = getRelativeHref(href);
|
||||||
getRecentPads(function (err, recent) {
|
getRecentPads(function (err, recent) {
|
||||||
if (err) {
|
if (err) {
|
||||||
cb(err);
|
cb(err);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user