Skip to content

Commit

Permalink
expose ability to create note revisions in backend API #2890
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Jun 2, 2022
1 parent 103aa95 commit 3cfca27
Show file tree
Hide file tree
Showing 10 changed files with 848 additions and 184 deletions.
72 changes: 72 additions & 0 deletions docs/backend_api/BackendScriptApi.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,78 @@ <h3 class="subsection-title">Members</h3>



<h4 class="name" id="__private"><span class="type-signature"></span>__private<span class="type-signature"> :Object</span></h4>




<div class="description">
This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
</div>



<h5>Type:</h5>
<ul>
<li>

<span class="param-type">Object</span>


</li>
</ul>





<dl class="details">


























<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line435">line 435</a>
</li></ul></dd>







</dl>








<h4 class="name" id="axios"><span class="type-signature"></span>axios<span class="type-signature"></span></h4>


Expand Down
267 changes: 186 additions & 81 deletions docs/backend_api/Note.html

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions docs/backend_api/becca_entities_note.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ <h1 class="page-title">Source: becca/entities/note.js</h1>
const AbstractEntity = require("./abstract_entity");
const NoteRevision = require("./note_revision");
const TaskContext = require("../../services/task_context.js");
const optionService = require("../../services/options.js");
const noteRevisionService = require("../../services/note_revisions.js");

const LABEL = 'label';
const RELATION = 'relation';
Expand Down Expand Up @@ -1192,6 +1194,41 @@ <h1 class="page-title">Source: becca/entities/note.js</h1>
return !(this.noteId in this.becca.notes);
}

/**
* @return {NoteRevision|null}
*/
saveNoteRevision() {
const content = this.getContent();

if (!content || (Buffer.isBuffer(content) &amp;&amp; content.byteLength === 0)) {
return null;
}

const contentMetadata = this.getContentMetadata();

const noteRevision = new NoteRevision({
noteId: this.noteId,
// title and text should be decrypted now
title: this.title,
type: this.type,
mime: this.mime,
isProtected: false, // will be fixed in the protectNoteRevisions() call
utcDateLastEdited: this.utcDateModified > contentMetadata.utcDateModified
? this.utcDateModified
: contentMetadata.utcDateModified,
utcDateCreated: dateUtils.utcNowDateTime(),
utcDateModified: dateUtils.utcNowDateTime(),
dateLastEdited: this.dateModified > contentMetadata.dateModified
? this.dateModified
: contentMetadata.dateModified,
dateCreated: dateUtils.localNowDateTime()
}).save();

noteRevision.setContent(content);

return noteRevision;
}

beforeSaving() {
super.beforeSaving();

Expand Down
9 changes: 9 additions & 0 deletions docs/backend_api/services_backend_script_api.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ <h1 class="page-title">Source: services/backend_script_api.js</h1>
* @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version
*/
this.getAppInfo = () => appInfo

/**
* This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
*
* @type {{becca: Becca}}
*/
this.__private = {
becca
}
}

module.exports = BackendScriptApi;
Expand Down
Loading

0 comments on commit 3cfca27

Please sign in to comment.