mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Merge pull request #1695 from cryptpad/link_exports
Links included in Drive exports
This commit is contained in:
commit
3f378aed47
@ -169,10 +169,17 @@ define([
|
||||
data: fData
|
||||
});
|
||||
}
|
||||
|
||||
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.channel) {
|
||||
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 +227,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 +283,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, '\n'], { type: "text/plain;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();
|
||||
});
|
||||
@ -286,7 +306,7 @@ 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) {
|
||||
@ -294,19 +314,20 @@ 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
|
||||
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);
|
||||
return void makeFolder(ctx, ctx.sf[el].root, zip.folder(sfName), ctx.sf[el].filesData, staticData);
|
||||
}
|
||||
var fData = fd[el];
|
||||
var fData = fd[el] || (sd && sd[el]);
|
||||
if (fData) {
|
||||
addFile(ctx, zip, fData, existingNames);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -330,11 +351,13 @@ 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;
|
||||
|
||||
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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user