Download folders in drive - test (no UI)
This commit is contained in:
@@ -21,16 +21,22 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var transform = function (ctx, type, sjson, cb) {
|
var transform = function (ctx, type, sjson, cb) {
|
||||||
|
console.error("backup - transform");
|
||||||
|
console.log('type', type);
|
||||||
|
console.log('sjson', sjson);
|
||||||
|
|
||||||
var result = {
|
var result = {
|
||||||
data: sjson,
|
data: sjson,
|
||||||
ext: '.json',
|
ext: '.json',
|
||||||
};
|
};
|
||||||
|
console.log('result', result);
|
||||||
var json;
|
var json;
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(sjson);
|
json = JSON.parse(sjson);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return void cb(result);
|
return void cb(result);
|
||||||
}
|
}
|
||||||
|
console.log('json', json);
|
||||||
var path = '/' + type + '/export.js';
|
var path = '/' + type + '/export.js';
|
||||||
require([path], function (Exporter) {
|
require([path], function (Exporter) {
|
||||||
Exporter.main(json, function (data) {
|
Exporter.main(json, function (data) {
|
||||||
@@ -46,6 +52,8 @@ define([
|
|||||||
// Add a file to the zip. We have to cryptget&transform it if it's a pad
|
// Add a file to the zip. We have to cryptget&transform it if it's a pad
|
||||||
// or fetch&decrypt it if it's a file.
|
// or fetch&decrypt it if it's a file.
|
||||||
var addFile = function (ctx, zip, fData, existingNames) {
|
var addFile = function (ctx, zip, fData, existingNames) {
|
||||||
|
console.error('backup - addFile');
|
||||||
|
console.log('fData', fData);
|
||||||
if (!fData.href && !fData.roHref) {
|
if (!fData.href && !fData.roHref) {
|
||||||
return void ctx.errors.push({
|
return void ctx.errors.push({
|
||||||
error: 'EINVAL',
|
error: 'EINVAL',
|
||||||
@@ -54,6 +62,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
var parsed = Hash.parsePadUrl(fData.href || fData.roHref);
|
var parsed = Hash.parsePadUrl(fData.href || fData.roHref);
|
||||||
|
console.log('parsed', parsed);
|
||||||
if (['pad', 'file'].indexOf(parsed.hashData.type) === -1) { return; }
|
if (['pad', 'file'].indexOf(parsed.hashData.type) === -1) { return; }
|
||||||
|
|
||||||
// waitFor is used to make sure all the pads and files are process before downloading the zip.
|
// waitFor is used to make sure all the pads and files are process before downloading the zip.
|
||||||
@@ -189,6 +198,7 @@ define([
|
|||||||
var ctx = {
|
var ctx = {
|
||||||
get: getPad,
|
get: getPad,
|
||||||
data: data.uo.drive,
|
data: data.uo.drive,
|
||||||
|
folder: data.folder || ctx.data.root,
|
||||||
sf: data.sf,
|
sf: data.sf,
|
||||||
zip: new JsZip(),
|
zip: new JsZip(),
|
||||||
errors: [],
|
errors: [],
|
||||||
@@ -201,7 +211,7 @@ define([
|
|||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
ctx.waitFor = waitFor;
|
ctx.waitFor = waitFor;
|
||||||
var zipRoot = ctx.zip.folder('Root');
|
var zipRoot = ctx.zip.folder('Root');
|
||||||
makeFolder(ctx, ctx.data.root, zipRoot, ctx.data.filesData);
|
makeFolder(ctx, ctx.folder, zipRoot, ctx.data.filesData);
|
||||||
progress('download', {});
|
progress('download', {});
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
console.log(ctx.zip);
|
console.log(ctx.zip);
|
||||||
|
|||||||
@@ -3467,6 +3467,41 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var downloadFolder = function (folderElement, folderName) {
|
||||||
|
console.warn("downloadFolder");
|
||||||
|
var todo = function (data) {
|
||||||
|
var getPad = function (data, cb) {
|
||||||
|
sframeChan.query("Q_CRYPTGET", data, function (err, obj) {
|
||||||
|
if (err) { return void cb(err); }
|
||||||
|
if (obj.error) { return void cb(obj.error); }
|
||||||
|
cb(null, obj.data);
|
||||||
|
}, { timeout: 60000 });
|
||||||
|
};
|
||||||
|
|
||||||
|
data.folder = folderElement;
|
||||||
|
folderName = Util.fixFileName(folderName) + '.zip';
|
||||||
|
console.log("data", data);
|
||||||
|
console.log("folderName", folderName);
|
||||||
|
|
||||||
|
Backup.create(data, getPad, function (blob, errors) {
|
||||||
|
console.log("blob", blob);
|
||||||
|
window.saveAs(blob, folderName);
|
||||||
|
console.error(errors);
|
||||||
|
}, function () {});
|
||||||
|
};
|
||||||
|
sframeChan.query("Q_SETTINGS_DRIVE_GET", "full", function (err, data) {
|
||||||
|
console.warn("sframeChan.query Q_SETTINGS_DRIVE_GET callback");
|
||||||
|
console.log("err", err);
|
||||||
|
console.log("data", data);
|
||||||
|
if (err) { return void console.error(err); }
|
||||||
|
if (data.error) { return void console.error(data.error); }
|
||||||
|
todo(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
$contextMenu.on("click", "a", function(e) {
|
$contextMenu.on("click", "a", function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
var paths = $contextMenu.data('paths');
|
var paths = $contextMenu.data('paths');
|
||||||
@@ -3563,16 +3598,27 @@ define([
|
|||||||
console.log("el", el);
|
console.log("el", el);
|
||||||
console.log('path', path);
|
console.log('path', path);
|
||||||
console.log("APP", APP);
|
console.log("APP", APP);
|
||||||
|
|
||||||
// folder
|
// folder
|
||||||
if (manager.isFolder(el)) {
|
if (manager.isFolder(el)) {
|
||||||
// folder
|
// folder
|
||||||
|
var name, folderEl;
|
||||||
if (!manager.isSharedFolder(el)) {
|
if (!manager.isSharedFolder(el)) {
|
||||||
console.log("--isFolder--");
|
console.log("--isFolder--");
|
||||||
|
name = path.path[path.path.length - 1];
|
||||||
|
console.log('name', name);
|
||||||
|
folderEl = el;
|
||||||
|
downloadFolder(folderEl, name);
|
||||||
}
|
}
|
||||||
// shared folder
|
// shared folder
|
||||||
else {
|
else {
|
||||||
console.log("--isSharedFolder--");
|
console.log("--isSharedFolder--");
|
||||||
|
data = manager.getSharedFolderData(el);
|
||||||
|
name = data.title;
|
||||||
|
folderEl = manager.find(path.path.concat("root"));
|
||||||
|
console.log("folderEl", folderEl);
|
||||||
|
console.log("data:", data);
|
||||||
|
console.log('name', name);
|
||||||
|
downloadFolder(folderEl, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// file
|
// file
|
||||||
|
|||||||
@@ -63,6 +63,31 @@ define([
|
|||||||
Utils.LocalStore.clearThumbnail();
|
Utils.LocalStore.clearThumbnail();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
sframeChan.on('Q_SETTINGS_DRIVE_GET', function (d, cb) {
|
||||||
|
Cryptpad.getUserObject(function (obj) {
|
||||||
|
if (obj.error) { return void cb(obj); }
|
||||||
|
if (d === "full") {
|
||||||
|
// We want shared folders too
|
||||||
|
var result = {
|
||||||
|
uo: obj,
|
||||||
|
sf: {}
|
||||||
|
};
|
||||||
|
if (!obj.drive || !obj.drive.sharedFolders) { return void cb(result); }
|
||||||
|
Utils.nThen(function (waitFor) {
|
||||||
|
Object.keys(obj.drive.sharedFolders).forEach(function (id) {
|
||||||
|
Cryptpad.getSharedFolder(id, waitFor(function (obj) {
|
||||||
|
result.sf[id] = obj;
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}).nThen(function () {
|
||||||
|
cb(result);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// We want only the user object
|
||||||
|
cb(obj);
|
||||||
|
});
|
||||||
|
});
|
||||||
sframeChan.on('Q_DRIVE_USEROBJECT', function (data, cb) {
|
sframeChan.on('Q_DRIVE_USEROBJECT', function (data, cb) {
|
||||||
Cryptpad.userObjectCommand(data, cb);
|
Cryptpad.userObjectCommand(data, cb);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user