mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
bug fixes for custom handlers
This commit is contained in:
parent
fb27088fcd
commit
b39f6ef7ad
@ -97,7 +97,7 @@ function AttributesModel() {
|
|||||||
await showAttributes(attributes);
|
await showAttributes(attributes);
|
||||||
|
|
||||||
// attribute might not be rendered immediatelly so could not focus
|
// attribute might not be rendered immediatelly so could not focus
|
||||||
setTimeout(() => $(".attribute-type-select:last").focus(), 100);
|
setTimeout(() => $(".attribute-type-select:last").focus(), 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.deleteAttribute = function(data, event) {
|
this.deleteAttribute = function(data, event) {
|
||||||
|
@ -34,8 +34,7 @@ async function uploadFile(req) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadFile(req, res) {
|
async function downloadNoteFile(noteId, res) {
|
||||||
const noteId = req.params.noteId;
|
|
||||||
const note = await repository.getNote(noteId);
|
const note = await repository.getNote(noteId);
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
@ -43,8 +42,7 @@ async function downloadFile(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (note.isProtected && !protectedSessionService.isProtectedSessionAvailable()) {
|
if (note.isProtected && !protectedSessionService.isProtectedSessionAvailable()) {
|
||||||
res.status(401).send("Protected session not available");
|
return res.status(401).send("Protected session not available");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalFileName = await note.getLabel('originalFileName');
|
const originalFileName = await note.getLabel('originalFileName');
|
||||||
@ -56,7 +54,15 @@ async function downloadFile(req, res) {
|
|||||||
res.send(note.content);
|
res.send(note.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadFile(req, res) {
|
||||||
|
const noteId = req.params.noteId;
|
||||||
|
|
||||||
|
return await downloadNoteFile(noteId, res);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
uploadFile,
|
uploadFile,
|
||||||
downloadFile
|
downloadFile,
|
||||||
|
downloadNoteFile
|
||||||
};
|
};
|
@ -1,21 +1,27 @@
|
|||||||
const repository = require('../services/repository');
|
const repository = require('../services/repository');
|
||||||
const log = require('../services/log');
|
const log = require('../services/log');
|
||||||
|
const fileUploadService = require('./api/file_upload');
|
||||||
const scriptService = require('../services/script');
|
const scriptService = require('../services/script');
|
||||||
|
|
||||||
function register(router) {
|
function register(router) {
|
||||||
router.all('/custom/:path*', async (req, res, next) => {
|
router.all('/custom/:path*', async (req, res, next) => {
|
||||||
const attrs = await repository.getEntities("SELECT * FROM attributes WHERE isDeleted = 0 AND type = 'label' AND ('customRequestHandler', 'customResourceProvider')");
|
// 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')");
|
||||||
|
|
||||||
for (const attr of attrs) {
|
for (const attr of attrs) {
|
||||||
const regex = new RegExp(attr.value);
|
const regex = new RegExp(attr.value);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const m = regex.match(router.path);
|
const m = path.match(regex);
|
||||||
|
|
||||||
if (m) {
|
if (m) {
|
||||||
if (attr.name === 'customRequestHandler') {
|
if (attr.name === 'customRequestHandler') {
|
||||||
const note = await attr.getNote();
|
const note = await attr.getNote();
|
||||||
|
|
||||||
|
log.info(`Handling custom request "${path}" with note ${note.noteId}`);
|
||||||
|
|
||||||
await scriptService.executeNote(note, {
|
await scriptService.executeNote(note, {
|
||||||
pathParams: m.slice(1),
|
pathParams: m.slice(1),
|
||||||
req,
|
req,
|
||||||
@ -23,10 +29,10 @@ function register(router) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (attr.name === 'customResourceProvider') {
|
else if (attr.name === 'customResourceProvider') {
|
||||||
|
await fileUploadService.downloadNoteFile(attr.noteId, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
@ -34,7 +40,10 @@ function register(router) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send('Hello ' + req.params.path);
|
const message = `No handler matched for custom ${path} request.`;
|
||||||
|
|
||||||
|
log.info(message);
|
||||||
|
res.status(404).send(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user