From ab7a07a318d09a9f69bccbb7d8bc63ebbdbeaa61 Mon Sep 17 00:00:00 2001 From: soulsands <407221377@qq.com> Date: Sat, 8 Apr 2023 19:51:39 +0800 Subject: [PATCH 1/6] fix: remove extra params --- src/etapi/special_notes.js | 10 +++++----- src/services/search/services/parse.js | 4 ++-- src/services/sql.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/etapi/special_notes.js b/src/etapi/special_notes.js index 3cc38260b..7e1e2a6f5 100644 --- a/src/etapi/special_notes.js +++ b/src/etapi/special_notes.js @@ -20,7 +20,7 @@ function register(router) { const {date} = req.params; if (!isValidDate(date)) { - throw getDateInvalidError(res, date); + throw getDateInvalidError(date); } const note = specialNotesService.getInboxNote(date); @@ -31,7 +31,7 @@ function register(router) { const {date} = req.params; if (!isValidDate(date)) { - throw getDateInvalidError(res, date); + throw getDateInvalidError(date); } const note = dateNotesService.getDayNote(date); @@ -42,7 +42,7 @@ function register(router) { const {date} = req.params; if (!isValidDate(date)) { - throw getDateInvalidError(res, date); + throw getDateInvalidError(date); } const note = dateNotesService.getWeekNote(date); @@ -53,7 +53,7 @@ function register(router) { const {month} = req.params; if (!/[0-9]{4}-[0-9]{2}/.test(month)) { - throw getMonthInvalidError(res, month); + throw getMonthInvalidError(month); } const note = dateNotesService.getMonthNote(month); @@ -64,7 +64,7 @@ function register(router) { const {year} = req.params; if (!/[0-9]{4}/.test(year)) { - throw getYearInvalidError(res, year); + throw getYearInvalidError(year); } const note = dateNotesService.getYearNote(year); diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.js index 6332f7728..1580caa37 100644 --- a/src/services/search/services/parse.js +++ b/src/services/search/services/parse.js @@ -155,7 +155,7 @@ function getExpression(tokens, searchContext, level = 0) { i++; - return new NoteContentFulltextExp(operator.token, {tokens: [tokens[i].token], raw }); + return new NoteContentFulltextExp(operator.token, {tokens: [tokens[i].token], raw}); } if (tokens[i].token === 'parents') { @@ -389,7 +389,7 @@ function getExpression(tokens, searchContext, level = 0) { else if (token === 'note') { i++; - expressions.push(parseNoteProperty(tokens)); + expressions.push(parseNoteProperty()); continue; } diff --git a/src/services/sql.js b/src/services/sql.js index 71af2394f..1b20eaff2 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -217,7 +217,7 @@ function wrap(query, func) { // in these cases error should be simply ignored. console.log(e.message); - return null + return null; } throw e; @@ -281,7 +281,7 @@ function fillParamList(paramIds, truncate = true) { } // doing it manually to avoid this showing up on the sloq query list - const s = stmt(`INSERT INTO param_list VALUES ${paramIds.map(paramId => `(?)`).join(',')}`, paramIds); + const s = stmt(`INSERT INTO param_list VALUES ${paramIds.map(paramId => `(?)`).join(',')}`); s.run(paramIds); } From 49d1c5140e1ecdd376fafb9aff8ce9b171887cb5 Mon Sep 17 00:00:00 2001 From: soulsands <407221377@qq.com> Date: Sat, 8 Apr 2023 19:54:59 +0800 Subject: [PATCH 2/6] fix: equal --- src/services/attributes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/attributes.js b/src/services/attributes.js index d123829d5..5dffc5c7f 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -7,7 +7,7 @@ const BAttribute = require('../becca/entities/battribute'); const {formatAttrForSearch} = require("./attribute_formatter"); const BUILTIN_ATTRIBUTES = require("./builtin_attributes"); -const ATTRIBUTE_TYPES = [ 'label', 'relation' ]; +const ATTRIBUTE_TYPES = ['label', 'relation']; /** @returns {BNote[]} */ function getNotesWithLabel(name, value = undefined) { @@ -122,7 +122,7 @@ function isAttributeType(type) { function isAttributeDangerous(type, name) { return BUILTIN_ATTRIBUTES.some(attr => - attr.type === attr.type && + attr.type === type && attr.name.toLowerCase() === name.trim().toLowerCase() && attr.isDangerous ); From 50043f889bf5ac69f66f6863da906d4f91811537 Mon Sep 17 00:00:00 2001 From: soulsands <407221377@qq.com> Date: Sat, 8 Apr 2023 20:00:42 +0800 Subject: [PATCH 3/6] fix: remove duplication --- src/becca/similarity.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/becca/similarity.js b/src/becca/similarity.js index dadfb1ce5..2e7750100 100644 --- a/src/becca/similarity.js +++ b/src/becca/similarity.js @@ -2,7 +2,7 @@ const becca = require('./becca'); const log = require('../services/log'); const beccaService = require('./becca_service'); const dateUtils = require('../services/date_utils'); -const { JSDOM } = require("jsdom"); +const {JSDOM} = require("jsdom"); const DEBUG = false; @@ -168,7 +168,6 @@ function trimMime(mime) { } mimeCache[mime] = str; - mimeCache[mime] = str; } return mimeCache[mime]; @@ -224,8 +223,8 @@ function splitToWords(text) { */ function hasConnectingRelation(sourceNote, targetNote) { return sourceNote.getAttributes().find(attr => attr.type === 'relation' - && ['includenotelink', 'imagelink'].includes(attr.name) - && attr.value === targetNote.noteId); + && ['includenotelink', 'imagelink'].includes(attr.name) + && attr.value === targetNote.noteId); } async function findSimilarNotes(noteId) { @@ -301,7 +300,7 @@ async function findSimilarNotes(noteId) { for (const branch of parentNote.getParentBranches()) { score += gatherRewards(branch.prefix, 0.3) - + gatherAncestorRewards(branch.parentNote); + + gatherAncestorRewards(branch.parentNote); } } } @@ -314,7 +313,7 @@ async function findSimilarNotes(noteId) { function computeScore(candidateNote) { let score = gatherRewards(trimMime(candidateNote.mime)) - + gatherAncestorRewards(candidateNote); + + gatherAncestorRewards(candidateNote); if (candidateNote.isDecrypted) { score += gatherRewards(candidateNote.title); @@ -382,7 +381,7 @@ async function findSimilarNotes(noteId) { score += 1; } else if (utcDateCreated.substr(0, 10) === dateLimits.minDate.substr(0, 10) - || utcDateCreated.substr(0, 10) === dateLimits.maxDate.substr(0, 10)) { + || utcDateCreated.substr(0, 10) === dateLimits.maxDate.substr(0, 10)) { if (displayRewards) { console.log("Adding reward for same day of creation"); } From 181ddce88759495c9fb300e5b64d60b08a04b5b3 Mon Sep 17 00:00:00 2001 From: soulsands <407221377@qq.com> Date: Sat, 8 Apr 2023 20:49:25 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=E3=80=80remove=20misleading=20await?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/app/services/branches.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/public/app/services/branches.js b/src/public/app/services/branches.js index b94c95b2a..c414cf257 100644 --- a/src/public/app/services/branches.js +++ b/src/public/app/services/branches.js @@ -10,7 +10,7 @@ async function moveBeforeBranch(branchIdsToMove, beforeBranchId) { branchIdsToMove = filterRootNote(branchIdsToMove); branchIdsToMove = filterSearchBranches(branchIdsToMove); - const beforeBranch = await froca.getBranch(beforeBranchId); + const beforeBranch = froca.getBranch(beforeBranchId); if (['root', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(beforeBranch.noteId)) { toastService.showError('Cannot move notes here.'); @@ -31,7 +31,7 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) { branchIdsToMove = filterRootNote(branchIdsToMove); branchIdsToMove = filterSearchBranches(branchIdsToMove); - const afterNote = await froca.getBranch(afterBranchId).getNote(); + const afterNote = froca.getBranch(afterBranchId).getNote(); const forbiddenNoteIds = [ 'root', @@ -59,7 +59,7 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) { } async function moveToParentNote(branchIdsToMove, newParentBranchId) { - const newParentBranch = await froca.getBranch(newParentBranchId); + const newParentBranch = froca.getBranch(newParentBranchId); if (newParentBranch.noteId === '_lbRoot') { toastService.showError('Cannot move notes here.'); @@ -165,7 +165,7 @@ function filterRootNote(branchIds) { const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); return branchIds.filter(branchId => { - const branch = froca.getBranch(branchId); + const branch = froca.getBranch(branchId); return branch.noteId !== 'root' && branch.noteId !== hoistedNoteId; From a0ac603260353072ed1ae56b173b8fbdfda53297 Mon Sep 17 00:00:00 2001 From: soulsands <407221377@qq.com> Date: Sat, 8 Apr 2023 21:07:48 +0800 Subject: [PATCH 5/6] fix:Remove duplicates in character class --- src/public/app/services/utils.js | 10 +++++----- src/services/attribute_formatter.js | 6 +++--- src/services/search/services/search.js | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/public/app/services/utils.js b/src/public/app/services/utils.js index 49edcf5ec..e0ef2d767 100644 --- a/src/public/app/services/utils.js +++ b/src/public/app/services/utils.js @@ -29,7 +29,7 @@ function formatTimeWithSeconds(date) { // this is producing local time! function formatDate(date) { -// return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear(); + // return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear(); // instead of european format we'll just use ISO as that's pretty unambiguous return formatDateISO(date); @@ -45,7 +45,7 @@ function formatDateTime(date) { } function localNowDateTime() { - return dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ') + return dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ'); } function now() { @@ -101,7 +101,7 @@ async function stopWatch(what, func) { } function formatValueWithWhitespace(val) { - return /[^\w_-]/.test(val) ? `"${val}"` : val; + return /[^\w-]/.test(val) ? `"${val}"` : val; } function formatLabel(label) { @@ -318,7 +318,7 @@ function initHelpDropdown($el) { initHelpButtons($dropdownMenu); } -const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/" +const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/"; function openHelp(e) { window.open(wikiBaseUrl + $(e.target).attr("data-help-page"), '_blank'); @@ -329,7 +329,7 @@ function initHelpButtons($el) { // so we do it manually $el.on("click", e => { if ($(e.target).attr("data-help-page")) { - openHelp(e) + openHelp(e); } }); } diff --git a/src/services/attribute_formatter.js b/src/services/attribute_formatter.js index 8891a7813..c8a9c1de6 100644 --- a/src/services/attribute_formatter.js +++ b/src/services/attribute_formatter.js @@ -1,4 +1,4 @@ -"use strict" +"use strict"; function formatAttrForSearch(attr, searchWithValue) { let searchStr = ''; @@ -28,7 +28,7 @@ function formatAttrForSearch(attr, searchWithValue) { } function formatValue(val) { - if (!/[^\w_]/.test(val)) { + if (!/[^\w]/.test(val)) { return val; } else if (!val.includes('"')) { @@ -47,4 +47,4 @@ function formatValue(val) { module.exports = { formatAttrForSearch -} +}; diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index 4b4f2110e..f1adc72d7 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -73,7 +73,7 @@ function searchFromRelation(note, relationName) { return []; } - const result = scriptService.executeNote(scriptNote, { originEntity: note }); + const result = scriptService.executeNote(scriptNote, {originEntity: note}); if (!Array.isArray(result)) { log.info(`Result from ${scriptNote.noteId} is not an array.`); @@ -288,7 +288,7 @@ function searchNotesForAutocomplete(query) { noteTitle: beccaService.getNoteTitle(result.noteId), notePathTitle: result.notePathTitle, highlightedNotePathTitle: result.highlightedNotePathTitle - } + }; }); } @@ -370,7 +370,7 @@ function formatAttribute(attr) { let label = `#${utils.escapeHtml(attr.name)}`; if (attr.value) { - const val = /[^\w_-]/.test(attr.value) ? `"${attr.value}"` : attr.value; + const val = /[^\w-]/.test(attr.value) ? `"${attr.value}"` : attr.value; label += `=${utils.escapeHtml(val)}`; } From 745e120a0bc61c19eee597575718106d51270081 Mon Sep 17 00:00:00 2001 From: soulsands <407221377@qq.com> Date: Sat, 8 Apr 2023 21:13:37 +0800 Subject: [PATCH 6/6] fix: remove unused variable --- src/public/app/services/import.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/public/app/services/import.js b/src/public/app/services/import.js index dfc91c0df..7e5fc43b6 100644 --- a/src/public/app/services/import.js +++ b/src/public/app/services/import.js @@ -10,7 +10,6 @@ export async function uploadFiles(parentNoteId, files, options) { } const taskId = utils.randomString(10); - let noteId; let counter = 0; for (const file of files) { @@ -25,19 +24,19 @@ export async function uploadFiles(parentNoteId, files, options) { formData.append(key, options[key]); } - ({noteId} = await $.ajax({ + await $.ajax({ url: `${baseApiUrl}notes/${parentNoteId}/import`, headers: await server.getHeaders(), data: formData, dataType: 'json', type: 'POST', timeout: 60 * 60 * 1000, - error: function(xhr) { + error: function (xhr) { toastService.showError(`Import failed: ${xhr.responseText}`); }, contentType: false, // NEEDED, DON'T REMOVE THIS processData: false, // NEEDED, DON'T REMOVE THIS - })); + }); } } @@ -74,4 +73,4 @@ ws.subscribeToMessages(async message => { export default { uploadFiles -} +};