Skip to content

Build your personal knowledge base with Trilium Notes

many small fixes from Intellij analysis

zadam6dfc72c0653c
diff --git a/.eslintrc.js b/.eslintrc.js
index 12f8725da3..17b0607302 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -92,6 +92,7 @@ module.exports = {
renderMathInElement: true,
// \src\public\app\widgets\type_widgets\editable_text.js
BalloonEditor: true,
+ FancytreeNode: true,
CKEditorInspector: true,
// \src\public\app\widgets\type_widgets\editable_code.js
CodeMirror: true,
diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js
index 0fbf01630f..4806063b52 100644
--- a/src/becca/entities/abstract_becca_entity.js
+++ b/src/becca/entities/abstract_becca_entity.js
@@ -189,7 +189,7 @@ class AbstractBeccaEntity {
* We're using the unencrypted blob for the hash calculation, because otherwise the random IV would
* cause every content blob to be unique which would balloon the database size (esp. with revisioning).
* This has minor security implications (it's easy to infer that given content is shared between different
- * notes/attachments, but the trade-off comes out clearly positive.
+ * notes/attachments, but the trade-off comes out clearly positive).
*/
newBlobId = utils.hashedBlobId(unencryptedContentForHashCalculation);
blobNeedsInsert = !sql.getValue('SELECT 1 FROM blobs WHERE blobId = ?', [newBlobId]);
@@ -228,7 +228,10 @@ class AbstractBeccaEntity {
return newBlobId;
}
- /** @protected */
+ /**
+ * @protected
+ * @returns {string|Buffer}
+ */
_getContent() {
const row = sql.getRow(`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]);
diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.js
index fd303542ab..118e617fc8 100644
--- a/src/becca/entities/battachment.js
+++ b/src/becca/entities/battachment.js
@@ -86,7 +86,7 @@ class BAttachment extends AbstractBeccaEntity {
|| protectedSessionService.isProtectedSessionAvailable()
}
- /** @returns {*} */
+ /** @returns {string|Buffer} */
getContent() {
return this._getContent();
}
diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js
index 4b15792b0b..a02ca99aaa 100644
--- a/src/becca/entities/bnote.js
+++ b/src/becca/entities/bnote.js
@@ -207,7 +207,7 @@ class BNote extends AbstractBeccaEntity {
* - but to the user note content and title changes are one and the same - single dateModified (so all changes must go through Note and content is not a separate entity)
*/
- /** @returns {*} */
+ /** @returns {string|Buffer} */
getContent() {
return this._getContent();
}
@@ -965,7 +965,7 @@ class BNote extends AbstractBeccaEntity {
};
}
- /** @returns {String[]} - includes the subtree root note as well */
+ /** @returns {string[]} - includes the subtree root note as well */
getSubtreeNoteIds({includeArchived = true, includeHidden = false, resolveSearch = false} = {}) {
return this.getSubtree({includeArchived, includeHidden, resolveSearch})
.notes
@@ -1157,13 +1157,10 @@ class BNote extends AbstractBeccaEntity {
}
const parentNotes = this.getParentNotes();
- let notePaths = [];
- if (parentNotes.length === 1) { // optimization for most common case
- notePaths = parentNotes[0].getAllNotePaths();
- } else {
- notePaths = parentNotes.flatMap(parentNote => parentNote.getAllNotePaths());
- }
+ const notePaths = parentNotes.length === 1
+ ? parentNotes[0].getAllNotePaths() // optimization for most common case
+ : parentNotes.flatMap(parentNote => parentNote.getAllNotePaths());
for (const notePath of notePaths) {
notePath.push(this.noteId);
@@ -1514,10 +1511,10 @@ class BNote extends AbstractBeccaEntity {
/**
* (Soft) delete a note and all its descendants.
*
- * @param {string} [deleteId] - optional delete identified
+ * @param {string} [deleteId=null] - optional delete identified
* @param {TaskContext} [taskContext]
*/
- deleteNote(deleteId, taskContext) {
+ deleteNote(deleteId = null, taskContext = null) {
if (this.isDeleted) {
return;
}
diff --git a/src/becca/entities/bnote_revision.js b/src/becca/entities/bnote_revision.js
index 0167d22a51..982bdc4971 100644
--- a/src/becca/entities/bnote_revision.js
+++ b/src/becca/entities/bnote_revision.js
@@ -80,7 +80,7 @@ class BNoteRevision extends AbstractBeccaEntity {
* This is the same approach as is used for Note's content.
*/
- /** @returns {*} */
+ /** @returns {string|Buffer} */
getContent() {
return this._getContent();
}
diff --git a/src/public/app/components/main_tree_executors.js b/src/public/app/components/main_tree_executors.js
index 4889eea9fd..f718ca7a63 100644
--- a/src/public/app/components/main_tree_executors.js
+++ b/src/public/app/components/main_tree_executors.js
@@ -47,7 +47,7 @@ export default class MainTreeExecutors extends Component {
}
const parentNotePath = treeService.getNotePath(node.getParent());
- const isProtected = await treeService.getParentProtectedStatus(node);
+ const isProtected = treeService.getParentProtectedStatus(node);
if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) {
return;
diff --git a/src/public/app/components/note_context.js b/src/public/app/components/note_context.js
index 16a52a7a26..ed2531db68 100644
--- a/src/public/app/components/note_context.js
+++ b/src/public/app/components/note_context.js
@@ -152,7 +152,7 @@ class NoteContext extends Component {
return resolvedNotePath;
}
- /** @property {FNote} */
+ /** @returns {FNote} */
get note() {
if (!this.noteId || !(this.noteId in froca.notes)) {
return null;
@@ -161,7 +161,7 @@ class NoteContext extends Component {
return froca.notes[this.noteId];
}
- /** @property {string[]} */
+ /** @returns {string[]} */
get notePathArray() {
return this.notePath ? this.notePath.split('/') : [];
}
diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js
index 73eee6f746..60e5835481 100644
--- a/src/public/app/components/tab_manager.js
+++ b/src/public/app/components/tab_manager.js
@@ -14,6 +14,8 @@ export default class TabManager extends Component {
constructor() {
super();
+ /** @property {NoteContext[]} */
+ this.children = [];
this.mutex = new Mutex();
this.activeNtxId = null;
@@ -38,7 +40,7 @@ export default class TabManager extends Component {
appContext.addBeforeUnloadListener(this);
}
- /** @type {NoteContext[]} */
+ /** @returns {NoteContext[]} */
get noteContexts() {
return this.children;
}
diff --git a/src/public/app/entities/fnote.js b/src/public/app/entities/fnote.js
index 47884f5575..3d8bb034f3 100644
--- a/src/public/app/entities/fnote.js
+++ b/src/public/app/entities/fnote.js
@@ -358,13 +358,10 @@ class FNote {
}
const parentNotes = this.getParentNotes();
- let notePaths = [];
- if (parentNotes.length === 1) { // optimization for most common case
- notePaths = parentNotes[0].getAllNotePaths();
- } else {
- notePaths = parentNotes.flatMap(parentNote => parentNote.getAllNotePaths());
- }
+ const notePaths = parentNotes.length === 1
+ ? parentNotes[0].getAllNotePaths() // optimization for most common case
+ : parentNotes.flatMap(parentNote => parentNote.getAllNotePaths());
for (const notePath of notePaths) {
notePath.push(this.noteId);
diff --git a/src/public/app/menus/tree_context_menu.js b/src/public/app/menus/tree_context_menu.js
index 2439371b30..aa457407f4 100644
--- a/src/public/app/menus/tree_context_menu.js
+++ b/src/public/app/menus/tree_context_menu.js
@@ -108,7 +108,7 @@ export default class TreeContextMenu {
}
else if (command === "insertNoteAfter") {
const parentNotePath = treeService.getNotePath(this.node.getParent());
- const isProtected = await treeService.getParentProtectedStatus(this.node);
+ const isProtected = treeService.getParentProtectedStatus(this.node);
noteCreateService.createNote(parentNotePath, {
target: 'after',
diff --git a/src/public/app/services/bundle.js b/src/public/app/services/bundle.js
index 09b20105f3..40658f692e 100644
--- a/src/public/app/services/bundle.js
+++ b/src/public/app/services/bundle.js
@@ -41,7 +41,7 @@ class WidgetsByParent {
add(widget) {
if (!widget.parentWidget) {
- console.log(`Custom widget does not have mandatory 'getParent()' method defined`);
+ console.log(`Custom widget does not have mandatory 'parentWidget' property defined`);
return;
}
diff --git a/src/public/app/services/debounce.js b/src/public/app/services/debounce.js
index 62415da292..4e5429a32e 100644
--- a/src/public/app/services/debounce.js
+++ b/src/public/app/services/debounce.js
@@ -9,15 +9,15 @@
* @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
* @param {Function} func to wrap
* @param {Number} waitMs in ms (`100`)
- * @param {Boolean} immediate whether to execute at the beginning (`false`)
+ * @param {Boolean} [immediate=false] whether to execute at the beginning (`false`)
* @api public
*/
-function debounce(func, waitMs, immediate) {
- var timeout, args, context, timestamp, result;
+function debounce(func, waitMs, immediate = false) {
+ let timeout, args, context, timestamp, result;
if (null == waitMs) waitMs = 100;
function later() {
- var last = Date.now() - timestamp;
+ const last = Date.now() - timestamp;
if (last < waitMs && last >= 0) {
timeout = setTimeout(later, waitMs - last);
@@ -30,11 +30,11 @@ function debounce(func, waitMs, immediate) {
}
}
- var debounced = function(){
+ const debounced = function () {
context = this;
args = arguments;
timestamp = Date.now();
- var callNow = immediate && !timeout;
+ const callNow = immediate && !timeout;
if (!timeout) timeout = setTimeout(later, waitMs);
if (callNow) {
result = func.apply(context, args);
diff --git a/src/public/app/services/froca_updater.js b/src/public/app/services/froca_updater.js
index 0b5314fd68..4768124721 100644
--- a/src/public/app/services/froca_updater.js
+++ b/src/public/app/services/froca_updater.js
@@ -5,6 +5,7 @@ import options from "./options.js";
import noteAttributeCache from "./note_attribute_cache.js";
import FBranch from "../entities/fbranch.js";
import FAttribute from "../entities/fattribute.js";
+import FAttachment from "../entities/fattachment.js";
async function processEntityChanges(entityChanges) {
const loadResults = new LoadResults(entityChanges);
diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js
index 98d4e84601..11d4de8c3a 100644
--- a/src/public/app/services/frontend_script_api.js
+++ b/src/public/app/services/frontend_script_api.js
@@ -322,7 +322,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
* See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
*
* @method
- * @returns {Promise<CKEditor>} instance of CKEditor
+ * @returns {Promise<BalloonEditor>} instance of CKEditor
*/
this.getActiveContextTextEditor = () => appContext.tabManager.getActiveContext()?.getTextEditor();
diff --git a/src/public/app/services/open.js b/src/public/app/services/open.js
index a6205173a0..4ced214b4b 100644
--- a/src/public/app/services/open.js
+++ b/src/public/app/services/open.js
@@ -79,7 +79,7 @@ async function openExternally(type, entityId, mime) {
if (res) {
// fallback in case there's no default application for this file
- window.open(getFileUrl(type, entityId), { url: true });
+ window.open(getFileUrl(type, entityId));
}
}
else {
diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.js
index 60e862f972..82436fd23e 100644
--- a/src/public/app/services/tree.js
+++ b/src/public/app/services/tree.js
@@ -18,7 +18,7 @@ async function resolveNotePath(notePath, hoistedNoteId = 'root') {
* notePath as possible. Part of the path might not be valid because of note moving (which causes
* path change) or other corruption, in that case this will try to get some other valid path to the correct note.
*
- * @returns {string[]}
+ * @returns {Promise<string[]>}
*/
async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logErrors = true) {
utils.assertArguments(notePath);
@@ -129,7 +129,7 @@ ws.subscribeToMessages(message => {
});
function getParentProtectedStatus(node) {
- return hoistedNoteService.isHoistedNode(node) ? 0 : node.getParent().data.isProtected;
+ return hoistedNoteService.isHoistedNode(node) ? false : node.getParent().data.isProtected;
}
function getNoteIdFromNotePath(notePath) {
diff --git a/src/public/app/services/utils.js b/src/public/app/services/utils.js
index f4eb4371fb..191c0965a9 100644
--- a/src/public/app/services/utils.js
+++ b/src/public/app/services/utils.js
@@ -399,10 +399,10 @@ function escapeRegExp(str) {
}
function areObjectsEqual () {
- var i, l, leftChain, rightChain;
+ let i, l, leftChain, rightChain;
function compare2Objects (x, y) {
- var p;
+ let p;
// remember that NaN === NaN returns false
// and isNaN(undefined) returns true
diff --git a/src/public/app/widgets/attribute_widgets/attribute_editor.js b/src/public/app/widgets/attribute_widgets/attribute_editor.js
index 1c4b9a3a19..8cd7aaf6fa 100644
--- a/src/public/app/widgets/attribute_widgets/attribute_editor.js
+++ b/src/public/app/widgets/attribute_widgets/attribute_editor.js
@@ -321,9 +321,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget {
parseAttributes() {
try {
- const attrs = attributesParser.lexAndParse(this.getPreprocessedData());
-
- return attrs;
+ return attributesParser.lexAndParse(this.getPreprocessedData());
}
catch (e) {
this.$errors.text(e.message).slideDown();
diff --git a/src/public/app/widgets/bookmark_switch.js b/src/public/app/widgets/bookmark_switch.js
index 3c661d9e04..b33a752b93 100644
--- a/src/public/app/widgets/bookmark_switch.js
+++ b/src/public/app/widgets/bookmark_switch.js
@@ -27,7 +27,7 @@ export default class BookmarkSwitchWidget extends SwitchWidget {
}
}
- refreshWithNote(note) {
+ async refreshWithNote(note) {
const isBookmarked = !!note.getParentBranches().find(b => b.parentNoteId === '_lbBookmarks');
this.$switchOn.toggle(!isBookmarked);
diff --git a/src/public/app/widgets/buttons/note_actions.js b/src/public/app/widgets/buttons/note_actions.js
index 58eec00073..f0f5b3419c 100644
--- a/src/public/app/widgets/buttons/note_actions.js
+++ b/src/public/app/widgets/buttons/note_actions.js
@@ -90,7 +90,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {
});
}
- refreshWithNote(note) {
+ async refreshWithNote(note) {
this.$convertNoteIntoAttachmentButton.toggle(note.isEligibleForConversionToAttachment());
this.toggleDisabled(this.$findInTextButton, ['text', 'code', 'book', 'search'].includes(note.type));
diff --git a/src/public/app/widgets/dialogs/confirm.js b/src/public/app/widgets/dialogs/confirm.js
index 64d6465c14..2ee8c8f427 100644
--- a/src/public/app/widgets/dialogs/confirm.js
+++ b/src/public/app/widgets/dialogs/confirm.js
@@ -34,7 +34,7 @@ export default class ConfirmDialog extends BasicWidget {
super();
this.resolve = null;
- this.$originallyFocused = null; // element focused before the dialog was opened, so we can return to it afterwards
+ this.$originallyFocused = null; // element focused before the dialog was opened, so we can return to it afterward
}
doRender() {
diff --git a/src/public/app/widgets/dialogs/info.js b/src/public/app/widgets/dialogs/info.js
index 113cc8732b..738ac438d2 100644
--- a/src/public/app/widgets/dialogs/info.js
+++ b/src/public/app/widgets/dialogs/info.js
@@ -27,7 +27,7 @@ export default class InfoDialog extends BasicWidget {
super();
this.resolve = null;
- this.$originallyFocused = null; // element focused before the dialog was opened, so we can return to it afterwards
+ this.$originallyFocused = null; // element focused before the dialog was opened, so we can return to it afterward
}
doRender() {
diff --git a/src/public/app/widgets/dialogs/note_type_chooser.js b/src/public/app/widgets/dialogs/note_type_chooser.js
index a3d7034937..9a55b94170 100644
--- a/src/public/app/widgets/dialogs/note_type_chooser.js
+++ b/src/public/app/widgets/dialogs/note_type_chooser.js
@@ -46,7 +46,7 @@ export default class NoteTypeChooserDialog extends BasicWidget {
super(props);
this.resolve = null;
- this.$originalFocused = null; // element focused before the dialog was opened, so we can return to it afterwards
+ this.$originalFocused = null; // element focused before the dialog was opened, so we can return to it afterward
this.$originalDialog = null;
}
diff --git a/src/public/app/widgets/floating_buttons/code_buttons.js b/src/public/app/widgets/floating_buttons/code_buttons.js
index f1763870b8..3556d99ccb 100644
--- a/src/public/app/widgets/floating_buttons/code_buttons.js
+++ b/src/public/app/widgets/floating_buttons/code_buttons.js
@@ -68,7 +68,7 @@ export default class CodeButtonsWidget extends NoteContextAwareWidget {
super.doRender();
}
- refreshWithNote(note) {
+ async refreshWithNote(note) {
this.$executeButton.toggle(
note.mime.startsWith('application/javascript')
|| note.mime === 'text/x-sqlite;schema=trilium'
diff --git a/src/public/app/widgets/mermaid.js b/src/public/app/widgets/mermaid.js
index 305209199c..ec99d2a564 100644
--- a/src/public/app/widgets/mermaid.js
+++ b/src/public/app/widgets/mermaid.js
@@ -1,6 +1,5 @@
import libraryLoader from "../services/library_loader.js";
import NoteContextAwareWidget from "./note_context_aware_widget.js";
-import froca from "../services/froca.js";
const TPL = `<div class="mermaid-widget">
<style>
diff --git a/src/public/app/widgets/note_map.js b/src/public/app/widgets/note_map.js
index d246b8ba85..65fceedd2e 100644
--- a/src/public/app/widgets/note_map.js
+++ b/src/public/app/widgets/note_map.js
@@ -78,7 +78,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
.width($parent.width());
}
- async refreshWithNote() {
+ async refreshWithNote(note) {
this.$widget.show();
this.css = {
diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js
index 8221fd448f..8688abe6c9 100644
--- a/src/public/app/widgets/note_tree.js
+++ b/src/public/app/widgets/note_tree.js
@@ -1424,11 +1424,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
const parentNote = froca.getNoteFromCache(node.getParent().data.noteId);
- if (parentNote && parentNote.hasLabel('sorted')) {
- return false;
- }
-
- return true;
+ return !parentNote?.hasLabel('sorted');
}
moveNoteUpCommand({node}) {
diff --git a/src/public/app/widgets/protected_note_switch.js b/src/public/app/widgets/protected_note_switch.js
index a99a7be4eb..e06bf973d5 100644
--- a/src/public/app/widgets/protected_note_switch.js
+++ b/src/public/app/widgets/protected_note_switch.js
@@ -20,7 +20,7 @@ export default class ProtectedNoteSwitchWidget extends SwitchWidget {
protectedSessionService.protectNote(this.noteId, false, false)
}
- refreshWithNote(note) {
+ async refreshWithNote(note) {
this.$switchOn.toggle(!note.isProtected);
this.$switchOff.toggle(!!note.isProtected);
}
diff --git a/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js b/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js
index 343cf8ff41..933d38283b 100644
--- a/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js
+++ b/src/public/app/widgets/ribbon_widgets/owned_attribute_list.js
@@ -75,14 +75,6 @@ export default class OwnedAttributeListWidget extends NoteContextAwareWidget {
await this.attributeEditorWidget.updateAttributeList(attributes);
}
- entitiesReloadedEvent({loadResults}) {
- if (loadResults.getAttributes(this.componentId).find(attr => attributeService.isAffecting(attr, this.note))) {
- this.refreshWithNote(this.note, true);
-
- this.getTitle(this.note);
- }
- }
-
focus() {
this.attributeEditorWidget.focus();
}
diff --git a/src/public/app/widgets/ribbon_widgets/similar_notes.js b/src/public/app/widgets/ribbon_widgets/similar_notes.js
index 8a34d2d1b2..983de9ce5b 100644
--- a/src/public/app/widgets/ribbon_widgets/similar_notes.js
+++ b/src/public/app/widgets/ribbon_widgets/similar_notes.js
@@ -60,7 +60,7 @@ export default class SimilarNotesWidget extends NoteContextAwareWidget {
this.$similarNotesWrapper = this.$widget.find(".similar-notes-wrapper");
}
- async refreshWithNote() {
+ async refreshWithNote(note) {
// remember which title was when we found the similar notes
this.title = this.note.title;
diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js
index a2efcc8ab5..ecddc9129f 100644
--- a/src/public/app/widgets/tab_row.js
+++ b/src/public/app/widgets/tab_row.js
@@ -517,7 +517,7 @@ export default class TabRowWidget extends BasicWidget {
draggabilly.on('dragEnd', _ => {
this.isDragging = false;
- const finalTranslateX = parseFloat(tabEl.style.left, 10);
+ const finalTranslateX = parseFloat(tabEl.style.left);
tabEl.style.transform = `translate3d(0, 0, 0)`;
// Animate dragged tab back into its place
@@ -617,7 +617,10 @@ export default class TabRowWidget extends BasicWidget {
this.updateTab($tab, noteContext);
}
- /** @param {NoteContext} noteContext */
+ /**
+ * @param {jQuery} $tab
+ * @param {NoteContext} noteContext
+ */
async updateTab($tab, noteContext) {
if (!$tab.length) {
return;
diff --git a/src/public/app/widgets/toc.js b/src/public/app/widgets/toc.js
index 4840a63109..0aba5dedfe 100644
--- a/src/public/app/widgets/toc.js
+++ b/src/public/app/widgets/toc.js
@@ -106,7 +106,7 @@ export default class TocWidget extends RightPanelWidget {
/**
* Builds a jquery table of contents.
*
- * @param {String} html Note's html content
+ * @param {string} html Note's html content
* @returns {$toc: jQuery, headingCount: integer} ordered list table of headings, nested by heading level
* with an onclick event that will cause the document to scroll to
* the desired position.
diff --git a/src/public/app/widgets/type_widgets/canvas.js b/src/public/app/widgets/type_widgets/canvas.js
index 365b89bf7a..aab38742e1 100644
--- a/src/public/app/widgets/type_widgets/canvas.js
+++ b/src/public/app/widgets/type_widgets/canvas.js
@@ -1,7 +1,6 @@
import libraryLoader from "../../services/library_loader.js";
import TypeWidget from "./type_widget.js";
import utils from '../../services/utils.js';
-import froca from "../../services/froca.js";
import debounce from "../../services/debounce.js";
const {sleep} = utils;
diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js
index aa2eac47d0..660d5a5c33 100644
--- a/src/public/app/widgets/type_widgets/read_only_text.js
+++ b/src/public/app/widgets/type_widgets/read_only_text.js
@@ -1,4 +1,3 @@
-import froca from "../../services/froca.js";
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
import treeService from "../../services/tree.js";
import libraryLoader from "../../services/library_loader.js";
diff --git a/src/public/app/widgets/watched_file_update_status.js b/src/public/app/widgets/watched_file_update_status.js
index 35efbb0d63..7e2818ac4d 100644
--- a/src/public/app/widgets/watched_file_update_status.js
+++ b/src/public/app/widgets/watched_file_update_status.js
@@ -24,8 +24,6 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidge
isEnabled() {
const { entityType, entityId } = this.getEntity();
- console.log(entityType, entityId);
-
return super.isEnabled() && !!fileWatcher.getFileModificationStatus(entityType, entityId);
}
@@ -56,7 +54,7 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidge
});
}
- refreshWithNote(note) {
+ async refreshWithNote(note) {
const { entityType, entityId } = this.getEntity();
const status = fileWatcher.getFileModificationStatus(entityType, entityId);
diff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.js
index abc9415c60..a41e950336 100644
--- a/src/routes/api/note_revisions.js
+++ b/src/routes/api/note_revisions.js
@@ -26,7 +26,6 @@ function getNoteRevisions(req) {
}
function getNoteRevision(req) {
- // FIXME
const noteRevision = becca.getNoteRevision(req.params.noteRevisionId);
if (noteRevision.type === 'file') {
diff --git a/src/services/data_encryption.js b/src/services/data_encryption.js
index 3218bb2855..d75d62d3b4 100644
--- a/src/services/data_encryption.js
+++ b/src/services/data_encryption.js
@@ -51,13 +51,16 @@ function encrypt(key, plainText) {
return encryptedDataWithIv.toString('base64');
}
+/**
+ * @returns {Buffer|false|null}
+ */
function decrypt(key, cipherText) {
if (cipherText === null) {
return null;
}
if (!key) {
- return "[protected]";
+ return Buffer.from("[protected]");
}
try {
@@ -103,17 +106,13 @@ function decryptString(dataKey, cipherText) {
if (buffer === null) {
return null;
- }
-
- const str = buffer.toString('utf-8');
-
- if (str === 'false') {
+ } else if (buffer === false) {
log.error(`Could not decrypt string. Buffer: ${buffer}`);
throw new Error("Could not decrypt string.");
}
- return str;
+ return buffer.toString('UTF-8');
}
module.exports = {
diff --git a/src/services/import/single.js b/src/services/import/single.js
index d0c3517407..cf7496c2ce 100644
--- a/src/services/import/single.js
+++ b/src/services/import/single.js
@@ -65,7 +65,7 @@ function importCodeNote(taskContext, file, parentNote) {
const detectedMime = mimeService.getMime(file.originalname) || file.mimetype;
const mime = mimeService.normalizeMimeType(detectedMime);
- const {note} = noteService.createNewNote({
+ const { note } = noteService.createNewNote({
parentNoteId: parentNote.noteId,
title,
content,
diff --git a/src/services/import/zip.js b/src/services/import/zip.js
index fb3c2a50b2..da272c6b3f 100644
--- a/src/services/import/zip.js
+++ b/src/services/import/zip.js
@@ -369,6 +369,10 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
return content;
}
+ /**
+ * @param {string} filePath
+ * @param {Buffer} content
+ */
function saveNote(filePath, content) {
const {parentNoteMeta, noteMeta, attachmentMeta} = getMeta(filePath);
@@ -566,6 +570,7 @@ function streamToBuffer(stream) {
return new Promise((res, rej) => stream.on('end', () => res(Buffer.concat(chunks))));
}
+/** @returns {Buffer} */
function readContent(zipfile, entry) {
return new Promise((res, rej) => {
zipfile.openReadStream(entry, function(err, readStream) {
diff --git a/src/services/options.js b/src/services/options.js
index 62d4c5aa25..ccb6225145 100644
--- a/src/services/options.js
+++ b/src/services/options.js
@@ -1,6 +1,7 @@
const becca = require('../becca/becca');
const sql = require("./sql");
+/** @returns {string|null} */
function getOptionOrNull(name) {
let option;
@@ -14,11 +15,12 @@ function getOptionOrNull(name) {
return option ? option.value : null;
}
+/** @returns {string} */
function getOption(name) {
const val = getOptionOrNull(name);
if (val === null) {
- throw new Error(`Option "${name}" doesn't exist`);
+ throw new Error(`Option '${name}' doesn't exist`);
}
return val;
diff --git a/src/share/routes.js b/src/share/routes.js
index cd3aa206b0..2d9aa50488 100644
--- a/src/share/routes.js
+++ b/src/share/routes.js
@@ -177,7 +177,7 @@ function register(router) {
res.send(note.getContent());
});
- // :filename is not used by trilium, but instead used for "save as" to assign a human readable filename
+ // :filename is not used by trilium, but instead used for "save as" to assign a human-readable filename
router.get('/share/api/images/:noteId/:filename', (req, res, next) => {
shacaLoader.ensureLoad();