From 6fa7ea583f507ea71be3d7afd5c30eb34c3bd390 Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Mon, 28 Oct 2024 12:48:16 +0100 Subject: [PATCH 01/10] Links are now part of Drive exports #942 --- www/common/make-backup.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 4e1d2b205..0b5e7d578 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -170,9 +170,17 @@ define([ }); } - var href = (fData.href && fData.href.indexOf('#') !== -1) ? fData.href : fData.roHref; - var parsed = Hash.parsePadUrl(href); - if (['pad', 'file'].indexOf(parsed.hashData.type) === -1) { return; } + var href; + var parsed; + if (fData.href.indexOf('https') !== -1 && fData.href.indexOf('http') !== -1) { + href = fData.href; + parsed = {}; + parsed['hashData'] = {type: 'link'}; + } else { + href = (fData.href && fData.href.indexOf('#') !== -1) ? fData.href : fData.roHref; + parsed = Hash.parsePadUrl(href); + } + if (['pad', 'file', 'link'].indexOf(parsed.hashData.type) === -1) { return; } // waitFor is used to make sure all the pads and files are process before downloading the zip. var w = ctx.waitFor(); @@ -220,7 +228,7 @@ define([ var opts = { password: fData.password }; - var rawName = fData.filename || fData.title || 'File'; + var rawName = fData.filename || fData.title || fData.name || 'File'; console.log(rawName); // Pads (pad,code,slide,kanban,poll,...) @@ -276,8 +284,21 @@ define([ } }, 50); }; + var todoLink = function () { + var opts = { + binary: true, + }; + var fileName = getUnique(sanitize(rawName), '.txt', existingNames); + existingNames.push(fileName.toLowerCase()); + var content = new Blob([fData.href], { type : "text/html;charset=utf-8" }); + zip.file(fileName, content, opts); + console.log('DONE ---- ' + fileName); + setTimeout(done, 1000); + }; if (parsed.hashData.type === 'file') { return void todoFile(); + } else if (parsed.hashData.type === 'link') { + return void todoLink(); } todoPad(); }); @@ -330,6 +351,10 @@ define([ sframeChan: sframeChan }; var filesData = data.sharedFolderId && ctx.sf[data.sharedFolderId] ? ctx.sf[data.sharedFolderId].filesData : ctx.data.filesData; + var links = ctx.data.static; + Object.keys(links).forEach(function(key) { + filesData[key] = links[key]; + }); progress('reading', -1); // Msg.settings_export_reading nThen(function (waitFor) { ctx.waitFor = waitFor; From b4dc9715d6021d38c6b860751e0376235c3c5a1e Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Tue, 29 Oct 2024 13:20:02 +0100 Subject: [PATCH 02/10] Added regex & fixed issue with read-only pads --- www/common/make-backup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 0b5e7d578..e83e4a781 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -169,10 +169,10 @@ define([ data: fData }); } - var href; var parsed; - if (fData.href.indexOf('https') !== -1 && fData.href.indexOf('http') !== -1) { + var linkRegex = new RegExp("^(http|https)://"); + if (fData.href && linkRegex.test(fData.href)) { href = fData.href; parsed = {}; parsed['hashData'] = {type: 'link'}; From 2796999be82b508b142bd4626f481e54135759aa Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Thu, 5 Dec 2024 14:33:32 +0100 Subject: [PATCH 03/10] Changed export file type & formatting --- www/common/make-backup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index e83e4a781..e90c93921 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -290,7 +290,7 @@ define([ }; var fileName = getUnique(sanitize(rawName), '.txt', existingNames); existingNames.push(fileName.toLowerCase()); - var content = new Blob([fData.href], { type : "text/html;charset=utf-8" }); + var content = new Blob([fData.href, '\n'], { type: "text/plain;charset=utf-8" }); zip.file(fileName, content, opts); console.log('DONE ---- ' + fileName); setTimeout(done, 1000); From 0b998a890dd4e5c86829fad2d97e0b2d70a60e93 Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Fri, 6 Dec 2024 13:33:01 +0100 Subject: [PATCH 04/10] Links in shared folders included in .zip --- www/common/make-backup.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index e90c93921..baf3161e8 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -307,26 +307,32 @@ define([ }; // Add folders and their content recursively in the zip - var makeFolder = function (ctx, root, zip, fd) { + var makeFolder = function (ctx, root, zip, fd, sd) { if (typeof (root) !== "object") { return; } var existingNames = []; Object.keys(root).forEach(function (k) { var el = root[k]; + let staticData; if (typeof el === "object" && el.metadata !== true) { // if folder var fName = getUnique(sanitize(k), '', existingNames); existingNames.push(fName.toLowerCase()); return void makeFolder(ctx, el, zip.folder(fName), fd); } if (ctx.data.sharedFolders[el]) { // if shared folder + staticData = ctx.sf[el].static; var sfData = ctx.sf[el].metadata; var sfName = getUnique(sanitize((sfData && sfData.title) || 'Folder'), '', existingNames); existingNames.push(sfName.toLowerCase()); - return void makeFolder(ctx, ctx.sf[el].root, zip.folder(sfName), ctx.sf[el].filesData); + return void makeFolder(ctx, ctx.sf[el].root, zip.folder(sfName), ctx.sf[el].filesData, staticData); } var fData = fd[el]; + var sData = sd[el]; if (fData) { addFile(ctx, zip, fData, existingNames); return; + } else if (sData) { + addFile(ctx, zip, sData, existingNames); + return; } }); }; From 2fb05156f0924d5ec7d3a9633cac61b0814bdd4a Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Fri, 6 Dec 2024 14:26:55 +0100 Subject: [PATCH 05/10] Shared folder fixes --- www/common/make-backup.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index baf3161e8..93e4e2850 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -316,7 +316,7 @@ define([ if (typeof el === "object" && el.metadata !== true) { // if folder var fName = getUnique(sanitize(k), '', existingNames); existingNames.push(fName.toLowerCase()); - return void makeFolder(ctx, el, zip.folder(fName), fd); + return void makeFolder(ctx, el, zip.folder(fName), fd, sd); } if (ctx.data.sharedFolders[el]) { // if shared folder staticData = ctx.sf[el].static; @@ -325,8 +325,9 @@ define([ existingNames.push(sfName.toLowerCase()); return void makeFolder(ctx, ctx.sf[el].root, zip.folder(sfName), ctx.sf[el].filesData, staticData); } + var sData; var fData = fd[el]; - var sData = sd[el]; + sd ? sData = sd[el] : sData = undefined if (fData) { addFile(ctx, zip, fData, existingNames); return; From 470a5711cf6732749dbf8033df66200173614c46 Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Fri, 6 Dec 2024 14:29:24 +0100 Subject: [PATCH 06/10] Linting --- www/common/make-backup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 93e4e2850..17a5be462 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -327,7 +327,7 @@ define([ } var sData; var fData = fd[el]; - sd ? sData = sd[el] : sData = undefined + sd ? sData = sd[el] : sData = undefined; if (fData) { addFile(ctx, zip, fData, existingNames); return; From dc7d94ea770da9a6f346738fc4f4f1aff703b38f Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Fri, 6 Dec 2024 18:47:56 +0100 Subject: [PATCH 07/10] Links included in standalone folder downloads --- www/common/make-backup.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 17a5be462..78270831a 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -358,7 +358,8 @@ define([ sframeChan: sframeChan }; var filesData = data.sharedFolderId && ctx.sf[data.sharedFolderId] ? ctx.sf[data.sharedFolderId].filesData : ctx.data.filesData; - var links = ctx.data.static; + var links = ctx.sf[data.sharedFolderId] && ctx.sf[data.sharedFolderId].static ? ctx.data.static && ctx.sf[data.sharedFolderId].static : ctx.data.static + Object.keys(links).forEach(function(key) { filesData[key] = links[key]; }); From 3385ac8843bd3c94f56dc1d068ea2ce558512977 Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Fri, 6 Dec 2024 18:49:18 +0100 Subject: [PATCH 08/10] Syntax correction --- www/common/make-backup.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 78270831a..98a4f5357 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -325,9 +325,8 @@ define([ existingNames.push(sfName.toLowerCase()); return void makeFolder(ctx, ctx.sf[el].root, zip.folder(sfName), ctx.sf[el].filesData, staticData); } - var sData; var fData = fd[el]; - sd ? sData = sd[el] : sData = undefined; + var sData = sd ? sd[el] : undefined; if (fData) { addFile(ctx, zip, fData, existingNames); return; From 04dff2738139291c922945774a78ce2e6a414bb1 Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Fri, 6 Dec 2024 18:52:05 +0100 Subject: [PATCH 09/10] Linting --- www/common/make-backup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 98a4f5357..fd2145ee2 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -357,7 +357,7 @@ define([ sframeChan: sframeChan }; var filesData = data.sharedFolderId && ctx.sf[data.sharedFolderId] ? ctx.sf[data.sharedFolderId].filesData : ctx.data.filesData; - var links = ctx.sf[data.sharedFolderId] && ctx.sf[data.sharedFolderId].static ? ctx.data.static && ctx.sf[data.sharedFolderId].static : ctx.data.static + var links = ctx.sf[data.sharedFolderId] && ctx.sf[data.sharedFolderId].static ? ctx.data.static && ctx.sf[data.sharedFolderId].static : ctx.data.static; Object.keys(links).forEach(function(key) { filesData[key] = links[key]; From 8b5df20220bea3f5d6313c7e0697d51f6659d701 Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Tue, 10 Dec 2024 13:44:24 +0100 Subject: [PATCH 10/10] Fixes --- www/common/make-backup.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index fd2145ee2..75bd19b78 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -171,8 +171,7 @@ define([ } var href; var parsed; - var linkRegex = new RegExp("^(http|https)://"); - if (fData.href && linkRegex.test(fData.href)) { + if (!fData.channel) { href = fData.href; parsed = {}; parsed['hashData'] = {type: 'link'}; @@ -312,28 +311,23 @@ define([ var existingNames = []; Object.keys(root).forEach(function (k) { var el = root[k]; - let staticData; if (typeof el === "object" && el.metadata !== true) { // if folder var fName = getUnique(sanitize(k), '', existingNames); existingNames.push(fName.toLowerCase()); return void makeFolder(ctx, el, zip.folder(fName), fd, sd); } if (ctx.data.sharedFolders[el]) { // if shared folder - staticData = ctx.sf[el].static; + let staticData = ctx.sf[el].static; var sfData = ctx.sf[el].metadata; var sfName = getUnique(sanitize((sfData && sfData.title) || 'Folder'), '', existingNames); existingNames.push(sfName.toLowerCase()); return void makeFolder(ctx, ctx.sf[el].root, zip.folder(sfName), ctx.sf[el].filesData, staticData); } - var fData = fd[el]; - var sData = sd ? sd[el] : undefined; + var fData = fd[el] || (sd && sd[el]); if (fData) { addFile(ctx, zip, fData, existingNames); return; - } else if (sData) { - addFile(ctx, zip, sData, existingNames); - return; - } + } }); }; @@ -359,14 +353,11 @@ define([ var filesData = data.sharedFolderId && ctx.sf[data.sharedFolderId] ? ctx.sf[data.sharedFolderId].filesData : ctx.data.filesData; var links = ctx.sf[data.sharedFolderId] && ctx.sf[data.sharedFolderId].static ? ctx.data.static && ctx.sf[data.sharedFolderId].static : ctx.data.static; - Object.keys(links).forEach(function(key) { - filesData[key] = links[key]; - }); progress('reading', -1); // Msg.settings_export_reading nThen(function (waitFor) { ctx.waitFor = waitFor; var zipRoot = ctx.zip.folder(data.name || Messages.fm_rootName); - makeFolder(ctx, ctx.folder || ctx.data.root, zipRoot, filesData); + makeFolder(ctx, ctx.folder || ctx.data.root, zipRoot, filesData, links); progress('download', {}); // Msg.settings_export_download }).nThen(function () { console.log(ctx.zip);