Migration for read-only links + fix issues with read-only pads

pull/1/head
yflory 6 years ago
parent 0f9a71686e
commit 425ac8ea57

@ -665,7 +665,7 @@ define([
// Update the current state
loading.driveState = data.state;
data.progress = data.progress || 100;
data.msg = Messages['loading_drive_'+data.state] || '';
data.msg = Messages['loading_drive_'+ Math.floor(data.state)] || '';
$progress.html(data.msg);
if (data.progress) {
$progress.append(h('div.cp-loading-progress-bar', [

@ -74,32 +74,12 @@ define([
}));
}).nThen(function (waitFor) {
var base = common.getMetadataMgr().getPrivateData().origin;
/* XXX
common.getPadAttribute('href', waitFor(function (err, val) {
var base = common.getMetadataMgr().getPrivateData().origin;
var parsed = Hash.parsePadUrl(val);
if (parsed.hashData.mode === "view") {
data.roHref = base + val;
return;
}
// We're not in a read-only pad
data.href = base + val;
// Get Read-only href
if (parsed.hashData.type !== "pad") { return; }
var i = data.href.indexOf('#') + 1;
var hBase = data.href.slice(0, i);
var hrefsecret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
if (!hrefsecret.keys) { return; }
var viewHash = Hash.getViewHashFromKeys(hrefsecret);
data.roHref = hBase + viewHash;
}));*/
common.getPadAttribute('href', waitFor(function (err, val) {
if (!val) { return; }
data.href = base + val;
}));
common.getPadAttribute('roHref', waitFor(function (err, val) {
if (!val) { return; }
data.roHref = base + val;
}));
common.getPadAttribute('channel', waitFor(function (err, val) {

@ -119,6 +119,7 @@ define([
});
oldFiles.forEach(function (id) {
var href = oldRecentPads[id].href || oldRecentPads[id].roHref;
var isRo = href === oldRecentPads[id].roHref;
// Do not migrate a pad if we already have it, it would create a duplicate in the drive
if (newHrefs.indexOf(href) !== -1) { return; }
// If we have a stronger version, do not add the current href

@ -123,12 +123,58 @@ define([
}));
});
});
n.nThen(waitFor());
n.nThen(waitFor(function () {
Feedback.send('Migrate-6', true);
userObject.version = version = 6;
}));
};
if (version < 6) {
addChannelId();
Feedback.send('Migrate-6', true);
userObject.version = version = 6;
}
}).nThen(function (waitFor) {
var addRoHref = function () {
var data = userObject.drive.filesData;
var el, parsed;
var n = nThen(function () {});
var padsLength = Object.keys(data).length;
Object.keys(data).forEach(function (k, i) {
n = n.nThen(function (w) {
setTimeout(w(function () {
el = data[k];
if (!el.href || (el.roHref && false)) {
// Already migrated
return void progress(7, Math.round(100*i/padsLength));
}
parsed = Hash.parsePadUrl(el.href);
if (parsed.hashData.type !== "pad") {
// No read-only mode for files
return void progress(7, Math.round(100*i/padsLength));
}
if (parsed.hashData.mode === "view") {
// This is a read-only pad in our drive
el.roHref = el.href;
delete el.href;
console.log('Move href to roHref in filesData ', el.roHref);
} else {
var secret = Hash.getSecrets(parsed.type, parsed.hash, el.password);
var hash = Hash.getViewHashFromKeys(secret);
if (hash) {
// Version 0 won't have a view hash available
el.roHref = '/' + parsed.type + '/#' + hash;
console.log('Adding missing roHref in filesData ', el.href);
}
}
progress(6, Math.round(100*i/padsLength));
}));
});
});
n.nThen(waitFor(function () {
Feedback.send('Migrate-7', true);
userObject.version = version = 7;
}));
};
if (version < 7) {
addRoHref();
}
/*}).nThen(function (waitFor) {
// Test progress bar in the loading screen

@ -441,9 +441,11 @@ define([
if (!data.href && !data.roHref) { return void cb({error:'NO_HREF'}); }
if (!data.roHref) {
var parsed = Hash.parsePadUrl(data.href);
if (parsed.hashData.type === "pad") {
var secret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
data.roHref = '/' + parsed.type + '/#' + Hash.getViewHashFromKeys(secret);
}
}
var pad = makePad(data.href, data.roHref, data.title);
if (data.owners) { pad.owners = data.owners; }
if (data.expire) { pad.expire = data.expire; }
@ -742,7 +744,7 @@ define([
// Edit > Edit (present) > View > View (present)
for (var id in allPads) {
var pad = allPads[id];
if (!pad.href || !pad.roHref) { continue; }
if (!pad.href && !pad.roHref) { continue; }
var p2 = Hash.parsePadUrl(pad.href || pad.roHref);
var h2 = p2.hashData;
@ -1364,7 +1366,7 @@ define([
}).nThen(function (waitFor) {
Migrate(proxy, waitFor(), function (version, progress) {
postMessage(clientId, 'LOADING_DRIVE', {
state: 2,
state: (2 + (version / 10)),
progress: progress
});
});

@ -133,11 +133,6 @@ define([
if (!loggedIn && !config.testMode) {
allFilesPaths.forEach(function (path) {
var id = path[1];
/* XXX
var el = exp.find(path);
if (!el) { return; }
var id = exp.getIdFromHref(el.href);
*/
if (!id) { return; }
spliceFileData(id);
});
@ -256,15 +251,6 @@ define([
};
// REPLACE
/* XXX
exp.replace = function (o, n) {
var idO = exp.getIdFromHref(o);
if (!idO || !exp.isFile(idO)) { return; }
var data = exp.getFileData(idO);
if (!data) { return; }
data.href = n;
};
*/
// If all the occurences of an href are in the trash, remove them and add the file in root.
// This is use with setPadTitle when we open a stronger version of a deleted pad
exp.restoreHref = function (href) {
@ -576,17 +562,18 @@ define([
}
// If we have an edit link, check the view link
if (el.href) {
var fixRo = function () {
if (el.href && parsed.hashData.type === "pad") {
if (parsed.hashData.mode === "view") {
el.roHref = el.href;
delete el.href;
} else if (!el.roHref) {
secret = Hash.getSecrets(parsed.type, parsed.hash, el.password);
el.roHref = '/' + parsed.type + '/#' + Hash.getViewHasFromKeys(secret);
};
if (!el.roHref) {
fixRo();
el.roHref = '/' + parsed.type + '/#' + Hash.getViewHashFromKeys(secret);
} else {
var parsed2 = Hash.parsePadUrl(el.roHref);
if (!parsed2.hash || !parsed2.type) {
fixRo();
secret = Hash.getSecrets(parsed.type, parsed.hash, el.password);
el.roHref = '/' + parsed.type + '/#' + Hash.getViewHashFromKeys(secret);
}
}
}

@ -79,13 +79,6 @@ define([
if (!isFile(element)) { return false; }
var data = exp.getFileData(element);
return Boolean(data.roHref && !data.href);
/* XXX
var parsed = Hash.parsePadUrl(data.href);
if (!parsed) { return false; }
var pHash = parsed.hashData;
if (!pHash || pHash.type !== "pad") { return; }
return pHash && pHash.mode === 'view';
*/
};
var isFolder = exp.isFolder = function (element) {

@ -2691,22 +2691,6 @@ define([
return $div.html();
};
/* XXX
var getReadOnlyUrl = APP.getRO = function (id) {
if (!filesOp.isFile(id)) { return; }
var data = filesOp.getFileData(id);
if (!data) { return; }
if (data.roHref) { return data.roHref; }
var parsed = Hash.parsePadUrl(data.href);
if (parsed.hashData.type !== "pad") { return; }
var i = data.href.indexOf('#') + 1;
var base = data.href.slice(0, i);
var hrefsecret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
if (!hrefsecret.keys) { return; }
var viewHash = Hash.getViewHashFromKeys(hrefsecret);
return base + viewHash;
};*/
// Disable middle click in the context menu to avoid opening /drive/inner.html# in new tabs
$(window).click(function (e) {
if (!e.target || !$(e.target).parents('.cp-dropdown-content').length) { return; }
@ -2723,20 +2707,14 @@ define([
//var ro = filesOp.isReadOnlyFile(el);
var base = APP.origin;
var data = JSON.parse(JSON.stringify(filesOp.getFileData(el)));
if (!data || !data.href) { return void cb('INVALID_FILE'); }
if (!data || !(data.href || data.roHref)) { return void cb('INVALID_FILE'); }
if (data.href) {
data.href = base + data.href;
}
if (data.roHref) {
data.roHref = base + data.roHref;
/* XXX
var roUrl;
if (ro) {
data.roHref = data.href;
delete data.href;
} else {
roUrl = getReadOnlyUrl(el);
if (roUrl) { data.roHref = base + roUrl; }
}
*/
UIElements.getProperties(common, data, cb);
};
@ -2810,11 +2788,15 @@ define([
else if ($(this).hasClass('cp-app-drive-context-openro')) {
paths.forEach(function (p) {
var el = filesOp.find(p.path);
if (filesOp.isPathIn(p.path, [FILES_DATA])) { el = el.href; }
var href;
if (filesOp.isPathIn(p.path, [FILES_DATA])) {
href = el.roHref;
} else {
if (!el || filesOp.isFolder(el)) { return; }
// var roUrl = getReadOnlyUrl(el);
openFile(el);
//, roUrl); XXX
var data = filesOp.getFileData(el);
href = data.roHref;
}
openFile(null, href);
});
}
else if ($(this).hasClass('cp-app-drive-context-newfolder')) {

@ -237,7 +237,8 @@ define([
&& typeof files.template[0] === "number"
&& typeof files.filesData[files.template[0]] === "object"
&& !files.filesData[files.template[0]].filename
&& files.filesData[files.template[0]].href === href3
&& !files.filesData[files.template[0]].href
&& files.filesData[files.template[0]].roHref === href3
&& typeof fileId2 === "number"
&& typeof files.filesData[fileId2] === "object"
&& files.filesData[fileId2].filename === "Trash"
@ -392,11 +393,6 @@ define([
console.log("DRIVE operations: rename");
return cb();
}
fo.replace(href1, href2);
if (fo.getFileData(id1).href !== href2) {
console.log("DRIVE operations: replace");
return cb();
}
cb(true);
}, "DRIVE operations");

Loading…
Cancel
Save