From c7556d916322d7b8da671e17254bc16d590c987e Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 29 Dec 2022 21:15:34 +0100 Subject: [PATCH] backend api for ZIP export --- docs/backend_api/Attribute.html | 14 +- docs/backend_api/BackendScriptApi.html | 263 +++++++++-- docs/backend_api/Branch.html | 14 +- docs/backend_api/Note.html | 362 +++++++++++++-- .../becca_entities_abstract_entity.js.html | 7 +- .../backend_api/becca_entities_branch.js.html | 40 +- docs/backend_api/becca_entities_note.js.html | 16 +- docs/backend_api/global.html | 12 +- .../services_backend_script_api.js.html | 11 +- docs/frontend_api/FrontendScriptApi.html | 422 ++++++++++++++++-- docs/frontend_api/global.html | 2 +- .../services_frontend_script_api.js.html | 18 + src/services/backend_script_api.js | 11 +- src/services/export/zip.js | 30 +- 14 files changed, 1052 insertions(+), 170 deletions(-) diff --git a/docs/backend_api/Attribute.html b/docs/backend_api/Attribute.html index 193b65b71..6b9aa5ed8 100644 --- a/docs/backend_api/Attribute.html +++ b/docs/backend_api/Attribute.html @@ -268,7 +268,7 @@ and relation (representing named relationship between source and target note)Source:
@@ -825,7 +825,7 @@ and relation (representing named relationship between source and target note)Source:
@@ -1286,7 +1286,7 @@ and relation (representing named relationship between source and target note)Source:
@@ -1741,7 +1741,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -1777,7 +1777,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and ' -

save() → {AbstractEntity}

+

save() → {this}

@@ -1834,7 +1834,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -1870,7 +1870,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
-AbstractEntity +this
diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.html index fed5a5872..81aeeaa36 100644 --- a/docs/backend_api/BackendScriptApi.html +++ b/docs/backend_api/BackendScriptApi.html @@ -81,7 +81,7 @@
Source:
@@ -185,7 +185,7 @@
Source:
@@ -295,7 +295,7 @@
Source:
@@ -405,7 +405,7 @@
Source:
@@ -515,7 +515,7 @@
Source:
@@ -625,7 +625,7 @@
Source:
@@ -735,7 +735,7 @@
Source:
@@ -845,7 +845,7 @@
Source:
@@ -955,7 +955,7 @@
Source:
@@ -1131,7 +1131,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -1298,7 +1298,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -1584,7 +1584,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -1743,7 +1743,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -1926,7 +1926,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2108,7 +2108,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2309,7 +2309,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2460,7 +2460,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2512,6 +2512,185 @@ JSON MIME type. See also createNewNote() for more options. + + + + + + +

exportSubtreeToZipFile(noteId, format, zipFilePath)

+ + + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
noteId + + +string + + + +
format + + +string + + + + either 'html' or 'markdown'
zipFilePath + + +string + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + @@ -2566,7 +2745,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2724,7 +2903,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -2878,7 +3057,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3081,7 +3260,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3282,7 +3461,7 @@ JSON MIME type. See also createNewNote() for more options.
Source:
@@ -3392,7 +3571,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -3593,7 +3772,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -3747,7 +3926,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -3948,7 +4127,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4149,7 +4328,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4255,7 +4434,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4425,7 +4604,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4659,7 +4838,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4860,7 +5039,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5013,7 +5192,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5150,7 +5329,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5258,7 +5437,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5439,7 +5618,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5641,7 +5820,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -5850,7 +6029,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -6030,7 +6209,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -6165,7 +6344,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -6371,7 +6550,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -6527,7 +6706,7 @@ exists, then we'll use that transaction.
Source:
@@ -6682,7 +6861,7 @@ exists, then we'll use that transaction.
Source:
diff --git a/docs/backend_api/Branch.html b/docs/backend_api/Branch.html index fd3cba371..bba99a3bc 100644 --- a/docs/backend_api/Branch.html +++ b/docs/backend_api/Branch.html @@ -203,7 +203,7 @@ Always check noteId instead.
Source:
@@ -942,7 +942,7 @@ of deletion should not act as a clone.
Source:
@@ -1502,7 +1502,7 @@ of deletion should not act as a clone.
Source:
@@ -1750,7 +1750,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -1786,7 +1786,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and ' -

save() → {AbstractEntity}

+

save() → {this}

