Trilium: Crypto module not available for backend code notes?

Created on 9 Aug 2019  ·  2Comments  ·  Source: zadam/trilium

I'm trying to import the crypto module in a backend node but I am getting the error:

Load of script note "bookmarks" (6OPdoa7YvWok) failed with: Could not find module note crypto⏎

Here is my code:

const {req, res} = api;
const {version} = req.body;
const crypto = require('crypto');

const dataNodeID = await api.currentNote.getRelationValue('data');
const dataNode = await api.getNote(dataNodeID);
const data = await dataNode.getJsonContent();

if (req.method == 'POST' && data.syncID === "")
{
    if (version != "1.0.0")
    {
        res.send(400, "Unexpected version! Expected version \"1.0.0\"");
        return;
    }

    if (data.password === "")
    {
        //res.send
    }

    const chars = [..."abcdef0123456789"];
    data.syncID = [...Array(32)].map(i=>chars[Math.random()*chars.length|0]).join``;
    data.lastUpdate = new Date().toISOString();

    dataNode.setJsonContent(data);

    res.send({
        "version": "1.0.0",
        "lastUpdated": data.lastUpdate,
        "syncID" : data.syncID});
}
else
{
    res.send(400, "SyncID already created! To reset it, delete it in the xBrowserSyncAPI note.");
}

Most helpful comment

Hello, require function is overriden to work with notes as modules and it currently does not have a fallback for native modules. But that's probably just an omission (not an intention) and I will fix it in the next release.

All 2 comments

Hello, require function is overriden to work with notes as modules and it currently does not have a fallback for native modules. But that's probably just an omission (not an intention) and I will fix it in the next release.

fixed in stable branch

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thbkrshw picture thbkrshw  ·  4Comments

zadam picture zadam  ·  5Comments

tvortsa picture tvortsa  ·  3Comments

zadam picture zadam  ·  4Comments

apg-dev picture apg-dev  ·  5Comments