mirror of https://github.com/xwiki-labs/cryptpad
Store the channel id as pad attribute
This commit is contained in:
parent
b26ae67df5
commit
43d046406f
|
@ -213,8 +213,7 @@ Version 1
|
||||||
if (ret.hashData.type !== 'pad') { return url + '#' + ret.hash; }
|
if (ret.hashData.type !== 'pad') { return url + '#' + ret.hash; }
|
||||||
if (ret.hashData.version === 0) { return url + '#' + ret.hash; }
|
if (ret.hashData.version === 0) { return url + '#' + ret.hash; }
|
||||||
var hash;
|
var hash;
|
||||||
if (options.readOnly === true ||
|
if (typeof (options.readOnly === "undefined") && ret.hashData.mode === "view") {
|
||||||
(typeof (options.readOnly === "undefined") && ret.hashData.mode === "view")) {
|
|
||||||
hash = getViewHashFromKeys({
|
hash = getViewHashFromKeys({
|
||||||
version: ret.hashData.version,
|
version: ret.hashData.version,
|
||||||
type: ret.hashData.app,
|
type: ret.hashData.app,
|
||||||
|
|
|
@ -462,22 +462,18 @@ define([
|
||||||
};
|
};
|
||||||
|
|
||||||
// When opening a new pad or renaming it, store the new title
|
// When opening a new pad or renaming it, store the new title
|
||||||
common.setPadTitle = function (title, padHref, path, cb) {
|
common.setPadTitle = function (data, cb) {
|
||||||
var href = padHref || window.location.href;
|
if (!data || typeof (data) !== "object") { return cb ('Data is not an object'); }
|
||||||
|
|
||||||
// Password not needed here since we don't access hashData
|
var href = data.href || window.location.href;
|
||||||
var parsed = Hash.parsePadUrl(href);
|
var parsed = Hash.parsePadUrl(href);
|
||||||
if (!parsed.hash) { return; }
|
if (!parsed.hash) { return cb ('Invalid hash'); }
|
||||||
href = parsed.getUrl({present: parsed.present});
|
data.href = parsed.getUrl({present: parsed.present});
|
||||||
|
|
||||||
if (title === null) { return; }
|
if (typeof (data.title) !== "string") { return cb('Missing title'); }
|
||||||
if (title.trim() === "") { title = Hash.getDefaultName(parsed); }
|
if (data.title.trim() === "") { data.title = Hash.getDefaultName(parsed); }
|
||||||
|
|
||||||
postMessage("SET_PAD_TITLE", {
|
postMessage("SET_PAD_TITLE", data, function (obj) {
|
||||||
href: href,
|
|
||||||
title: title,
|
|
||||||
path: path
|
|
||||||
}, function (obj) {
|
|
||||||
if (obj && obj.error) {
|
if (obj && obj.error) {
|
||||||
console.log("unable to set pad title");
|
console.log("unable to set pad title");
|
||||||
return void cb(obj.error);
|
return void cb(obj.error);
|
||||||
|
@ -498,13 +494,6 @@ define([
|
||||||
cb(void 0, data);
|
cb(void 0, data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// Set initial path when creating a pad from pad creation screen
|
|
||||||
common.setInitialPath = function (path) {
|
|
||||||
postMessage("SET_INITIAL_PATH", path);
|
|
||||||
};
|
|
||||||
common.setNewPadPassword = function (password) {
|
|
||||||
postMessage("SET_NEW_PAD_PASSWORD", password);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Messaging (manage friends from the userlist)
|
// Messaging (manage friends from the userlist)
|
||||||
common.inviteFromUserlist = function (netfluxId, cb) {
|
common.inviteFromUserlist = function (netfluxId, cb) {
|
||||||
|
|
|
@ -685,10 +685,11 @@ define([
|
||||||
Store.setPadTitle = function (data, cb) {
|
Store.setPadTitle = function (data, cb) {
|
||||||
var title = data.title;
|
var title = data.title;
|
||||||
var href = data.href;
|
var href = data.href;
|
||||||
var padData = store.userObject.getFileData(store.userObject.getIdFromHref(href));
|
var channel = data.channel;
|
||||||
var p = Hash.parsePadUrl(href, padData && padData.password);
|
var p = Hash.parsePadUrl(href);
|
||||||
var h = p.hashData;
|
var h = p.hashData;
|
||||||
|
|
||||||
|
console.log(channel, data);
|
||||||
if (AppConfig.disableAnonymousStore && !store.loggedIn) { return void cb(); }
|
if (AppConfig.disableAnonymousStore && !store.loggedIn) { return void cb(); }
|
||||||
|
|
||||||
var owners;
|
var owners;
|
||||||
|
@ -713,19 +714,19 @@ define([
|
||||||
var pad = allPads[id];
|
var pad = allPads[id];
|
||||||
if (!pad.href) { continue; }
|
if (!pad.href) { continue; }
|
||||||
|
|
||||||
var p2 = Hash.parsePadUrl(pad.href, pad.password);
|
var p2 = Hash.parsePadUrl(pad.href);
|
||||||
var h2 = p2.hashData;
|
var h2 = p2.hashData;
|
||||||
|
|
||||||
// Different types, proceed to the next one
|
// Different types, proceed to the next one
|
||||||
// No hash data: corrupted pad?
|
// No hash data: corrupted pad?
|
||||||
if (p.type !== p2.type || !h2) { continue; }
|
if (p.type !== p2.type || !h2) { continue; }
|
||||||
|
// Different channel: continue
|
||||||
|
if (pad.channel !== channel) { continue; }
|
||||||
|
|
||||||
var shouldUpdate = p.hash.replace(/\/$/, '') === p2.hash.replace(/\/$/, '');
|
var shouldUpdate = p.hash.replace(/\/$/, '') === p2.hash.replace(/\/$/, '');
|
||||||
|
|
||||||
// If the hash is different but represents the same channel, check if weaker or stronger
|
// If the hash is different but represents the same channel, check if weaker or stronger
|
||||||
if (!shouldUpdate &&
|
if (!shouldUpdate && h.version !== 0) {
|
||||||
h.version === h2.version &&
|
|
||||||
h.channel === h2.channel) {
|
|
||||||
// We had view & now we have edit, update
|
// We had view & now we have edit, update
|
||||||
if (h2.mode === 'view' && h.mode === 'edit') { shouldUpdate = true; }
|
if (h2.mode === 'view' && h.mode === 'edit') { shouldUpdate = true; }
|
||||||
// Same mode and we had present URL, update
|
// Same mode and we had present URL, update
|
||||||
|
@ -762,13 +763,13 @@ define([
|
||||||
if (!contains) {
|
if (!contains) {
|
||||||
Store.addPad({
|
Store.addPad({
|
||||||
href: href,
|
href: href,
|
||||||
|
channel: channel,
|
||||||
title: title,
|
title: title,
|
||||||
owners: owners,
|
owners: owners,
|
||||||
expire: expire,
|
expire: expire,
|
||||||
password: store.data && store.data.newPadPassword,
|
password: data.password,
|
||||||
path: data.path || (store.data && store.data.initialPath)
|
path: data.path
|
||||||
}, cb);
|
}, cb);
|
||||||
delete store.data.newPadPassword;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onSync(cb);
|
onSync(cb);
|
||||||
|
@ -807,14 +808,6 @@ define([
|
||||||
Store.getPadData = function (id, cb) {
|
Store.getPadData = function (id, cb) {
|
||||||
cb(store.userObject.getFileData(id));
|
cb(store.userObject.getFileData(id));
|
||||||
};
|
};
|
||||||
Store.setInitialPath = function (path) {
|
|
||||||
if (!store.data) { return; }
|
|
||||||
store.data.initialPath = path;
|
|
||||||
};
|
|
||||||
Store.setNewPadPassword = function (password) {
|
|
||||||
if (!store.data) { return; }
|
|
||||||
store.data.newPadPassword = password;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Messaging (manage friends from the userlist)
|
// Messaging (manage friends from the userlist)
|
||||||
|
|
|
@ -120,12 +120,6 @@ define([
|
||||||
case 'GET_PAD_DATA': {
|
case 'GET_PAD_DATA': {
|
||||||
Store.getPadData(data, cb); break;
|
Store.getPadData(data, cb); break;
|
||||||
}
|
}
|
||||||
case 'SET_INITIAL_PATH': {
|
|
||||||
Store.setInitialPath(data); break;
|
|
||||||
}
|
|
||||||
case 'SET_NEW_PAD_PASSWORD': {
|
|
||||||
Store.setNewPadPassword(data); break;
|
|
||||||
}
|
|
||||||
case 'GET_STRONGER_HASH': {
|
case 'GET_STRONGER_HASH': {
|
||||||
Store.getStrongerHash(data, cb); break;
|
Store.getStrongerHash(data, cb); break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,14 @@ define([
|
||||||
|
|
||||||
if (noStore) { return void onComplete(href); }
|
if (noStore) { return void onComplete(href); }
|
||||||
|
|
||||||
common.setPadTitle(title || "", href, path, function (err) {
|
// PASSWORD_FILES
|
||||||
|
var data = {
|
||||||
|
title: title || "",
|
||||||
|
href: href,
|
||||||
|
path: path,
|
||||||
|
channel: id
|
||||||
|
};
|
||||||
|
common.setPadTitle(data, function (err) {
|
||||||
if (err) { return void console.error(err); }
|
if (err) { return void console.error(err); }
|
||||||
onComplete(href);
|
onComplete(href);
|
||||||
common.setPadAttribute('fileType', metadata.type, null, href);
|
common.setPadAttribute('fileType', metadata.type, null, href);
|
||||||
|
|
|
@ -552,33 +552,52 @@ define([
|
||||||
for (var id in fd) {
|
for (var id in fd) {
|
||||||
id = Number(id);
|
id = Number(id);
|
||||||
var el = fd[id];
|
var el = fd[id];
|
||||||
|
|
||||||
|
// Clean corrupted data
|
||||||
if (!el || typeof(el) !== "object") {
|
if (!el || typeof(el) !== "object") {
|
||||||
debug("An element in filesData was not an object.", el);
|
debug("An element in filesData was not an object.", el);
|
||||||
toClean.push(id);
|
toClean.push(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Clean missing href
|
||||||
if (!el.href) {
|
if (!el.href) {
|
||||||
debug("Removing an element in filesData with a missing href.", el);
|
debug("Removing an element in filesData with a missing href.", el);
|
||||||
toClean.push(id);
|
toClean.push(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (/^https*:\/\//.test(el.href)) { el.href = Hash.getRelativeHref(el.href); }
|
|
||||||
if (!el.ctime) { el.ctime = el.atime; }
|
|
||||||
|
|
||||||
// Password not needed here since we only need the type and hash
|
|
||||||
var parsed = Hash.parsePadUrl(el.href);
|
var parsed = Hash.parsePadUrl(el.href);
|
||||||
if (!el.title) { el.title = Hash.getDefaultName(parsed); }
|
// Clean invalid hash
|
||||||
if (!parsed.hash) {
|
if (!parsed.hash) {
|
||||||
debug("Removing an element in filesData with a invalid href.", el);
|
debug("Removing an element in filesData with a invalid href.", el);
|
||||||
toClean.push(id);
|
toClean.push(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Clean invalid type
|
||||||
if (!parsed.type) {
|
if (!parsed.type) {
|
||||||
debug("Removing an element in filesData with a invalid type.", el);
|
debug("Removing an element in filesData with a invalid type.", el);
|
||||||
toClean.push(id);
|
toClean.push(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix href
|
||||||
|
if (/^https*:\/\//.test(el.href)) { el.href = Hash.getRelativeHref(el.href); }
|
||||||
|
// Fix creation time
|
||||||
|
if (!el.ctime) { el.ctime = el.atime; }
|
||||||
|
// Fix title
|
||||||
|
if (!el.title) { el.title = Hash.getDefaultName(parsed); }
|
||||||
|
// Fix channel
|
||||||
|
if (!el.channel) {
|
||||||
|
if (parsed.hashData && parsed.hashData.type === "file") {
|
||||||
|
// PASSWORD_FILES
|
||||||
|
el.channel = Util.base64ToHex(parsed.hashData.channel);
|
||||||
|
} else {
|
||||||
|
var secret = Hash.getSecrets(parsed.type, parsed.hash, el.password);
|
||||||
|
el.channel = secret.channel;
|
||||||
|
}
|
||||||
|
console.log('Adding missing channel in filesData ', el.channel);
|
||||||
|
}
|
||||||
|
|
||||||
if ((loggedIn || config.testMode) && rootFiles.indexOf(id) === -1) {
|
if ((loggedIn || config.testMode) && rootFiles.indexOf(id) === -1) {
|
||||||
debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", id, el);
|
debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", id, el);
|
||||||
var newName = Hash.createChannelId();
|
var newName = Hash.createChannelId();
|
||||||
|
|
|
@ -25,6 +25,7 @@ define([
|
||||||
var AppConfig;
|
var AppConfig;
|
||||||
var Test;
|
var Test;
|
||||||
var password;
|
var password;
|
||||||
|
var initialPathInDrive;
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
// Load #2, the loading screen is up so grab whatever you need...
|
// Load #2, the loading screen is up so grab whatever you need...
|
||||||
|
@ -295,8 +296,13 @@ define([
|
||||||
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) {
|
||||||
currentTitle = newTitle;
|
currentTitle = newTitle;
|
||||||
setDocumentTitle();
|
setDocumentTitle();
|
||||||
Cryptpad.setNewPadPassword(password);
|
var data = {
|
||||||
Cryptpad.setPadTitle(newTitle, undefined, undefined, function (err) {
|
password: password,
|
||||||
|
title: newTitle,
|
||||||
|
channel: secret.channel,
|
||||||
|
path: initialPathInDrive // Where to store the pad if we don't have it in our drive
|
||||||
|
};
|
||||||
|
Cryptpad.setPadTitle(data, function (err) {
|
||||||
cb(err);
|
cb(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -718,8 +724,6 @@ define([
|
||||||
var newHash = Utils.Hash.createRandomHash(parsed.type, password);
|
var newHash = Utils.Hash.createRandomHash(parsed.type, password);
|
||||||
secret = Utils.Hash.getSecrets(parsed.type, newHash, password);
|
secret = Utils.Hash.getSecrets(parsed.type, newHash, password);
|
||||||
|
|
||||||
Cryptpad.setNewPadPassword(password);
|
|
||||||
|
|
||||||
// Update the hash in the address bar
|
// Update the hash in the address bar
|
||||||
var ohc = window.onhashchange;
|
var ohc = window.onhashchange;
|
||||||
window.onhashchange = function () {};
|
window.onhashchange = function () {};
|
||||||
|
@ -744,7 +748,7 @@ define([
|
||||||
nThen(function(waitFor) {
|
nThen(function(waitFor) {
|
||||||
if (data.templateId) {
|
if (data.templateId) {
|
||||||
if (data.templateId === -1) {
|
if (data.templateId === -1) {
|
||||||
Cryptpad.setInitialPath(['template']);
|
initialPathInDrive = ['template'];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cryptpad.getPadData(data.templateId, waitFor(function (err, d) {
|
Cryptpad.getPadData(data.templateId, waitFor(function (err, d) {
|
||||||
|
|
Loading…
Reference in New Issue