From bd85f1b003fbc2ef206f357ba5cb293dc4e56834 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 1 Dec 2017 10:16:48 +0100 Subject: [PATCH] Fix file upload and remove unnecessary dependencies --- www/common/cryptpad-common.js | 7 ++++--- www/common/outer/async-store.js | 2 +- www/common/outer/upload.js | 3 +-- www/common/sframe-common-outer.js | 2 +- www/common/userObject.js | 17 ++++++++--------- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 45c401175..dc8a37025 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -129,7 +129,7 @@ define([ common.getMetadata = function (cb) { postMessage("GET_METADATA", null, function (obj) { - if (obj.error) { return void cb(obj.error); } + if (obj && obj.error) { return void cb(obj.error); } cb(null, obj); }); }; @@ -291,7 +291,7 @@ define([ }; // When opening a new pad or renaming it, store the new title - common.setPadTitle = function (title, padHref, cb) { + common.setPadTitle = function (title, padHref, path, cb) { var href = padHref || window.location.href; var parsed = Hash.parsePadUrl(href); if (!parsed.hash) { return; } @@ -302,7 +302,8 @@ define([ postMessage("SET_PAD_TITLE", { href: href, - title: title + title: title, + path: path }, function (obj) { if (obj && obj.error) { console.log("unable to set pad title"); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index bf7dae60e..b67153830 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -568,7 +568,7 @@ define([ Store.addPad({ href: href, title: title, - path: store.data && store.data.initialPath + path: data.path || (store.data && store.data.initialPath) }, cb); return; } diff --git a/www/common/outer/upload.js b/www/common/outer/upload.js index 381c9bc4d..cce3e6b3c 100644 --- a/www/common/outer/upload.js +++ b/www/common/outer/upload.js @@ -58,8 +58,7 @@ define([ if (noStore) { return void onComplete(href); } - common.initialPath = path; - common.renamePad(title || "", href, function (err) { + common.setPadTitle(title || "", href, path, function (err) { if (err) { return void console.error(err); } onComplete(href); common.setPadAttribute('fileType', metadata.type, null, href); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 9d245959a..76510078b 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -234,7 +234,7 @@ define([ sframeChan.on('Q_SET_PAD_TITLE_IN_DRIVE', function (newTitle, cb) { currentTitle = newTitle; setDocumentTitle(); - Cryptpad.setPadTitle(newTitle, undefined, function (err) { + Cryptpad.setPadTitle(newTitle, undefined, undefined, function (err) { cb(err); }); }); diff --git a/www/common/userObject.js b/www/common/userObject.js index 35d5690b9..d2beb93a9 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -1,12 +1,11 @@ define([ - 'jquery', '/customize/application_config.js', '/common/common-util.js', '/common/common-hash.js', '/common/common-realtime.js', '/common/common-constants.js', '/customize/messages.js' -], function ($, AppConfig, Util, Hash, Realtime, Constants, Messages) { +], function (AppConfig, Util, Hash, Realtime, Constants, Messages) { var module = {}; var ROOT = module.ROOT = "root"; @@ -101,7 +100,7 @@ define([ }; for (var f in element) { if (trashRoot) { - if ($.isArray(element[f])) { + if (Array.isArray(element[f])) { element[f].forEach(addSubfolder); } } else { @@ -119,7 +118,7 @@ define([ }; for (var f in element) { if (trashRoot) { - if ($.isArray(element[f])) { + if (Array.isArray(element[f])) { element[f].forEach(addFile); } } else { @@ -148,14 +147,14 @@ define([ return data.filename || data.title || NEW_FILE_NAME; }; exp.getPadAttribute = function (href, attr, cb) { - cb = cb || $.noop; + cb = cb || function () {}; var id = exp.getIdFromHref(href); if (!id) { return void cb(null, undefined); } var data = getFileData(id); cb(null, clone(data[attr])); }; exp.setPadAttribute = function (href, attr, value, cb) { - cb = cb || $.noop; + cb = cb || function () {}; var id = exp.getIdFromHref(href); if (!id) { return void cb("E_INVAL_HREF"); } if (!attr || !attr.trim()) { return void cb("E_INVAL_ATTR"); } @@ -167,7 +166,7 @@ define([ // PATHS var comparePath = exp.comparePath = function (a, b) { - if (!a || !b || !$.isArray(a) || !$.isArray(b)) { return false; } + if (!a || !b || !Array.isArray(a) || !Array.isArray(b)) { return false; } if (a.length !== b.length) { return false; } var result = true; var i = a.length - 1; @@ -265,7 +264,7 @@ define([ } }; for (var e in root) { - if (!$.isArray(root[e])) { + if (!Array.isArray(root[e])) { error("Trash contains a non-array element"); return; } @@ -967,7 +966,7 @@ define([ var addToClean = function (obj, idx, el) { if (typeof(obj) !== "object") { toClean.push(idx); return; } if (!isFile(obj.element, true) && !isFolder(obj.element)) { toClean.push(idx); return; } - if (!$.isArray(obj.path)) { toClean.push(idx); return; } + if (!Array.isArray(obj.path)) { toClean.push(idx); return; } if (typeof obj.element === "string") { // We have an old file (href) which is not in filesData: add it var id = Util.createRandomInteger();