Migration for read-only links + fix issues with read-only pads
This commit is contained in:
@@ -665,7 +665,7 @@ define([
|
|||||||
// Update the current state
|
// Update the current state
|
||||||
loading.driveState = data.state;
|
loading.driveState = data.state;
|
||||||
data.progress = data.progress || 100;
|
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);
|
$progress.html(data.msg);
|
||||||
if (data.progress) {
|
if (data.progress) {
|
||||||
$progress.append(h('div.cp-loading-progress-bar', [
|
$progress.append(h('div.cp-loading-progress-bar', [
|
||||||
|
|||||||
@@ -74,32 +74,12 @@ define([
|
|||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
var base = common.getMetadataMgr().getPrivateData().origin;
|
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) {
|
common.getPadAttribute('href', waitFor(function (err, val) {
|
||||||
|
if (!val) { return; }
|
||||||
data.href = base + val;
|
data.href = base + val;
|
||||||
}));
|
}));
|
||||||
common.getPadAttribute('roHref', waitFor(function (err, val) {
|
common.getPadAttribute('roHref', waitFor(function (err, val) {
|
||||||
|
if (!val) { return; }
|
||||||
data.roHref = base + val;
|
data.roHref = base + val;
|
||||||
}));
|
}));
|
||||||
common.getPadAttribute('channel', waitFor(function (err, val) {
|
common.getPadAttribute('channel', waitFor(function (err, val) {
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ define([
|
|||||||
});
|
});
|
||||||
oldFiles.forEach(function (id) {
|
oldFiles.forEach(function (id) {
|
||||||
var href = oldRecentPads[id].href || oldRecentPads[id].roHref;
|
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
|
// 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 (newHrefs.indexOf(href) !== -1) { return; }
|
||||||
// If we have a stronger version, do not add the current href
|
// 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) {
|
if (version < 6) {
|
||||||
addChannelId();
|
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) {
|
/*}).nThen(function (waitFor) {
|
||||||
// Test progress bar in the loading screen
|
// Test progress bar in the loading screen
|
||||||
|
|||||||
@@ -441,8 +441,10 @@ define([
|
|||||||
if (!data.href && !data.roHref) { return void cb({error:'NO_HREF'}); }
|
if (!data.href && !data.roHref) { return void cb({error:'NO_HREF'}); }
|
||||||
if (!data.roHref) {
|
if (!data.roHref) {
|
||||||
var parsed = Hash.parsePadUrl(data.href);
|
var parsed = Hash.parsePadUrl(data.href);
|
||||||
var secret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
|
if (parsed.hashData.type === "pad") {
|
||||||
data.roHref = '/' + parsed.type + '/#' + Hash.getViewHashFromKeys(secret);
|
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);
|
var pad = makePad(data.href, data.roHref, data.title);
|
||||||
if (data.owners) { pad.owners = data.owners; }
|
if (data.owners) { pad.owners = data.owners; }
|
||||||
@@ -742,7 +744,7 @@ define([
|
|||||||
// Edit > Edit (present) > View > View (present)
|
// Edit > Edit (present) > View > View (present)
|
||||||
for (var id in allPads) {
|
for (var id in allPads) {
|
||||||
var pad = allPads[id];
|
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 p2 = Hash.parsePadUrl(pad.href || pad.roHref);
|
||||||
var h2 = p2.hashData;
|
var h2 = p2.hashData;
|
||||||
@@ -1364,7 +1366,7 @@ define([
|
|||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
Migrate(proxy, waitFor(), function (version, progress) {
|
Migrate(proxy, waitFor(), function (version, progress) {
|
||||||
postMessage(clientId, 'LOADING_DRIVE', {
|
postMessage(clientId, 'LOADING_DRIVE', {
|
||||||
state: 2,
|
state: (2 + (version / 10)),
|
||||||
progress: progress
|
progress: progress
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -133,11 +133,6 @@ define([
|
|||||||
if (!loggedIn && !config.testMode) {
|
if (!loggedIn && !config.testMode) {
|
||||||
allFilesPaths.forEach(function (path) {
|
allFilesPaths.forEach(function (path) {
|
||||||
var id = path[1];
|
var id = path[1];
|
||||||
/* XXX
|
|
||||||
var el = exp.find(path);
|
|
||||||
if (!el) { return; }
|
|
||||||
var id = exp.getIdFromHref(el.href);
|
|
||||||
*/
|
|
||||||
if (!id) { return; }
|
if (!id) { return; }
|
||||||
spliceFileData(id);
|
spliceFileData(id);
|
||||||
});
|
});
|
||||||
@@ -256,15 +251,6 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
// REPLACE
|
// 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.
|
// 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
|
// This is use with setPadTitle when we open a stronger version of a deleted pad
|
||||||
exp.restoreHref = function (href) {
|
exp.restoreHref = function (href) {
|
||||||
@@ -576,17 +562,18 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have an edit link, check the view link
|
// If we have an edit link, check the view link
|
||||||
if (el.href) {
|
if (el.href && parsed.hashData.type === "pad") {
|
||||||
var fixRo = function () {
|
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);
|
secret = Hash.getSecrets(parsed.type, parsed.hash, el.password);
|
||||||
el.roHref = '/' + parsed.type + '/#' + Hash.getViewHasFromKeys(secret);
|
el.roHref = '/' + parsed.type + '/#' + Hash.getViewHashFromKeys(secret);
|
||||||
};
|
|
||||||
if (!el.roHref) {
|
|
||||||
fixRo();
|
|
||||||
} else {
|
} else {
|
||||||
var parsed2 = Hash.parsePadUrl(el.roHref);
|
var parsed2 = Hash.parsePadUrl(el.roHref);
|
||||||
if (!parsed2.hash || !parsed2.type) {
|
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; }
|
if (!isFile(element)) { return false; }
|
||||||
var data = exp.getFileData(element);
|
var data = exp.getFileData(element);
|
||||||
return Boolean(data.roHref && !data.href);
|
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) {
|
var isFolder = exp.isFolder = function (element) {
|
||||||
|
|||||||
@@ -2691,22 +2691,6 @@ define([
|
|||||||
return $div.html();
|
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
|
// Disable middle click in the context menu to avoid opening /drive/inner.html# in new tabs
|
||||||
$(window).click(function (e) {
|
$(window).click(function (e) {
|
||||||
if (!e.target || !$(e.target).parents('.cp-dropdown-content').length) { return; }
|
if (!e.target || !$(e.target).parents('.cp-dropdown-content').length) { return; }
|
||||||
@@ -2723,20 +2707,14 @@ define([
|
|||||||
//var ro = filesOp.isReadOnlyFile(el);
|
//var ro = filesOp.isReadOnlyFile(el);
|
||||||
var base = APP.origin;
|
var base = APP.origin;
|
||||||
var data = JSON.parse(JSON.stringify(filesOp.getFileData(el)));
|
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'); }
|
||||||
data.href = base + data.href;
|
|
||||||
data.roHref = base + data.roHref;
|
|
||||||
|
|
||||||
/* XXX
|
if (data.href) {
|
||||||
var roUrl;
|
data.href = base + data.href;
|
||||||
if (ro) {
|
}
|
||||||
data.roHref = data.href;
|
if (data.roHref) {
|
||||||
delete data.href;
|
data.roHref = base + data.roHref;
|
||||||
} else {
|
|
||||||
roUrl = getReadOnlyUrl(el);
|
|
||||||
if (roUrl) { data.roHref = base + roUrl; }
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
UIElements.getProperties(common, data, cb);
|
UIElements.getProperties(common, data, cb);
|
||||||
};
|
};
|
||||||
@@ -2810,11 +2788,15 @@ define([
|
|||||||
else if ($(this).hasClass('cp-app-drive-context-openro')) {
|
else if ($(this).hasClass('cp-app-drive-context-openro')) {
|
||||||
paths.forEach(function (p) {
|
paths.forEach(function (p) {
|
||||||
var el = filesOp.find(p.path);
|
var el = filesOp.find(p.path);
|
||||||
if (filesOp.isPathIn(p.path, [FILES_DATA])) { el = el.href; }
|
var href;
|
||||||
if (!el || filesOp.isFolder(el)) { return; }
|
if (filesOp.isPathIn(p.path, [FILES_DATA])) {
|
||||||
// var roUrl = getReadOnlyUrl(el);
|
href = el.roHref;
|
||||||
openFile(el);
|
} else {
|
||||||
//, roUrl); XXX
|
if (!el || filesOp.isFolder(el)) { return; }
|
||||||
|
var data = filesOp.getFileData(el);
|
||||||
|
href = data.roHref;
|
||||||
|
}
|
||||||
|
openFile(null, href);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if ($(this).hasClass('cp-app-drive-context-newfolder')) {
|
else if ($(this).hasClass('cp-app-drive-context-newfolder')) {
|
||||||
|
|||||||
@@ -237,7 +237,8 @@ define([
|
|||||||
&& typeof files.template[0] === "number"
|
&& typeof files.template[0] === "number"
|
||||||
&& typeof files.filesData[files.template[0]] === "object"
|
&& typeof files.filesData[files.template[0]] === "object"
|
||||||
&& !files.filesData[files.template[0]].filename
|
&& !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 fileId2 === "number"
|
||||||
&& typeof files.filesData[fileId2] === "object"
|
&& typeof files.filesData[fileId2] === "object"
|
||||||
&& files.filesData[fileId2].filename === "Trash"
|
&& files.filesData[fileId2].filename === "Trash"
|
||||||
@@ -392,11 +393,6 @@ define([
|
|||||||
console.log("DRIVE operations: rename");
|
console.log("DRIVE operations: rename");
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
fo.replace(href1, href2);
|
|
||||||
if (fo.getFileData(id1).href !== href2) {
|
|
||||||
console.log("DRIVE operations: replace");
|
|
||||||
return cb();
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(true);
|
cb(true);
|
||||||
}, "DRIVE operations");
|
}, "DRIVE operations");
|
||||||
|
|||||||
Reference in New Issue
Block a user