Download folders in drive - test (no UI)

pull/1/head
ClemDee 5 years ago
parent 4f26986fde
commit 4b027e83ad

@ -21,16 +21,22 @@ define([
};
var transform = function (ctx, type, sjson, cb) {
console.error("backup - transform");
console.log('type', type);
console.log('sjson', sjson);
var result = {
data: sjson,
ext: '.json',
};
console.log('result', result);
var json;
try {
json = JSON.parse(sjson);
} catch (e) {
return void cb(result);
}
console.log('json', json);
var path = '/' + type + '/export.js';
require([path], function (Exporter) {
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
// or fetch&decrypt it if it's a file.
var addFile = function (ctx, zip, fData, existingNames) {
console.error('backup - addFile');
console.log('fData', fData);
if (!fData.href && !fData.roHref) {
return void ctx.errors.push({
error: 'EINVAL',
@ -54,6 +62,7 @@ define([
}
var parsed = Hash.parsePadUrl(fData.href || fData.roHref);
console.log('parsed', parsed);
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.
@ -189,6 +198,7 @@ define([
var ctx = {
get: getPad,
data: data.uo.drive,
folder: data.folder || ctx.data.root,
sf: data.sf,
zip: new JsZip(),
errors: [],
@ -201,7 +211,7 @@ define([
nThen(function (waitFor) {
ctx.waitFor = waitFor;
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', {});
}).nThen(function () {
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) {
e.stopPropagation();
var paths = $contextMenu.data('paths');
@ -3563,16 +3598,27 @@ define([
console.log("el", el);
console.log('path', path);
console.log("APP", APP);
// folder
if (manager.isFolder(el)) {
// folder
var name, folderEl;
if (!manager.isSharedFolder(el)) {
console.log("--isFolder--");
name = path.path[path.path.length - 1];
console.log('name', name);
folderEl = el;
downloadFolder(folderEl, name);
}
// shared folder
else {
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

@ -63,6 +63,31 @@ define([
Utils.LocalStore.clearThumbnail();
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) {
Cryptpad.userObjectCommand(data, cb);
});

Loading…
Cancel
Save