-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
The customRequestHandler return error: await is only valid in async function.
Removing await keyword from the code seems working.
trilium version: 0.48.1-beta
My revised code:
// HowTo:
// 1- Add this file to trilium as a `JS Backend` code note.
// 2- Set label `customRequestHandler` to 'singlefile2trilium'.
const template = `
<script>
var iframe = document.getElementById('r-iframe');
function pageY(elem) {
return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
}
function resizeIframe() {
var height = document.documentElement.clientHeight;
height -= pageY(iframe) + 20 ;
height = (height < 0) ? 0 : height;
iframe.style.height = height + 'px';
}
iframe.onload = resizeIframe;
window.onresize = resizeIframe;
</script>
<iframe id="r-iframe" style="width:100%" src="data:text/html;charset=utf-8,%%CONTENT%%" sandbox=""></iframe>
`;
const {req, res} = api;
const {title, url, content} = req.body;
if (req.method == 'POST') {
api.log("==========================");
// create render note
const renderNote = (api.createNewNote({
parentNoteId: "IIgUiHfe3hu0",
title: title,
content: '',
type: 'render'
})).note;
renderNote.setLabel('clipType', 'singlefile2trilium');
renderNote.setLabel('pageUrl', url);
renderNote.setLabel('pageTitle', title);
// create child `content.html`
var wrapped_content = template.replace("%%CONTENT%%", encodeURIComponent(content));
const htmlNote = (api.createNewNote({
parentNoteId: renderNote.noteId,
title: 'content.html',
content: wrapped_content,
type: 'code',
mime: 'text/html'
})).note;
htmlNote.setLabel('archived');
// link renderNote to htmlNote
renderNote.setRelation('renderNote', htmlNote.noteId);
res.send(201); // http 201: created
}
else {
res.send(400); // http 400: bad request
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels