This commit is contained in:
zadam
2023-06-30 11:18:34 +02:00
parent fc564f6aed
commit 192e399cb5
77 changed files with 160 additions and 159 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ function getNotesWithLabel(name, value = undefined) {
// TODO: should be in search service
/** @returns {BNote|null} */
function getNoteWithLabel(name, value = undefined) {
// optimized version (~20 times faster) without using normal search, useful for e.g. finding date notes
// optimized version (~20 times faster) without using normal search, useful for e.g., finding date notes
const attrs = becca.findAttributes('label', name);
if (value === undefined) {
+1 -1
View File
@@ -23,7 +23,7 @@ function checkAuth(req, res, next) {
}
// for electron things which need network stuff
// currently we're doing that for file upload because handling form data seems to be difficult
// currently, we're doing that for file upload because handling form data seems to be difficult
function checkApiAuthOrElectron(req, res, next) {
if (!req.session.loggedIn && !utils.isElectron() && !noAuthentication) {
reject(req, res, "Logged in session not found");
+3 -3
View File
@@ -142,7 +142,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @param {string} noteId
* @param {string} parentNoteId
* @param {string} prefix - if branch will be created between note and parent note, set this prefix
* @param {string} prefix - if branch is created between note and parent note, set this prefix
* @returns {{branch: BBranch|null}}
*/
this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
@@ -164,7 +164,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @param {boolean} present - true if we want the branch to exist, false if we want it gone
* @param {string} noteId
* @param {string} parentNoteId
* @param {string} prefix - if branch will be created between note and parent note, set this prefix
* @param {string} prefix - if branch is created between note and parent note, set this prefix
* @returns {void}
*/
this.toggleNoteInParent = cloningService.toggleNoteInParent;
@@ -244,7 +244,7 @@ function BackendScriptApi(currentNote, apiParams) {
const parentNote = becca.getNote(parentNoteId);
// code note type can be inherited, otherwise text is default
// code note type can be inherited, otherwise "text" is the default
extraOptions.type = parentNote.type === 'code' ? 'code' : 'text';
extraOptions.mime = parentNote.type === 'code' ? parentNote.mime : 'text/html';
+1 -1
View File
@@ -156,7 +156,7 @@ function cloneNoteAfter(noteId, afterBranchId) {
return validationResult;
}
// we don't change utcDateModified so other changes are prioritized in case of conflict
// we don't change utcDateModified, so other changes are prioritized in case of conflict
// also we would have to sync all those modified branches otherwise hash checks would fail
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
[afterNote.parentNoteId, afterNote.notePosition]);
+1 -1
View File
@@ -810,7 +810,7 @@ function getBlankContent(isProtected, type, mime) {
return '{}';
}
return ''; // empty string might be wrong choice for some note types, but it's the best guess
return ''; // empty string might be a wrong choice for some note types, but it's the best guess
}
function logFix(message) {
+1 -1
View File
@@ -108,7 +108,7 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true)
}
}
// if the note is already named with extension (e.g. "jquery"), then it's silly to append exact same extension again
// if the note is already named with extension (e.g. "jquery"), then it's silly to append the exact same extension again
if (newExtension && existingExtension !== `.${newExtension.toLowerCase()}`) {
fileName += `.${newExtension}`;
}
+1 -1
View File
@@ -76,7 +76,7 @@ async function importOpml(taskContext, fileBuffer, parentNote) {
for (const outline of outlines) {
const note = importOutline(outline, parentNote.noteId);
// first created note will be activated after import
// the first created note will be activated after import
returnNote = returnNote || note;
}
+1 -1
View File
@@ -145,7 +145,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
} else if (parentPath in createdPaths) {
parentNoteId = createdPaths[parentPath];
} else {
// ZIP allows creating out of order records - i.e., file in a directory can appear in the ZIP stream before actual directory
// ZIP allows creating out of order records - i.e., file in a directory can appear in the ZIP stream before the actual directory
parentNoteId = saveDirectory(parentPath);
}
}
+14 -14
View File
@@ -69,7 +69,7 @@ function copyChildAttributes(parentNote, childNote) {
if (hasAlreadyTemplate && attr.type === 'relation' && name === 'template') {
// if the note already has a template, it means the template was chosen by the user explicitly
// in the menu. In that case we should override the default templates defined in the child: attrs
// in the menu. In that case, we should override the default templates defined in the child: attrs
continue;
}
@@ -105,8 +105,8 @@ function getNewNoteTitle(parentNote) {
}
}
// this isn't in theory a good place to sanitize title, but this will catch a lot of XSS attempts
// title is supposed to contain text only (not HTML) and be printed text only, but given the number of usages
// this isn't in theory a good place to sanitize title, but this will catch a lot of XSS attempts.
// title is supposed to contain text only (not HTML) and be printed text only, but given the number of usages,
// it's difficult to guarantee correct handling in all cases
title = htmlSanitizer.sanitize(title);
@@ -147,12 +147,12 @@ function getAndValidateParent(params) {
* - {*} content
* - {string} type - text, code, file, image, search, book, relationMap, canvas, render
*
* Following are optional (have defaults)
* The following are optional (have defaults)
* - {string} mime - value is derived from default mimes for type
* - {boolean} isProtected - default is false
* - {boolean} isExpanded - default is false
* - {string} prefix - default is empty string
* - {int} notePosition - default is last existing notePosition in a parent + 10
* - {int} notePosition - default is the last existing notePosition in a parent + 10
*
* @param params
* @returns {{note: BNote, branch: BBranch}}
@@ -226,7 +226,7 @@ function createNewNote(params) {
eventService.emit(eventService.ENTITY_CREATED, { entityName: 'notes', entity: note });
eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'notes', entity: note });
triggerNoteTitleChanged(note);
// blobs doesn't use "created" event
// blobs entity doesn't use "created" event
eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'blobs', entity: note });
eventService.emit(eventService.ENTITY_CREATED, { entityName: 'branches', entity: branch });
eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'branches', entity: branch });
@@ -245,7 +245,7 @@ function createNewNoteWithTarget(target, targetBranchId, params) {
if (!params.type) {
const parentNote = becca.notes[params.parentNoteId];
// code note type can be inherited, otherwise text is default
// code note type can be inherited, otherwise "text" is the default
params.type = parentNote.type === 'code' ? 'code' : 'text';
params.mime = parentNote.type === 'code' ? parentNote.mime : 'text/html';
}
@@ -366,7 +366,7 @@ function checkImageAttachments(note, content) {
const unknownAttachments = becca.getAttachments(unknownAttachmentIds);
for (const unknownAttachment of unknownAttachments) {
// the attachment belongs to a different note (was copy pasted). Attachments can be linked only from the note
// the attachment belongs to a different note (was copy-pasted). Attachments can be linked only from the note
// which owns it, so either find an existing attachment having the same content or make a copy.
let localAttachment = note.getAttachments().find(att => att.role === unknownAttachment.role && att.blobId === unknownAttachment.blobId);
@@ -412,7 +412,7 @@ function findImageLinks(content, foundLinks) {
});
}
// removing absolute references to server to keep it working between instances
// removing absolute references to server to keep it working between instances,
// we also omit / at the beginning to keep the paths relative
return content.replace(/src="[^"]*\/api\/images\//g, 'src="api/images/');
}
@@ -557,10 +557,10 @@ function downloadImages(noteId, content) {
setTimeout(() => {
// the normal expected flow of the offline image saving is that users will paste the image(s)
// which will get asynchronously downloaded, during that time they keep editing the note
// once the download is finished, the image note representing downloaded image will be used
// once the download is finished, the image note representing the downloaded image will be used
// to replace the IMG link.
// However, there's another flow where user pastes the image and leaves the note before the images
// are downloaded and the IMG references are not updated. For this occassion we have this code
// However, there's another flow where the user pastes the image and leaves the note before the images
// are downloaded and the IMG references are not updated. For this occasion we have this code
// which upon the download of all the images will update the note if the links have not been fixed before
sql.transactional(() => {
@@ -972,7 +972,7 @@ function eraseUnusedAttachmentsNow() {
eraseScheduledAttachments(0);
}
// do a replace in str - all keys should be replaced by the corresponding values
// all keys should be replaced by the corresponding values
function replaceByMap(str, mapObj) {
const re = new RegExp(Object.keys(mapObj).join("|"),"g");
@@ -1076,7 +1076,7 @@ function duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapp
const existingNote = becca.notes[newNoteId];
if (existingNote && existingNote.title !== undefined) { // checking that it's not just note's skeleton created because of Branch above
// note has multiple clones and was already created from another placement in the tree
// note has multiple clones and was already created from another placement in the tree,
// so a branch is all we need for this clone
return {
note: existingNote,
+2 -2
View File
@@ -123,7 +123,7 @@ function getImage(imageUrl) {
host: parsedTargetUrl.hostname,
port: parsedTargetUrl.port,
path: parsedTargetUrl.path,
timeout: opts.timeout, // works only for node client
timeout: opts.timeout, // works only for the node client
headers: {},
agent: proxyAgent
});
@@ -170,7 +170,7 @@ function getProxyAgent(opts) {
}
function getClient(opts) {
// it's not clear how to explicitly configure proxy (as opposed to system proxy)
// it's not clear how to explicitly configure proxy (as opposed to system proxy),
// so in that case, we always use node's modules
if (utils.isElectron() && !opts.proxy) {
return require('electron').net;
+1 -1
View File
@@ -4,7 +4,7 @@ const fs = require('fs');
const RESOURCE_DIR = path.resolve(__dirname, "../..");
// where "trilium" executable is
// where the "trilium" executable is
const ELECTRON_APP_ROOT_DIR = path.resolve(RESOURCE_DIR, "../..");
const DB_INIT_DIR = path.resolve(RESOURCE_DIR, "db");
+1 -1
View File
@@ -35,7 +35,7 @@ function executeBundle(bundle, apiParams = {}) {
cls.set('componentId', 'script');
cls.set('bundleNoteId', bundle.note.noteId);
// last \r\n is necessary if script contains line comment on its last line
// last \r\n is necessary if the script contains line comment on its last line
const script = `function() {\r
${bundle.script}\r
}`;
@@ -47,7 +47,7 @@ class OrderByAndLimitExp extends Expression {
return larger;
}
// if both are numbers then parse them for numerical comparison
// if both are numbers, then parse them for numerical comparison
if (this.isNumber(valA) && this.isNumber(valB)) {
valA = parseFloat(valA);
valB = parseFloat(valB);
@@ -5,8 +5,8 @@ const NoteSet = require('../note_set');
const buildComparator = require("../services/build_comparator");
/**
* Search string is lower cased for case-insensitive comparison. But when retrieving properties
* we need case-sensitive form, so we have this translation object.
* Search string is lower cased for case-insensitive comparison. But when retrieving properties,
* we need the case-sensitive form, so we have this translation object.
*/
const PROP_MAPPING = {
"noteid": "noteId",
+1 -1
View File
@@ -33,7 +33,7 @@ class SearchContext {
}
addError(error) {
// we record only the first error, subsequent ones are usually consequence of the first
// we record only the first error, subsequent ones are usually a consequence of the first
if (!this.error) {
this.error = error;
}
+1 -1
View File
@@ -1,7 +1,7 @@
"use strict";
/**
* Search string is lower cased for case-insensitive comparison. But when retrieving properties
* Search string is lower cased for case-insensitive comparison. But when retrieving properties,
* we need a case-sensitive form, so we have this translation object.
*/
const PROP_MAPPING = {
+2 -2
View File
@@ -37,7 +37,7 @@ async function sendSeedToSyncServer() {
syncVersion: appInfo.syncVersion
});
// this is completely new sync, need to reset counters. If this would not be new sync,
// this is a completely new sync, need to reset counters. If this was not a new sync,
// the previous request would have failed.
optionService.setOption('lastSyncedPush', 0);
optionService.setOption('lastSyncedPull', 0);
@@ -66,7 +66,7 @@ async function setupSyncFromSyncServer(syncServerHost, syncProxy, password) {
try {
log.info("Getting document options FROM sync server.");
// response is expected to contain documentId and documentSecret options
// the response is expected to contain documentId and documentSecret options
const resp = await request.exec({
method: 'get',
url: `${syncServerHost}/api/setup/sync-seed`,
+1 -1
View File
@@ -47,7 +47,7 @@ class SpacedUpdate {
this.changed = false;
}
else {
// update not triggered but changes are still pending, so we need to schedule another check
// update isn't triggered but changes are still pending, so we need to schedule another check
this.scheduleUpdate();
}
}
+1 -1
View File
@@ -171,7 +171,7 @@ dbReady.then(() => {
// kickoff first backup soon after start up
setTimeout(() => require('./backup').regularBackup(), 5 * 60 * 1000);
// optimize is usually inexpensive no-op so running it semi-frequently is not a big deal
// optimize is usually inexpensive no-op, so running it semi-frequently is not a big deal
setTimeout(() => optimize(), 60 * 60 * 1000);
setInterval(() => optimize(), 10 * 60 * 60 * 1000);
+2 -2
View File
@@ -203,7 +203,7 @@ async function pushChanges(syncContext) {
});
if (filteredEntityChanges.length === 0) {
// there still might be more sync changes (because of batch limit), just all from current batch
// there still might be more sync changes (because of batch limit), just all the current batch
// has been filtered out
setLastSyncedPush(lastSyncedPush);
@@ -255,7 +255,7 @@ async function checkContentHash(syncContext) {
const failedChecks = contentHashService.checkContentHashes(resp.entityHashes);
if (failedChecks.length > 0) {
// before requeuing sectors make sure the entity changes are correct
// before requeuing sectors, make sure the entity changes are correct
const consistencyChecks = require("./consistency_checks");
consistencyChecks.runEntityChangesChecks();
+1 -1
View File
@@ -21,7 +21,7 @@ module.exports = {
isSyncSetup: () => {
const syncServerHost = get('syncServerHost');
// special value "disabled" is here to support use case where document is configured with sync server,
// special value "disabled" is here to support a use case where the document is configured with sync server,
// and we need to override it with config from config.ini
return !!syncServerHost && syncServerHost !== 'disabled';
},
+2 -2
View File
@@ -93,8 +93,8 @@ function updateNoteReordering(entityChange, entity, instanceId) {
}
function handleContent(content) {
// we always use Buffer object which is different from normal saving - there we use simple string type for
// "string notes". The problem is that in general it's not possible to detect whether a blob content
// we always use a Buffer object which is different from normal saving - there we use a simple string type for
// "string notes". The problem is that in general, it's not possible to detect whether a blob content
// is string note or note (syncs can arrive out of order)
content = content === null ? null : Buffer.from(content, 'base64');
+2 -2
View File
@@ -14,10 +14,10 @@ class TaskContext {
// progressCount is meant to represent just some progress - to indicate the task is not stuck
this.progressCount = -1; // we're incrementing immediatelly
this.lastSentCountTs = 0; // 0 will guarantee first message will be sent
this.lastSentCountTs = 0; // 0 will guarantee the first message will be sent
// just the fact this has been initialized is a progress which should be sent to clients
// this is esp. important when importing big files/images which take long time to upload/process
// this is esp. important when importing big files/images which take a long time to upload/process
// which means that first "real" increaseProgressCount() will be called quite late and user is without
// feedback until then
this.increaseProgressCount();
+1 -1
View File
@@ -87,7 +87,7 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder
const bHasChildren = b.hasChildren();
if ((aHasChildren && !bHasChildren) || (!aHasChildren && bHasChildren)) {
// exactly one note of the two is a directory so the sorting will be done based on this status
// exactly one note of the two is a directory, so the sorting will be done based on this status
return aHasChildren ? -1 : 1;
}
}
+2 -2
View File
@@ -9,7 +9,7 @@ const cls = require('./cls');
const keyboardActionsService = require('./keyboard_actions');
const {ipcMain} = require('electron');
// Prevent window being garbage collected
// Prevent the window being garbage collected
/** @type {Electron.BrowserWindow} */
let mainWindow;
/** @type {Electron.BrowserWindow} */
@@ -48,7 +48,7 @@ async function createMainWindow(app) {
const windowStateKeeper = require('electron-window-state'); // should not be statically imported
const mainWindowState = windowStateKeeper({
// default window width & height, so it's usable on 1600 * 900 display (including some extra panels etc.)
// default window width & height, so it's usable on a 1600 * 900 display (including some extra panels etc.)
defaultWidth: 1200,
defaultHeight: 800
});
+1 -1
View File
@@ -185,7 +185,7 @@ function sendPing(client, entityChangeIds = []) {
// sort entity changes since froca expects "referential order", i.e. referenced entities should already exist
// in froca.
// Froca needs this since it is incomplete copy, it can't create "skeletons" like becca.
// Froca needs this since it is an incomplete copy, it can't create "skeletons" like becca.
entityChanges.sort((a, b) => ORDERING[a.entityName] - ORDERING[b.entityName]);
for (const entityChange of entityChanges) {