Store the channel id as pad attribute
This commit is contained in:
@@ -685,10 +685,11 @@ define([
|
||||
Store.setPadTitle = function (data, cb) {
|
||||
var title = data.title;
|
||||
var href = data.href;
|
||||
var padData = store.userObject.getFileData(store.userObject.getIdFromHref(href));
|
||||
var p = Hash.parsePadUrl(href, padData && padData.password);
|
||||
var channel = data.channel;
|
||||
var p = Hash.parsePadUrl(href);
|
||||
var h = p.hashData;
|
||||
|
||||
console.log(channel, data);
|
||||
if (AppConfig.disableAnonymousStore && !store.loggedIn) { return void cb(); }
|
||||
|
||||
var owners;
|
||||
@@ -713,19 +714,19 @@ define([
|
||||
var pad = allPads[id];
|
||||
if (!pad.href) { continue; }
|
||||
|
||||
var p2 = Hash.parsePadUrl(pad.href, pad.password);
|
||||
var p2 = Hash.parsePadUrl(pad.href);
|
||||
var h2 = p2.hashData;
|
||||
|
||||
// Different types, proceed to the next one
|
||||
// No hash data: corrupted pad?
|
||||
if (p.type !== p2.type || !h2) { continue; }
|
||||
// Different channel: continue
|
||||
if (pad.channel !== channel) { continue; }
|
||||
|
||||
var shouldUpdate = p.hash.replace(/\/$/, '') === p2.hash.replace(/\/$/, '');
|
||||
|
||||
// If the hash is different but represents the same channel, check if weaker or stronger
|
||||
if (!shouldUpdate &&
|
||||
h.version === h2.version &&
|
||||
h.channel === h2.channel) {
|
||||
if (!shouldUpdate && h.version !== 0) {
|
||||
// We had view & now we have edit, update
|
||||
if (h2.mode === 'view' && h.mode === 'edit') { shouldUpdate = true; }
|
||||
// Same mode and we had present URL, update
|
||||
@@ -762,13 +763,13 @@ define([
|
||||
if (!contains) {
|
||||
Store.addPad({
|
||||
href: href,
|
||||
channel: channel,
|
||||
title: title,
|
||||
owners: owners,
|
||||
expire: expire,
|
||||
password: store.data && store.data.newPadPassword,
|
||||
path: data.path || (store.data && store.data.initialPath)
|
||||
password: data.password,
|
||||
path: data.path
|
||||
}, cb);
|
||||
delete store.data.newPadPassword;
|
||||
return;
|
||||
}
|
||||
onSync(cb);
|
||||
@@ -807,14 +808,6 @@ define([
|
||||
Store.getPadData = function (id, cb) {
|
||||
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)
|
||||
|
||||
@@ -120,12 +120,6 @@ define([
|
||||
case 'GET_PAD_DATA': {
|
||||
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': {
|
||||
Store.getStrongerHash(data, cb); break;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,14 @@ define([
|
||||
|
||||
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); }
|
||||
onComplete(href);
|
||||
common.setPadAttribute('fileType', metadata.type, null, href);
|
||||
|
||||
@@ -552,33 +552,52 @@ define([
|
||||
for (var id in fd) {
|
||||
id = Number(id);
|
||||
var el = fd[id];
|
||||
|
||||
// Clean corrupted data
|
||||
if (!el || typeof(el) !== "object") {
|
||||
debug("An element in filesData was not an object.", el);
|
||||
toClean.push(id);
|
||||
continue;
|
||||
}
|
||||
// Clean missing href
|
||||
if (!el.href) {
|
||||
debug("Removing an element in filesData with a missing href.", el);
|
||||
toClean.push(id);
|
||||
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);
|
||||
if (!el.title) { el.title = Hash.getDefaultName(parsed); }
|
||||
// Clean invalid hash
|
||||
if (!parsed.hash) {
|
||||
debug("Removing an element in filesData with a invalid href.", el);
|
||||
toClean.push(id);
|
||||
continue;
|
||||
}
|
||||
// Clean invalid type
|
||||
if (!parsed.type) {
|
||||
debug("Removing an element in filesData with a invalid type.", el);
|
||||
toClean.push(id);
|
||||
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) {
|
||||
debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", id, el);
|
||||
var newName = Hash.createChannelId();
|
||||
|
||||
Reference in New Issue
Block a user