Versioned hash for onlyoffice

pull/1/head
yflory 4 years ago
parent 68423f49bc
commit 16af013bce

@ -40,13 +40,16 @@ define([
if (endWithCp) { cpIndex = 0; }
var $version, $time;
var $version, $time, $share;
var $hist = $toolbar.find('.cp-toolbar-history');
var $bottom = $toolbar.find('.cp-toolbar-bottom');
var showVersion = function (initial) {
var getVersion = function () {
var major = sortedCp.length - cpIndex;
var v = major + '.' + msgIndex;
return major + '.' + msgIndex;
};
var showVersion = function (initial) {
var v = getVersion();
if (initial) {
v = "Latest"; // XXX
}
@ -113,6 +116,7 @@ define([
fillOO(id, messages);
loading = false;
config.onCheckpoint(cp);
$share.show();
});
};
@ -199,10 +203,10 @@ define([
$next.hide().appendTo($hist);
$fastNext.hide().appendTo($hist);
var $share = $('<button>', {
$share = $('<button>', {
'class': 'fa fa-shhare-alt buttonPrimary',
title: Messages.shareButton
}).appendTo($hist);
}).hide().appendTo($hist);
$('<span>', {'class': 'cp-history-filler'}).appendTo($hist);
$time = $(h('div')).appendTo($hist);
var $close = $('<button>', {
@ -247,6 +251,9 @@ define([
// Versioned link
$share.click(function () {
// XXX
common.getSframeChannel().event('EV_SHARE_OPEN', {
versionHash: getVersion()
});
});
// Push one patch

@ -409,7 +409,7 @@ define([
}
myUniqueOOId = undefined;
setMyId();
APP.docEditor.destroyEditor(); // Kill the old editor
if (APP.docEditor) { APP.docEditor.destroyEditor(); } // Kill the old editor
$('iframe[name="frameEditor"]').after(h('div#cp-app-oo-placeholder')).remove();
ooLoaded = false;
oldLocks = {};
@ -546,6 +546,9 @@ define([
return new Blob([newText], {type: 'text/plain'});
};
var loadLastDocument = function (lastCp, onCpError, cb) {
if (!lastCp || !lastCp.file) {
return void onCpError('EEMPTY');
}
ooChannel.cpIndex = lastCp.index || 0;
ooChannel.lastHash = lastCp.hash;
var parsed = Hash.parsePadUrl(lastCp.file);
@ -611,6 +614,52 @@ define([
});
};
var openVersionHash = function (version) {
readOnly = true;
var hashes = content.hashes || {};
var sortedCp = Object.keys(hashes).map(Number).sort(function (a, b) {
return hashes[a].index - hashes[b].index;
});
var s = version.split('.');
if (s.length !== 2) { return; }
var major = Number(s[0]);
var cpId = sortedCp[major - 1];
var nextCpId = sortedCp[major];
var cp = hashes[cpId] || {};
var minor = Number(s[1]) + 1;
var toHash = cp.hash || 'NONE';
var fromHash = nextCpId ? hashes[nextCpId].hash : 'NONE';
sframeChan.query('Q_GET_HISTORY_RANGE', {
channel: content.channel,
lastKnownHash: fromHash,
toHash: toHash,
}, function (err, data) {
if (err) { return void console.error(err); }
if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); }
var messages = (data.messages || []).slice(1, minor).forEach(function (obj) {
try { obj.msg = JSON.parse(obj.msg); } catch (e) { console.error(e); }
});
loadLastDocument(cp, function () {
var file = getFileType();
var type = common.getMetadataMgr().getPrivateData().ooType;
var blob = loadInitDocument(type, true);
ooChannel.queue = messages;
resetData(blob, file);
UI.removeLoadingScreen();
}, function (blob, file) {
ooChannel.queue = messages;
resetData(blob, file);
UI.removeLoadingScreen();
});
});
};
var openRtChannel = function (cb) {
if (rtChannel.ready) { return void cb(); }
var chan = content.channel || Hash.createChannelId();
@ -1763,10 +1812,10 @@ define([
makeCheckpoint(true);
});
$save.appendTo(toolbar.$bottomM);
}
(function () {
/* add a history button */
// XXX move out of dev mode
var commit = function () {
APP.stopHistory = true;
makeCheckpoint(true);
@ -1831,7 +1880,7 @@ define([
History.create(common, histConfig);
}).appendTo(toolbar.$drawer);
})();
}
if (window.CP_DEV_MODE || DISPLAY_RESTORE_BUTTON) {
common.createButton('', true, {
name: 'delete',
@ -1978,6 +2027,11 @@ define([
sframeChan.event('EV_BURN_PAD', content.channel);
}
if (privateData.ooVersionHash) {
return void openVersionHash(privateData.ooVersionHash);
}
var useNewDefault = content.version && content.version >= 2;
openRtChannel(function () {
setMyId();

@ -4,12 +4,13 @@ define([
'/api/config',
'/common/dom-ready.js',
'/common/requireconfig.js',
'/common/common-hash.js',
'/common/sframe-common-outer.js'
], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
], function (nThen, ApiConfig, DomReady, RequireConfig, Hash, SFCommonO) {
var requireConfig = RequireConfig();
// Loaded in load #2
var hash, href;
var hash, href, version;
nThen(function (waitFor) {
DomReady.onReady(waitFor());
}).nThen(function (waitFor) {
@ -27,6 +28,14 @@ define([
if (window.history && window.history.replaceState && hash) {
window.history.replaceState({}, window.document.title, '#');
}
var parsed = Hash.parsePadUrl(href);
var opts = parsed.getOptions();
version = opts.versionHash;
opts.versionHash = "";
href = parsed.getUrl(opts);
hash = parsed.hashData.getHash(opts);
document.getElementById('sbox-iframe').setAttribute('src',
ApiConfig.httpSafeOrigin + window.location.pathname + 'inner.html?' +
requireConfig.urlArgs + '#' + encodeURIComponent(JSON.stringify(req)));
@ -46,6 +55,7 @@ define([
}).nThen(function (/*waitFor*/) {
var addData = function (obj) {
obj.ooType = window.location.pathname.replace(/^\//, '').replace(/\/$/, '');
obj.ooVersionHash = version;
obj.ooForceVersion = localStorage.CryptPad_ooVersion || sessionStorage.CryptPad_ooVersion || "";
};
var addRpc = function (sframeChan, Cryptpad, Utils) {

@ -2035,8 +2035,6 @@ define([
var lastKnownHash;
var txid = Util.uid();
console.error(data);
var onMsg = function (msg) {
if (completed) { return; }
var parsed = parse(msg);

Loading…
Cancel
Save