@@ -1843,7 +1843,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -1879,7 +1879,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
-AbstractEntity +this
diff --git a/docs/backend_api/Note.html b/docs/backend_api/Note.html index c14d61cdc..763500c81 100644 --- a/docs/backend_api/Note.html +++ b/docs/backend_api/Note.html @@ -199,7 +199,7 @@
Source:
@@ -1050,7 +1050,7 @@ -

addAttribute(type, name, valueopt) → {Attribute}

+

addAttribute(type, name, valueopt, isInheritableopt, positionopt) → {Attribute}

@@ -1087,6 +1087,8 @@ See addLabel, addRelation for more specific methods. + Default + Description @@ -1120,6 +1122,10 @@ See addLabel, addRelation for more specific methods. + + + + attribute type (label / relation) @@ -1151,6 +1157,10 @@ See addLabel, addRelation for more specific methods. + + + + name of the attribute, not including the leading ~/# @@ -1184,11 +1194,93 @@ See addLabel, addRelation for more specific methods. + + + + value of the attribute - text for labels, target note ID for relations; optional. + + + + isInheritable + + + + + +boolean + + + + + + + + + <optional>
+ + + + + + + + + + + + false + + + + + + + + + + + + position + + + + + +int + + + + + + + + + <optional>
+ + + + + + + + + + + + 1000 + + + + + + + + @@ -1226,7 +1318,7 @@ See addLabel, addRelation for more specific methods.
Source:
@@ -1333,7 +1425,7 @@ See addLabel, addRelation for more specific methods.
Source:
@@ -1369,7 +1461,7 @@ See addLabel, addRelation for more specific methods. -

addLabel(name, valueopt) → {Attribute}

+

addLabel(name, valueopt, isInheritableopt) → {Attribute}

@@ -1405,6 +1497,8 @@ See addLabel, addRelation for more specific methods. + Default + Description @@ -1438,6 +1532,10 @@ See addLabel, addRelation for more specific methods. + + + + name of the label, not including the leading # @@ -1471,11 +1569,54 @@ See addLabel, addRelation for more specific methods. + + + + text value of the label; optional + + + + isInheritable + + + + + +boolean + + + + + + + + + <optional>
+ + + + + + + + + + + + false + + + + + + + + @@ -1513,7 +1654,7 @@ See addLabel, addRelation for more specific methods.
Source:
@@ -1567,7 +1708,7 @@ See addLabel, addRelation for more specific methods. -

addRelation(name, value) → {Attribute}

+

addRelation(name, targetNoteId, isInheritableopt) → {Attribute}

@@ -1600,8 +1741,12 @@ returned. Type + Attributes + + Default + Description @@ -1625,7 +1770,19 @@ returned. + + + + + + + + + + + + name of the relation, not including the leading ~ @@ -1635,7 +1792,7 @@ returned. - value + targetNoteId @@ -1648,10 +1805,61 @@ returned. + + + + + + - ID of the target note of the relation + + + + + + + + + + + + + + isInheritable + + + + + +boolean + + + + + + + + + <optional>
+ + + + + + + + + + + + false + + + + + @@ -1692,7 +1900,7 @@ returned.
Source:
@@ -1927,7 +2135,7 @@ returned.
Source:
@@ -2127,7 +2335,7 @@ returned.
Source:
@@ -2389,7 +2597,7 @@ returned.
Source:
@@ -2495,7 +2703,7 @@ returned.
Source:
@@ -3614,6 +3822,92 @@ returned. + + + + + + +

getDescendantNoteIds()

+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
Deprecated:
  • use getSubtreeNoteIds() instead
+ + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + @@ -6425,7 +6719,7 @@ This method can be significantly faster than the getAttribute()
Source:
@@ -7439,6 +7733,10 @@ This method can be significantly faster than the getAttribute()
Returns:
+
+ - includes the subtree node as well +
+
@@ -7615,7 +7913,7 @@ This method can be significantly faster than the getAttribute()
Source:
@@ -7811,7 +8109,7 @@ This method can be significantly faster than the getAttribute()
Source:
@@ -9306,7 +9604,7 @@ This method can be significantly faster than the getAttribute()
Source:
@@ -10017,7 +10315,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -10228,7 +10526,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -10408,7 +10706,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -10588,7 +10886,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -10624,7 +10922,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and ' -

save() → {AbstractEntity}

+

save() → {this}

