implement minor fixes and add comments following code review

pull/1/head
ansuz 3 years ago
parent 6faaec5042
commit 2019e1d70a

@ -42,7 +42,8 @@ define([
Pages) Pages)
{ {
Messages.fm_link = "Link"; // XXX Messages.fm_link = "Link"; // XXX "New Link" ?
// XXX check for all occurrences of `fm_link` before changing it
var APP = window.APP = { var APP = window.APP = {
editable: false, editable: false,
@ -1924,10 +1925,10 @@ define([
var $name = $('<span>', {'class': 'cp-app-drive-element-name'}).text(name); var $name = $('<span>', {'class': 'cp-app-drive-element-name'}).text(name);
$element.append($name); $element.append($name);
if (getViewMode() === 'grid') { if (getViewMode() === 'grid') {
$element.attr('title', name); $element.attr('title', name); // XXX Util.fixHTML
} }
var type = Messages.fm_link; var type = Messages.fm_link; // XXX new translation key ("Link")
var $type = $('<span>', { var $type = $('<span>', {
'class': 'cp-app-drive-element-type cp-app-drive-element-list' 'class': 'cp-app-drive-element-type cp-app-drive-element-list'
}).text(type); }).text(type);

@ -238,7 +238,8 @@ define([
// content.name, content.title, content.href, content.password // content.name, content.title, content.href, content.password
if (isMuted(ctx, data)) { return void cb(true); } if (isMuted(ctx, data)) { return void cb(true); }
// if the shared content is a 'link' then we can't use the channel to deduplicate notifications
// use href instead.
var channel = content.isStatic ? content.href : Hash.hrefToHexChannelId(content.href, content.password); var channel = content.isStatic ? content.href : Hash.hrefToHexChannelId(content.href, content.password);
var parsed = Hash.parsePadUrl(content.href); var parsed = Hash.parsePadUrl(content.href);
var mode = parsed.hashData && parsed.hashData.mode || 'n/a'; var mode = parsed.hashData && parsed.hashData.mode || 'n/a';

@ -616,13 +616,18 @@ define([
var element = elem || files[ROOT]; var element = elem || files[ROOT];
if (!element) { return console.error("Invalid element in root"); } if (!element) { return console.error("Invalid element in root"); }
var nbMetadataFolders = 0; var nbMetadataFolders = 0;
// caching this variables saves a lot of hashmap lookups in this loop
var static_data = files[STATIC_DATA];
var files_data = files[FILES_DATA];
var element_el;
for (var el in element) { for (var el in element) {
if (element[el] === null) { element_el = element[el];
if (element_el === null) {
console.error('element[%s] is null', el); console.error('element[%s] is null', el);
delete element[el]; delete element[el];
continue; continue;
} }
if (exp.isFolderData(element[el])) { if (exp.isFolderData(element_el)) {
if (nbMetadataFolders !== 0) { if (nbMetadataFolders !== 0) {
debug("Multiple metadata files in folder"); debug("Multiple metadata files in folder");
delete element[el]; delete element[el];
@ -630,30 +635,30 @@ define([
nbMetadataFolders++; nbMetadataFolders++;
continue; continue;
} }
if (!exp.isFile(element[el], true) && !exp.isFolder(element[el])) { if (!exp.isFile(element_el, true) && !exp.isFolder(element_el)) {
debug("An element in ROOT was not a folder nor a file. ", element[el]); debug("An element in ROOT was not a folder nor a file. ", element_el);
delete element[el]; delete element[el];
continue; continue;
} }
if (exp.isFolder(element[el])) { if (exp.isFolder(element_el)) {
fixRoot(element[el]); fixRoot(element_el);
continue; continue;
} }
if (typeof element[el] === "string") { if (typeof element_el === "string") {
// We have an old file (href) which is not in filesData: add it // We have an old file (href) which is not in filesData: add it
var id = Util.createRandomInteger(); var id = Util.createRandomInteger();
var key = Hash.createChannelId(); var key = Hash.createChannelId();
files[FILES_DATA][id] = { files_data[id] = {
href: exp.cryptor.encrypt(element[el]), href: exp.cryptor.encrypt(element_el),
filename: el filename: el
}; };
element[key] = id; element[key] = id;
delete element[el]; delete element[el];
} }
if (typeof element[el] === "number") { if (typeof element_el === "number") {
var data = files[FILES_DATA][element[el]] || files[STATIC_DATA][element[el]]; var data = files_data[element_el] || static_data[element_el];
if (!data) { if (!data) {
debug("An element in ROOT doesn't have associated data", element[el], el); debug("An element in ROOT doesn't have associated data", element_el, el);
delete element[el]; delete element[el];
} }
} }
@ -862,6 +867,7 @@ define([
toClean.forEach(function (id) { toClean.forEach(function (id) {
spliceFileData(id); spliceFileData(id);
}); });
// make sure that links are displayed at least once in your drive if you are going to keep them
var sd = files[STATIC_DATA]; var sd = files[STATIC_DATA];
var toCleanSD = []; var toCleanSD = [];
for (var id2 in sd) { for (var id2 in sd) {
@ -929,7 +935,7 @@ define([
} }
}; };
var fixStaticData = function () { var fixStaticData = function () {
if (typeof(files[STATIC_DATA]) !== "object") { if (Util.isObject(files[STATIC_DATA])) {
debug("STATIC_DATA was not an object"); debug("STATIC_DATA was not an object");
files[STATIC_DATA] = {}; files[STATIC_DATA] = {};
} }

@ -24,6 +24,8 @@ define([
sframeChan.on('Q_DRIVE_USEROBJECT', function (data, cb) { sframeChan.on('Q_DRIVE_USEROBJECT', function (data, cb) {
if (!teamId) { return void cb({error: 'EINVAL'}); } if (!teamId) { return void cb({error: 'EINVAL'}); }
// a teamId of -1 bypasses guards against modifying your drive
// from the team app
if (data.teamId !== -1) { data.teamId = teamId; } if (data.teamId !== -1) { data.teamId = teamId; }
else { delete data.teamId; } else { delete data.teamId; }
Cryptpad.userObjectCommand(data, cb); Cryptpad.userObjectCommand(data, cb);

Loading…
Cancel
Save