refactor exportcontext to taskcontext

This commit is contained in:
zadam
2019-10-18 22:27:38 +02:00
parent 157bd3816d
commit 56e4f4f5ac
9 changed files with 37 additions and 93 deletions

View File

@@ -3,7 +3,7 @@
const repository = require("../repository");
const utils = require('../utils');
async function exportToOpml(exportContext, branch, version, res) {
async function exportToOpml(taskContext, branch, version, res) {
if (!['1.0', '2.0'].includes(version)) {
throw new Error("Unrecognized OPML version " + version);
}
@@ -38,7 +38,7 @@ async function exportToOpml(exportContext, branch, version, res) {
throw new Error("Unrecognized OPML version " + opmlVersion);
}
exportContext.increaseProgressCount();
taskContext.increaseProgressCount();
for (const child of await note.getChildBranches()) {
await exportNoteInner(child.branchId);
@@ -66,7 +66,7 @@ async function exportToOpml(exportContext, branch, version, res) {
</opml>`);
res.end();
exportContext.exportFinished();
taskContext.taskSucceeded();
}
function prepareText(text) {

View File

@@ -5,7 +5,7 @@ const html = require('html');
const utils = require('../utils');
const mdService = require('./md');
async function exportSingleNote(exportContext, branch, format, res) {
async function exportSingleNote(taskContext, branch, format, res) {
const note = await branch.getNote();
if (note.type === 'image' || note.type === 'file') {
@@ -54,8 +54,8 @@ async function exportSingleNote(exportContext, branch, format, res) {
res.send(payload);
exportContext.increaseProgressCount();
exportContext.exportFinished();
taskContext.increaseProgressCount();
taskContext.taskSucceeded();
}
module.exports = {

View File

@@ -12,11 +12,11 @@ const protectedSessionService = require('../protected_session');
const sanitize = require("sanitize-filename");
/**
* @param {ExportContext} exportContext
* @param {TaskContext} taskContext
* @param {Branch} branch
* @param {string} format - 'html' or 'markdown'
*/
async function exportToTar(exportContext, branch, format, res) {
async function exportToTar(taskContext, branch, format, res) {
const pack = tar.pack();
const noteIdToMeta = {};
@@ -124,7 +124,7 @@ async function exportToTar(exportContext, branch, format, res) {
})
};
exportContext.increaseProgressCount();
taskContext.increaseProgressCount();
if (note.type === 'text') {
meta.format = format;
@@ -268,7 +268,7 @@ ${content}
pack.entry({name: filePathPrefix + noteMeta.dataFileName, size: content.length}, content);
}
exportContext.increaseProgressCount();
taskContext.increaseProgressCount();
if (noteMeta.children && noteMeta.children.length > 0) {
const directoryPath = filePathPrefix + noteMeta.dirFileName;
@@ -315,7 +315,7 @@ ${content}
pack.pipe(res);
exportContext.exportFinished();
taskContext.taskSucceeded();
}
module.exports = {

View File

@@ -390,7 +390,9 @@ async function updateNote(noteId, noteUpdates) {
}
/** @return {boolean} - true if note has been deleted, false otherwise */
async function deleteBranch(branch) {
async function deleteBranch(branch, taskContext) {
taskContext.increaseProgressCount();
if (!branch || branch.isDeleted) {
return false;
}
@@ -413,7 +415,7 @@ async function deleteBranch(branch) {
await note.save();
for (const childBranch of await note.getChildBranches()) {
await deleteBranch(childBranch);
await deleteBranch(childBranch, taskContext);
}
for (const attribute of await note.getOwnedAttributes()) {