@@ -10681,7 +10979,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -10717,7 +11015,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
-AbstractEntity +this
@@ -10783,7 +11081,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -11015,7 +11313,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -11195,7 +11493,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -11355,7 +11653,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -11597,7 +11895,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -11808,7 +12106,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
@@ -12019,7 +12317,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
Source:
diff --git a/docs/backend_api/becca_entities_abstract_entity.js.html b/docs/backend_api/becca_entities_abstract_entity.js.html index b7b47377a..b30f61521 100644 --- a/docs/backend_api/becca_entities_abstract_entity.js.html +++ b/docs/backend_api/becca_entities_abstract_entity.js.html @@ -74,7 +74,10 @@ class AbstractEntity { return this.utcDateModified || this.utcDateCreated; } - /** @protected */ + /** + * @protected + * @returns {Becca} + */ get becca() { if (!becca) { becca = require('../becca'); @@ -103,7 +106,7 @@ class AbstractEntity { /** * Saves entity - executes SQL, but doesn't commit the transaction on its own * - * @returns {AbstractEntity} + * @returns {this} */ save() { const entityName = this.constructor.entityName; diff --git a/docs/backend_api/becca_entities_branch.js.html b/docs/backend_api/becca_entities_branch.js.html index 2ace41813..e914ea3ad 100644 --- a/docs/backend_api/becca_entities_branch.js.html +++ b/docs/backend_api/becca_entities_branch.js.html @@ -106,7 +106,7 @@ class Branch extends AbstractEntity { childNote.parentBranches.push(this); } - if (this.branchId === 'root') { + if (this.noteId === 'root') { return; } @@ -193,8 +193,7 @@ class Branch extends AbstractEntity { } } - if (this.branchId === 'root' - || this.noteId === 'root' + if (this.noteId === 'root' || this.noteId === cls.getHoistedNoteId()) { throw new Error("Can't delete root or hoisted branch/note"); @@ -237,11 +236,19 @@ class Branch extends AbstractEntity { } beforeSaving() { + if (!this.noteId || !this.parentNoteId) { + throw new Error(`noteId and parentNoteId are mandatory properties for Branch`); + } + + this.branchId = `${this.parentNoteId}_${this.noteId}`; + if (this.notePosition === undefined || this.notePosition === null) { let maxNotePos = 0; for (const childBranch of this.parentNote.getChildBranches()) { - if (maxNotePos < childBranch.notePosition && childBranch.noteId !== '_hidden') { + if (maxNotePos < childBranch.notePosition + && childBranch.noteId !== '_hidden' // hidden has very large notePosition to always stay last + ) { maxNotePos = childBranch.notePosition; } } @@ -253,6 +260,10 @@ class Branch extends AbstractEntity { this.isExpanded = false; } + if (!this.prefix?.trim()) { + this.prefix = null; + } + this.utcDateModified = dateUtils.utcNowDateTime(); super.beforeSaving(); @@ -274,13 +285,20 @@ class Branch extends AbstractEntity { } createClone(parentNoteId, notePosition) { - return new Branch({ - noteId: this.noteId, - parentNoteId: parentNoteId, - notePosition: notePosition, - prefix: this.prefix, - isExpanded: this.isExpanded - }); + const existingBranch = this.becca.getBranchFromChildAndParent(this.noteId, parentNoteId); + + if (existingBranch) { + existingBranch.notePosition = notePosition; + return existingBranch; + } else { + return new Branch({ + noteId: this.noteId, + parentNoteId: parentNoteId, + notePosition: notePosition, + prefix: this.prefix, + isExpanded: this.isExpanded + }); + } } } diff --git a/docs/backend_api/becca_entities_note.js.html b/docs/backend_api/becca_entities_note.js.html index 6dd861f70..0a5e86b0c 100644 --- a/docs/backend_api/becca_entities_note.js.html +++ b/docs/backend_api/becca_entities_note.js.html @@ -973,13 +973,14 @@ class Note extends AbstractEntity { }; } - /** @returns {String[]} */ - getSubtreeNoteIds({includeArchived = true, resolveSearch = false} = {}) { - return this.getSubtree({includeArchived, resolveSearch}) + /** @returns {String[]} - includes the subtree node as well */ + getSubtreeNoteIds({includeArchived = true, includeHidden = false, resolveSearch = false} = {}) { + return this.getSubtree({includeArchived, includeHidden, resolveSearch}) .notes .map(note => note.noteId); } + /** @deprecated use getSubtreeNoteIds() instead */ getDescendantNoteIds() { return this.getSubtreeNoteIds(); } @@ -1199,7 +1200,8 @@ class Note extends AbstractEntity { * @param {string} type - attribute type (label / relation) * @param {string} name - name of the attribute, not including the leading ~/# * @param {string} [value] - value of the attribute - text for labels, target note ID for relations; optional. - * + * @param {boolean} [isInheritable=false] + * @param {int} [position] * @return {Attribute} */ addAttribute(type, name, value = "", isInheritable = false, position = 1000) { @@ -1220,7 +1222,7 @@ class Note extends AbstractEntity { * * @param {string} name - name of the label, not including the leading # * @param {string} [value] - text value of the label; optional - * + * @param {boolean} [isInheritable=false] * @return {Attribute} */ addLabel(name, value = "", isInheritable = false) { @@ -1232,8 +1234,8 @@ class Note extends AbstractEntity { * returned. * * @param {string} name - name of the relation, not including the leading ~ - * @param {string} value - ID of the target note of the relation - * + * @param {string} targetNoteId + * @param {boolean} [isInheritable=false] * @return {Attribute} */ addRelation(name, targetNoteId, isInheritable = false) { diff --git a/docs/backend_api/global.html b/docs/backend_api/global.html index c2cc94c79..0cba37b8c 100644 --- a/docs/backend_api/global.html +++ b/docs/backend_api/global.html @@ -391,7 +391,7 @@
Source:
@@ -579,7 +579,7 @@
Source:
@@ -767,7 +767,7 @@
Source:
@@ -1053,7 +1053,7 @@
Source:
@@ -1468,7 +1468,7 @@
Source:
@@ -1681,7 +1681,7 @@
Source:
diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.html index 7d05b7408..eb02c31b5 100644 --- a/docs/backend_api/services_backend_script_api.js.html +++ b/docs/backend_api/services_backend_script_api.js.html @@ -45,7 +45,8 @@ const becca = require("../becca/becca"); const ws = require("./ws"); const SpacedUpdate = require("./spaced_update"); const specialNotesService = require("./special_notes"); -const branchService = require("./branches.js"); +const branchService = require("./branches"); +const exportService = require("./export/zip"); /** * This is the main backend API interface for scripts. It's published in the local "api" object. @@ -590,6 +591,14 @@ function BackendScriptApi(currentNote, apiParams) { } }; + /** + * @method + * @param {string} noteId + * @param {string} format - either 'html' or 'markdown' + * @param {string} zipFilePath + */ + this.exportSubtreeToZipFile = (noteId, format, zipFilePath) => exportService.exportToZipFile(noteId, format, zipFilePath); + /** * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. * diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index 2c0ad3896..1b66f9ea7 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -329,7 +329,7 @@
Source:
@@ -559,6 +559,330 @@ +

NoteContextCachingWidget

+ + + + + + + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ + +NoteContextAwareWidget + + + +
+ + + + +
+ + + + + + + + + + + + + + + + +
Deprecated:
  • use NoteContextAwareWidget instead
+ + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

TabAwareWidget

+ + + + + + + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ + +NoteContextAwareWidget + + + +
+ + + + +
+ + + + + + + + + + + + + + + + +
Deprecated:
  • use NoteContextAwareWidget instead
+ + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

TabCachingWidget

+ + + + + + + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ + +NoteContextAwareWidget + + + +
+ + + + +
+ + + + + + + + + + + + + + + + +
Deprecated:
  • use NoteContextAwareWidget instead
+ + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + +

currentNote

@@ -1003,7 +1327,7 @@
Source:
@@ -1158,7 +1482,7 @@
Source:
@@ -1316,7 +1640,7 @@
Source:
@@ -1453,7 +1777,7 @@
Source:
@@ -1592,7 +1916,7 @@
Source:
@@ -1800,7 +2124,7 @@
Source:
@@ -2164,7 +2488,7 @@
Source:
@@ -2297,7 +2621,7 @@
Source:
@@ -2407,7 +2731,7 @@
Source:
@@ -2513,7 +2837,7 @@
Source:
@@ -2619,7 +2943,7 @@
Source:
@@ -2729,7 +3053,7 @@
Source:
@@ -2840,7 +3164,7 @@ implementation of actual widget type.
Source:
@@ -2944,7 +3268,7 @@ implementation of actual widget type.
Source:
@@ -3052,7 +3376,7 @@ implementation of actual widget type.
Source:
@@ -3220,7 +3544,7 @@ implementation of actual widget type.
Source:
@@ -3357,7 +3681,7 @@ implementation of actual widget type.
Source:
@@ -3514,7 +3838,7 @@ implementation of actual widget type.
Source:
@@ -3669,7 +3993,7 @@ implementation of actual widget type.
Source:
@@ -3776,7 +4100,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -3931,7 +4255,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4087,7 +4411,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -4288,7 +4612,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -4394,7 +4718,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -4549,7 +4873,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -4704,7 +5028,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -4854,7 +5178,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -5014,7 +5338,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -5192,7 +5516,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -5343,7 +5667,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -5451,7 +5775,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -5607,7 +5931,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -5763,7 +6087,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -5900,7 +6224,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -6054,7 +6378,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -6140,7 +6464,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -6277,7 +6601,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -6438,7 +6762,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -6546,7 +6870,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -6684,7 +7008,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -6840,7 +7164,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -6995,7 +7319,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7146,7 +7470,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7283,7 +7607,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7420,7 +7744,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7580,7 +7904,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7740,7 +8064,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -7832,7 +8156,7 @@ Typical use case is when new note has been created, we should wait until it is s
Source:
diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.html index 70445bbc2..657f703e2 100644 --- a/docs/frontend_api/global.html +++ b/docs/frontend_api/global.html @@ -427,7 +427,7 @@
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html index 4c186fa99..13673d085 100644 --- a/docs/frontend_api/services_frontend_script_api.js.html +++ b/docs/frontend_api/services_frontend_script_api.js.html @@ -69,6 +69,24 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain /** @property {NoteContextAwareWidget} */ this.NoteContextAwareWidget = NoteContextAwareWidget; + /** + * @property {NoteContextAwareWidget} + * @deprecated use NoteContextAwareWidget instead + */ + this.TabAwareWidget = NoteContextAwareWidget; + + /** + * @property {NoteContextAwareWidget} + * @deprecated use NoteContextAwareWidget instead + */ + this.TabCachingWidget = NoteContextAwareWidget; + + /** + * @property {NoteContextAwareWidget} + * @deprecated use NoteContextAwareWidget instead + */ + this.NoteContextCachingWidget = NoteContextAwareWidget; + /** @property {BasicWidget} */ this.BasicWidget = BasicWidget; diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index df31fb2e6..d83e51b99 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -17,7 +17,8 @@ const becca = require("../becca/becca"); const ws = require("./ws"); const SpacedUpdate = require("./spaced_update"); const specialNotesService = require("./special_notes"); -const branchService = require("./branches.js"); +const branchService = require("./branches"); +const exportService = require("./export/zip"); /** * This is the main backend API interface for scripts. It's published in the local "api" object. @@ -562,6 +563,14 @@ function BackendScriptApi(currentNote, apiParams) { } }; + /** + * @method + * @param {string} noteId + * @param {string} format - either 'html' or 'markdown' + * @param {string} zipFilePath + */ + this.exportSubtreeToZipFile = (noteId, format, zipFilePath) => exportService.exportToZipFile(noteId, format, zipFilePath); + /** * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. * diff --git a/src/services/export/zip.js b/src/services/export/zip.js index 3fdaa2dd5..bc79f3610 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -14,13 +14,19 @@ const becca = require("../../becca/becca"); const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR; const archiver = require('archiver'); const log = require("../log"); +const TaskContext = require("../task_context"); +const ValidationError = require("../../errors/validation_error"); /** * @param {TaskContext} taskContext * @param {Branch} branch * @param {string} format - 'html' or 'markdown' */ -function exportToZip(taskContext, branch, format, res) { +function exportToZip(taskContext, branch, format, res, setHeaders = true) { + if (!['html', 'markdown'].includes(format)) { + throw new ValidationError(`Only 'html' and 'markdown' allowed as export format, '${format}' given`); + } + const archive = archiver('zip', { zlib: { level: 9 } // Sets the compression level. }); @@ -466,8 +472,10 @@ ${markdownContent}`; const note = branch.getNote(); const zipFileName = `${branch.prefix ? `${branch.prefix} - ` : ""}${note.getTitleOrProtected()}.zip`; - res.setHeader('Content-Disposition', utils.getContentDisposition(zipFileName)); - res.setHeader('Content-Type', 'application/zip'); + if (setHeaders) { + res.setHeader('Content-Disposition', utils.getContentDisposition(zipFileName)); + res.setHeader('Content-Type', 'application/zip'); + } archive.pipe(res); archive.finalize(); @@ -475,6 +483,20 @@ ${markdownContent}`; taskContext.taskSucceeded(); } +function exportToZipFile(noteId, format, zipFilePath) { + const fileOutputStream = fs.createWriteStream(zipFilePath); + const taskContext = new TaskContext('no-progress-reporting'); + + const note = becca.getNote(noteId); + + if (!note) { + throw new ValidationError(`Note ${noteId} not found.`); + } + + exportToZip(taskContext, note.getParentBranches()[0], format, fileOutputStream, false); +} + module.exports = { - exportToZip + exportToZip, + exportToZipFile };