Skip to content

Build your personal knowledge base with Trilium Notes

Merge remote-tracking branch 'origin/stable' into syncification

zadama574fce13fef
diff --cc src/routes/api/notes.js
index 1bc14ff6ef,12f58540b9..5a69ad429f
--- a/src/routes/api/notes.js
+++ b/src/routes/api/notes.js
@@@ -164,10 -164,16 +164,16 @@@ function changeTitle(req)
return [400, `Note ${noteId} is not available for change`];
}
+ const noteTitleChanged = note.title !== title;
+
note.title = title;
- await note.save();
+ note.save();
+ if (noteTitleChanged) {
+ await noteService.triggerNoteTitleChanged(note);
+ }
+
return note;
}
diff --cc src/routes/custom.js
index e269f14194,c8535c6046..5f26a42761
--- a/src/routes/custom.js
+++ b/src/routes/custom.js
@@@ -2,64 -2,73 +2,73 @@@ const repository = require('../services
const log = require('../services/log');
const fileUploadService = require('./api/files.js');
const scriptService = require('../services/script');
+ const cls = require('../services/cls');
- function register(router) {
- // explicitly no CSRF middleware since it's meant to allow integration from external services
+ async function handleRequest(req, res) {
+ // express puts content after first slash into 0 index element
+
+ const path = req.params.path + req.params[0];
- router.all('/custom/:path*', (req, res, next) => {
- // express puts content after first slash into 0 index element
- const path = req.params.path + req.params[0];
- const attrs = await repository.getEntities("SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label' AND name IN ('customRequestHandler', 'customResourceProvider')");
++ const attrs = repository.getEntities("SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label' AND name IN ('customRequestHandler', 'customResourceProvider')");
- const attrs = repository.getEntities("SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label' AND name IN ('customRequestHandler', 'customResourceProvider')");
+ for (const attr of attrs) {
+ const regex = new RegExp(attr.value);
+ let match;
- for (const attr of attrs) {
- const regex = new RegExp(attr.value);
- let match;
+ try {
+ match = path.match(regex);
+ }
+ catch (e) {
+ log.error(`Testing path for label ${attr.attributeId}, regex=${attr.value} failed with error ` + e.stack);
+ continue;
+ }
+
+ if (!match) {
+ continue;
+ }
+
+ if (attr.name === 'customRequestHandler') {
- const note = await attr.getNote();
++ const note = attr.getNote();
+
+ log.info(`Handling custom request "${path}" with note ${note.noteId}`);
try {
- match = path.match(regex);
- await scriptService.executeNote(note, {
++ scriptService.executeNote(note, {
+ pathParams: match.slice(1),
+ req,
+ res
+ });
}
catch (e) {
- log.error(`Testing path for label ${attr.attributeId}, regex=${attr.value} failed with error ` + e.stack);
- continue;
- }
+ log.error(`Custom handler ${note.noteId} failed with ${e.message}`);
- if (!match) {
- continue;
+ res.status(500).send(e.message);
}
+ }
+ else if (attr.name === 'customResourceProvider') {
- await fileUploadService.downloadNoteFile(attr.noteId, res);
++ fileUploadService.downloadNoteFile(attr.noteId, res);
+ }
+ else {
+ throw new Error("Unrecognized attribute name " + attr.name);
+ }
- if (attr.name === 'customRequestHandler') {
- const note = attr.getNote();
-
- log.info(`Handling custom request "${path}" with note ${note.noteId}`);
+ return; // only first handler is executed
+ }
- try {
- scriptService.executeNote(note, {
- pathParams: match.slice(1),
- req,
- res
- });
- }
- catch (e) {
- log.error(`Custom handler ${note.noteId} failed with ${e.message}`);
+ const message = `No handler matched for custom ${path} request.`;
- res.status(500).send(e.message);
- }
- }
- else if (attr.name === 'customResourceProvider') {
- fileUploadService.downloadNoteFile(attr.noteId, res);
- }
- else {
- throw new Error("Unrecognized attribute name " + attr.name);
- }
+ log.info(message);
+ res.status(404).send(message);
+ }
- return; // only first handler is executed
- }
+ function register(router) {
+ // explicitly no CSRF middleware since it's meant to allow integration from external services
- const message = `No handler matched for custom ${path} request.`;
+ router.all('/custom/:path*', async (req, res, next) => {
+ cls.namespace.bindEmitter(req);
+ cls.namespace.bindEmitter(res);
- log.info(message);
- res.status(404).send(message);
+ cls.init(() => handleRequest(req, res));
});
}
diff --cc src/services/handlers.js
index 90541a3540,e68f3be44a..3b94609f40
--- a/src/services/handlers.js
+++ b/src/services/handlers.js
@@@ -66,11 -66,14 +66,14 @@@ eventService.subscribe(eventService.ENT
return;
}
- await note.setContent(await targetNote.getContent());
+ note.setContent(targetNote.getContent());
}
+ else if (entity.type === 'label' && entity.name === 'sorted') {
+ await treeService.sortNotesAlphabetically(entity.noteId);
+ }
}
else if (entityName === 'notes') {
- await runAttachedRelations(entity, 'runOnNoteCreation', entity);
+ runAttachedRelations(entity, 'runOnNoteCreation', entity);
}
});
diff --cc src/services/import/single.js
index 6241092f46,2c99a687f7..6d59d9aa7f
--- a/src/services/import/single.js
+++ b/src/services/import/single.js
@@@ -21,18 -21,18 +21,18 @@@ function importSingleFile(taskContext,
}
if (taskContext.data.codeImportedAsCode && mimeService.getType(taskContext.data, mime) === 'code') {
- return await importCodeNote(taskContext, file, parentNote);
+ return importCodeNote(taskContext, file, parentNote);
}
- if (["image/jpeg", "image/gif", "image/png", "image/webp"].includes(mime)) {
+ if (mime.startsWith("image/")) {
- return await importImage(file, parentNote, taskContext);
+ return importImage(file, parentNote, taskContext);
}
- return await importFile(taskContext, file, parentNote);
+ return importFile(taskContext, file, parentNote);
}
-async function importImage(file, parentNote, taskContext) {
- const {note} = await imageService.saveImage(parentNote.noteId, file.buffer, file.originalname, taskContext.data.shrinkImages);
+function importImage(file, parentNote, taskContext) {
+ const {note} = imageService.saveImage(parentNote.noteId, file.buffer, file.originalname, taskContext.data.shrinkImages);
taskContext.increaseProgressCount();