Add embed options in the secure pad hashes

pull/1/head
yflory 7 years ago
parent 31a6881dba
commit e85b34f127

@ -193,6 +193,39 @@ define([
&& secret.hashData.present); && secret.hashData.present);
}, "Couldn't handle multiple successive slashes"); }, "Couldn't handle multiple successive slashes");
// test support for present & embed mode in hashes
assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit//CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G/embed/present/');
return cb(secret.hashData.version === 1
&& secret.hashData.mode === "edit"
&& secret.hashData.channel === "CmN5+YJkrHFS3NSBg-P7Sg"
&& secret.hashData.key === "DNZ2wcG683GscU4fyOyqA87G"
&& secret.hashData.present
&& secret.hashData.embed);
}, "Couldn't handle multiple successive slashes");
// test support for present & embed mode in hashes
assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit//CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G/present/embed');
return cb(secret.hashData.version === 1
&& secret.hashData.mode === "edit"
&& secret.hashData.channel === "CmN5+YJkrHFS3NSBg-P7Sg"
&& secret.hashData.key === "DNZ2wcG683GscU4fyOyqA87G"
&& secret.hashData.present
&& secret.hashData.embed);
}, "Couldn't handle multiple successive slashes");
// test support for embed mode in hashes
assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit//CmN5+YJkrHFS3NSBg-P7Sg/DNZ2wcG683GscU4fyOyqA87G///embed//');
return cb(secret.hashData.version === 1
&& secret.hashData.mode === "edit"
&& secret.hashData.channel === "CmN5+YJkrHFS3NSBg-P7Sg"
&& secret.hashData.key === "DNZ2wcG683GscU4fyOyqA87G"
&& !secret.hashData.present
&& secret.hashData.embed);
}, "Couldn't handle multiple successive slashes");
// test support for trailing slash // test support for trailing slash
assert(function (cb) { assert(function (cb) {
var secret = Cryptpad.parsePadUrl('/pad/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI/'); var secret = Cryptpad.parsePadUrl('/pad/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI/');

@ -68,7 +68,9 @@ Version 1
parsed.mode = hashArr[2]; parsed.mode = hashArr[2];
parsed.channel = hashArr[3]; parsed.channel = hashArr[3];
parsed.key = hashArr[4].replace(/-/g, '/'); parsed.key = hashArr[4].replace(/-/g, '/');
parsed.present = typeof(hashArr[5]) === "string" && hashArr[5] === 'present'; var options = hashArr.slice(5);
parsed.present = options.indexOf('present') !== -1;
parsed.embed = options.indexOf('embed') !== -1;
return parsed; return parsed;
} }
return parsed; return parsed;
@ -115,6 +117,27 @@ Version 1
var idx; var idx;
ret.getUrl = function (options) {
options = options || {};
var url = '/';
if (!ret.type) { return url; }
url += ret.type + '/';
if (!ret.hashData) { return url; }
if (ret.hashData.type !== 'pad') { return url + '/#' + ret.hash; }
if (ret.hashData.version !== 1) { throw new Error("Only v1 hashes are managed here."); }
url += '#/' + ret.hashData.version +
'/' + ret.hashData.mode +
'/' + ret.hashData.channel.replace(/\//g, '-') +
'/' + ret.hashData.key.replace(/\//g, '-') +'/';
if (options.embed) {
url += 'embed/';
}
if (options.present) {
url += 'present/';
}
return url;
};
if (!/^https*:\/\//.test(href)) { if (!/^https*:\/\//.test(href)) {
idx = href.indexOf('/#'); idx = href.indexOf('/#');
ret.type = href.slice(1, idx); ret.type = href.slice(1, idx);

@ -674,7 +674,8 @@ define([
var href = typeof padHref === "string" ? padHref : window.location.href; var href = typeof padHref === "string" ? padHref : window.location.href;
var parsed = parsePadUrl(href); var parsed = parsePadUrl(href);
if (!parsed.hash) { return; } if (!parsed.hash) { return; }
href = getRelativeHref(href); href = parsed.getUrl({present: parsed.present});
//href = getRelativeHref(href);
// getRecentPads return the array from the drive, not a copy // getRecentPads return the array from the drive, not a copy
// We don't have to call "set..." at the end, everything is stored with listmap // We don't have to call "set..." at the end, everything is stored with listmap
getRecentPads(function (err, recent) { getRecentPads(function (err, recent) {

@ -82,7 +82,9 @@ define([
isTemplate: Cryptpad.isTemplate(window.location.href), isTemplate: Cryptpad.isTemplate(window.location.href),
feedbackAllowed: Cryptpad.isFeedbackAllowed(), feedbackAllowed: Cryptpad.isFeedbackAllowed(),
friends: proxy.friends || {}, friends: proxy.friends || {},
settings: proxy.settings || {} settings: proxy.settings || {},
isPresent: parsed.hashData && parsed.hashData.present,
isEmbed: parsed.hashData && parsed.hashData.embed,
} }
}); });
}); });
@ -290,6 +292,13 @@ define([
readOnly: readOnly, readOnly: readOnly,
crypto: Crypto.createEncryptor(secret.keys), crypto: Crypto.createEncryptor(secret.keys),
onConnect: function (wc) { onConnect: function (wc) {
if (window.location.hash && window.location.hash !== '#') {
window.location = parsed.getUrl({
present: parsed.hashData.present,
embed: parsed.hashData.embed
});
return;
}
if (readOnly) { return; } if (readOnly) { return; }
Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys)); Cryptpad.replaceHash(Cryptpad.getEditHashFromKeys(wc.id, secret.keys));
} }

@ -50,6 +50,12 @@ define([
var createRealtimeToolbar = function (config) { var createRealtimeToolbar = function (config) {
if (!config.$container) { return; } if (!config.$container) { return; }
var $container = config.$container; var $container = config.$container;
var isEmbed = Bar.isEmbed = config.metadataMgr.getPrivateData().isEmbed;
if (isEmbed) {
$container.hide();
}
var $toolbar = $('<div>', { var $toolbar = $('<div>', {
'class': TOOLBAR_CLS, 'class': TOOLBAR_CLS,
id: uid(), id: uid(),
@ -304,6 +310,7 @@ define([
}); });
}; };
var show = function () { var show = function () {
if (Bar.isEmbed) { $content.hide(); return; }
$content.show(); $content.show();
if (mobile) { if (mobile) {
$ck.hide(); $ck.hide();
@ -440,7 +447,7 @@ define([
}; };
var createFileShare = function (toolbar) { var createFileShare = function (toolbar) {
throw new Error('TODO: Update createFileShare to add "embed" and work in secure iframes'); if (true) { throw new Error('TODO: Update createFileShare to add "embed" and work in secure iframes'); }
if (!window.location.hash) { if (!window.location.hash) {
throw new Error("Unable to display the share button: hash required in the URL"); throw new Error("Unable to display the share button: hash required in the URL");
} }

@ -1,7 +1,8 @@
define([ define([
'jquery', 'jquery',
'/common/diffMarked.js', '/common/diffMarked.js',
],function ($, DiffMd) { '/common/cryptpad-common.js.js',
],function ($, DiffMd, Cryptpad) {
var Slide = { var Slide = {
index: 0, index: 0,
@ -116,13 +117,13 @@ define([
}; };
var isPresentURL = Slide.isPresentURL = function () { var isPresentURL = Slide.isPresentURL = function () {
var hash = window.location.hash; var parsed = Cryptpad.parsePadUrl(window.location.href);
// Present mode has /present at the end of the hash return parsed && parsed.hashData && parsed.hashData.present;
var urlLastFragment = hash.slice(hash.lastIndexOf('/')+1);
return urlLastFragment === "present";
}; };
var show = Slide.show = function (bool, content) { var show = Slide.show = function (bool, content) {
var parsed = Cryptpad.parsePadUrl(window.location.href);
var hashData = parsed.hashData || {};
Slide.shown = bool; Slide.shown = bool;
if (bool) { if (bool) {
Slide.update(content); Slide.update(content);
@ -131,10 +132,7 @@ define([
$(ifrw).focus(); $(ifrw).focus();
change(null, Slide.index); change(null, Slide.index);
if (!isPresentURL()) { if (!isPresentURL()) {
if (window.location.href.slice(-1) !== '/') { window.location += parsed.getUrl({present: true, embed: hashData.embed});
window.location.hash += '/';
}
window.location.hash += 'present';
} }
$pad.contents().find('.cryptpad-present-button').hide(); $pad.contents().find('.cryptpad-present-button').hide();
$pad.contents().find('.cryptpad-source-button').show(); $pad.contents().find('.cryptpad-source-button').show();
@ -144,7 +142,7 @@ define([
updateFontSize(); updateFontSize();
return; return;
} }
window.location.hash = window.location.hash.replace(/\/present$/, '/'); window.location = parsed.getUrl({embed: hashData.embed});
change(Slide.index, null); change(Slide.index, null);
$pad.contents().find('.cryptpad-present-button').show(); $pad.contents().find('.cryptpad-present-button').show();
$pad.contents().find('.cryptpad-source-button').hide(); $pad.contents().find('.cryptpad-source-button').hide();

Loading…
Cancel
Save