Skip to content

Links included in Drive exports #1695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 12, 2024
45 changes: 34 additions & 11 deletions www/common/make-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,...)
Expand Down Expand Up @@ -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();
});
Expand All @@ -286,27 +306,28 @@ 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];
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;
}
}
});
};

Expand All @@ -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);
Expand Down