Use the hidden hash when opening a pad from the drive

pull/1/head
yflory 5 years ago
parent 83c35543b9
commit 718610b6db

@ -68,10 +68,9 @@ var factory = function (Util, Crypto, Nacl) {
if (secret.keys && secret.keys.fileKeyStr) { mode = ''; } if (secret.keys && secret.keys.fileKeyStr) { mode = ''; }
var hash = '/3/' + type + '/' + mode + secret.channel + '/' + pass; var hash = '/3/' + type + '/' + mode + secret.channel + '/' + pass;
var href = '/' + type + '/#' + hash; var hashData = Hash.parseTypeHash(type, hash);
var parsed = Hash.parsePadUrl(href); if (hashData && hashData.getHash) {
if (parsed.hashData && parsed.hashData.getHash) { return hashData.getHash(opts || {});
return parsed.hashData.getHash(opts || {});
} }
return hash; return hash;
}; };
@ -380,6 +379,14 @@ Version 1
return ret; return ret;
}; };
Hash.hashToHref = function (hash, type) {
return '/' + type + '/#' + hash;
};
Hash.hrefToHref = function (href) {
var parsed = parsedPadUrl(href);
return parsed.hash;
};
Hash.getRelativeHref = function (href) { Hash.getRelativeHref = function (href) {
if (!href) { return; } if (!href) { return; }
if (href.indexOf('#') === -1) { return; } if (href.indexOf('#') === -1) { return; }

@ -1029,15 +1029,18 @@ define([
return ret; return ret;
}; };
var openFile = function (el, href) { var openFile = function (el, isRo) {
if (!href) {
var data = manager.getFileData(el); var data = manager.getFileData(el);
if (!data || (!data.href && !data.roHref)) { if (!data || (!data.href && !data.roHref)) {
return void logError("Missing data for the file", el, data); return void logError("Missing data for the file", el, data);
} }
href = data.href || data.roHref; var href = data.href || data.roHref;
} var parsed = Hash.parsePadUrl(href);
window.open(APP.origin + href); var secret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
var hash = Hash.getHiddenHashFromKeys(parsed.type, secret);
var hiddenHref = Hash.hashToHref(hash, parsed.type);
// XXX hidden hash: use settings
window.open(APP.origin + hiddenHref);
}; };
var refresh = APP.refresh = function () { var refresh = APP.refresh = function () {
@ -3034,7 +3037,7 @@ define([
$icon.append(getFileIcon(r.id)); $icon.append(getFileIcon(r.id));
$type.text(Messages.type[parsed.type] || parsed.type); $type.text(Messages.type[parsed.type] || parsed.type);
$title.click(function () { $title.click(function () {
openFile(null, r.data.href); openFile(r.id);
}); });
$atimeName.text(Messages.fm_lastAccess); $atimeName.text(Messages.fm_lastAccess);
$atime.text(new Date(r.data.atime).toLocaleString()); $atime.text(new Date(r.data.atime).toLocaleString());
@ -3944,15 +3947,12 @@ define([
// ANON_SHARED_FOLDER // ANON_SHARED_FOLDER
el = manager.find(paths[0].path.slice(1), APP.newSharedFolder); el = manager.find(paths[0].path.slice(1), APP.newSharedFolder);
} }
var href;
if (manager.isPathIn(p.path, [FILES_DATA])) { if (manager.isPathIn(p.path, [FILES_DATA])) {
href = el.roHref; el = p.path[1];
} else { } else {
if (!el || manager.isFolder(el)) { return; } if (!el || manager.isFolder(el)) { return; }
var data = manager.getFileData(el);
href = data.roHref;
} }
openFile(null, href); openFile(el, true);
}); });
} }
else if ($this.hasClass('cp-app-drive-context-openincode')) { else if ($this.hasClass('cp-app-drive-context-openincode')) {

Loading…
Cancel
Save