mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
Merge branch 'master' into next60
This commit is contained in:
@@ -1 +1 @@
|
||||
module.exports = { buildDate:"", buildRevision: "9881e6de3e4966af39ec6245562dca6ac7b25eaa" };
|
||||
module.exports = { buildDate:"2023-04-17T21:40:35+02:00", buildRevision: "1d3272e9f8c27106a66227fbb580677ae5d70427" };
|
||||
|
||||
@@ -83,7 +83,7 @@ const ACTION_HANDLERS = {
|
||||
let res;
|
||||
|
||||
if (note.getParentBranches().length > 1) {
|
||||
res = cloningService.cloneNoteToNote(note.noteId, action.targetParentNoteId);
|
||||
res = cloningService.cloneNoteToParentNote(note.noteId, action.targetParentNoteId);
|
||||
}
|
||||
else {
|
||||
res = branchService.moveBranchToNote(note.getParentBranches()[0], action.targetParentNoteId);
|
||||
|
||||
@@ -8,7 +8,7 @@ const becca = require("../becca/becca");
|
||||
const beccaService = require("../becca/becca_service");
|
||||
const log = require("./log");
|
||||
|
||||
function cloneNoteToNote(noteId, parentNoteId, prefix) {
|
||||
function cloneNoteToParentNote(noteId, parentNoteId, prefix) {
|
||||
const parentNote = becca.getNote(parentNoteId);
|
||||
|
||||
if (parentNote.type === 'search') {
|
||||
@@ -19,7 +19,7 @@ function cloneNoteToNote(noteId, parentNoteId, prefix) {
|
||||
}
|
||||
|
||||
if (isNoteDeleted(noteId) || isNoteDeleted(parentNoteId)) {
|
||||
return { success: false, message: 'Note is deleted.' };
|
||||
return { success: false, message: 'Note cannot be cloned because either the cloned note or the intended parent is deleted.' };
|
||||
}
|
||||
|
||||
const validationResult = treeService.validateParentChild(parentNoteId, noteId);
|
||||
@@ -35,12 +35,12 @@ function cloneNoteToNote(noteId, parentNoteId, prefix) {
|
||||
isExpanded: 0
|
||||
}).save();
|
||||
|
||||
log.info(`Cloned note '${noteId}' to new parent note '${parentNoteId}' with prefix '${prefix}'`);
|
||||
log.info(`Cloned note '${noteId}' to a new parent note '${parentNoteId}' with prefix '${prefix}'`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
branchId: branch.branchId,
|
||||
notePath: `${beccaService.getNotePath(parentNoteId).path}/${noteId}`
|
||||
notePath: `${parentNote.getBestNotePathString()}/${noteId}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ function cloneNoteToBranch(noteId, parentBranchId, prefix) {
|
||||
return { success: false, message: `Parent branch ${parentBranchId} does not exist.` };
|
||||
}
|
||||
|
||||
const ret = cloneNoteToNote(noteId, parentBranch.noteId, prefix);
|
||||
const ret = cloneNoteToParentNote(noteId, parentBranch.noteId, prefix);
|
||||
|
||||
parentBranch.isExpanded = true; // the new target should be expanded, so it immediately shows up to the user
|
||||
parentBranch.save();
|
||||
@@ -182,7 +182,7 @@ function isNoteDeleted(noteId) {
|
||||
|
||||
module.exports = {
|
||||
cloneNoteToBranch,
|
||||
cloneNoteToNote,
|
||||
cloneNoteToParentNote,
|
||||
ensureNoteIsPresentInParent,
|
||||
ensureNoteIsAbsentFromParent,
|
||||
toggleNoteInParent,
|
||||
|
||||
@@ -20,6 +20,7 @@ const dayjs = require("dayjs");
|
||||
const htmlSanitizer = require("./html_sanitizer");
|
||||
const ValidationError = require("../errors/validation_error");
|
||||
const noteTypesService = require("./note_types");
|
||||
const fs = require("fs");
|
||||
|
||||
/** @param {BNote} parentNote */
|
||||
function getNewNotePosition(parentNote) {
|
||||
@@ -395,7 +396,24 @@ const imageUrlToAttachmentIdMapping = {};
|
||||
|
||||
async function downloadImage(noteId, imageUrl) {
|
||||
try {
|
||||
const imageBuffer = await request.getImage(imageUrl);
|
||||
let imageBuffer;
|
||||
|
||||
if (imageUrl.toLowerCase().startsWith("file://")) {
|
||||
imageBuffer = await new Promise((res, rej) => {
|
||||
const localFilePath = imageUrl.substr("file://".length);
|
||||
|
||||
return fs.readFile(localFilePath, (err, data) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
} else {
|
||||
res(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
imageBuffer = await request.getImage(imageUrl);
|
||||
}
|
||||
|
||||
const parsedUrl = url.parse(imageUrl);
|
||||
const title = path.basename(parsedUrl.pathname);
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ class NoteFlatTextExp extends Expression {
|
||||
* @param {string[]} tokens
|
||||
* @param {string[]} path
|
||||
*/
|
||||
function searchDownThePath(note, tokens, path) {
|
||||
const searchDownThePath = (note, tokens, path) => {
|
||||
if (tokens.length === 0) {
|
||||
const retPath = beccaService.getSomePath(note, path);
|
||||
const retPath = this.getNotePath(note, path);
|
||||
|
||||
if (retPath) {
|
||||
const noteId = retPath[retPath.length - 1];
|
||||
@@ -131,6 +131,17 @@ class NoteFlatTextExp extends Expression {
|
||||
return resultNoteSet;
|
||||
}
|
||||
|
||||
getNotePath(note, path) {
|
||||
if (path.length === 0) {
|
||||
return note.getBestNotePath();
|
||||
} else {
|
||||
const closestNoteId = path[0];
|
||||
const closestNoteBestNotePath = becca.getNote(closestNoteId).getBestNotePath();
|
||||
|
||||
return [...closestNoteBestNotePath, ...path.slice(1)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns noteIds which have at least one matching tokens
|
||||
*
|
||||
|
||||
@@ -157,7 +157,7 @@ function findResultsWithExpression(expression, searchContext) {
|
||||
const searchResults = noteSet.notes
|
||||
.filter(note => !note.isDeleted)
|
||||
.map(note => {
|
||||
const notePathArray = executionContext.noteIdToNotePath[note.noteId] || beccaService.getSomePath(note);
|
||||
const notePathArray = executionContext.noteIdToNotePath[note.noteId] || note.getBestNotePath();
|
||||
|
||||
if (!notePathArray) {
|
||||
throw new Error(`Can't find note path for note ${JSON.stringify(note.getPojo())}`);
|
||||
|
||||
@@ -9,6 +9,18 @@ const protectedSessionService = require('./protected_session');
|
||||
const becca = require("../becca/becca");
|
||||
const AbstractBeccaEntity = require("../becca/entities/abstract_becca_entity");
|
||||
|
||||
const env = require('./env');
|
||||
if (env.isDev()) {
|
||||
const chokidar = require('chokidar');
|
||||
const debounce = require('debounce');
|
||||
const debouncedReloadFrontend = debounce(reloadFrontend, 200);
|
||||
chokidar
|
||||
.watch('src/public')
|
||||
.on('add', debouncedReloadFrontend)
|
||||
.on('change', debouncedReloadFrontend)
|
||||
.on('unlink', debouncedReloadFrontend);
|
||||
}
|
||||
|
||||
let webSocketServer;
|
||||
let lastSyncedPush = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user