Git Product home page Git Product logo

singlefile2trilium's Introduction

singlefile2trilium's People

Contributors

dousha avatar imgbot[bot] avatar imgbotapp avatar nil0x42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

singlefile2trilium's Issues

await is only valid in async functions

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
}

UnicodeDecodeError

head = fd.read(4096)

UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 271: illegal multibyte sequence

Saved Content Not Displaying

Hello,
I've tried to run your plugin and the content in my Trilium instance is not displaying. I've have this issue on both an Ubuntu 22 and Linux Mint.

DB not initialized, please visit setup page
DB size: 4 KB
Generated session secret
Trusted reverse proxy: false
App HTTP server starting up at port 37840
{
  "appVersion": "0.60.4",
  "dbVersion": 214,
  "syncVersion": 29,
  "buildDate": "2023-06-19T23:26:50+02:00",
  "buildRevision": "5905950c17791ce0eb278e010c2c8b3450fdb447",
  "dataDirectory": "/home/user/.local/share/trilium-data",
  "clipperProtocolVersion": "1.0",
  "utcDateTime": "2023-09-06T01:24:17.796Z"
}

When I run the js code, I see the following output in the terminal. The first is when I run the js script by itself. The second is the file being processed by the js code.


[Script HgXeirde76dJ] ERROR: Execution of script "singlefile2trilium-handler.js" (HgXeirde76dJ) failed with error: Load of script note "singlefile2trilium-handler.js" (HgXeirde76dJ) failed with: Cannot read properties of undefined (reading 'body')
ERROR: post /api/script/run/:noteId threw exception: 'Load of script note "singlefile2trilium-handler.js" (HgXeirde76dJ) failed with: Cannot read properties of undefined (reading 'body')', stack: Error: Load of script note "singlefile2trilium-handler.js" (HgXeirde76dJ) failed with: Cannot read properties of undefined (reading 'body')
    at Object.eval (eval at <anonymous> (/usr/lib/trilium/resources/app.asar/src/services/script.js:79:32), <anonymous>:72:21)
    at eval (eval at <anonymous> (/usr/lib/trilium/resources/app.asar/src/services/script.js:79:32), <anonymous>:75:4)
    at eval (eval at <anonymous> (/usr/lib/trilium/resources/app.asar/src/services/script.js:79:32), <anonymous>:78:2)
    at ScriptContext.<anonymous> (/usr/lib/trilium/resources/app.asar/src/services/script.js:79:32)
    at execute (/usr/lib/trilium/resources/app.asar/src/services/script.js:79:89)
    at executeBundle (/usr/lib/trilium/resources/app.asar/src/services/script.js:45:16)
    at Object.executeNote (/usr/lib/trilium/resources/app.asar/src/services/script.js:15:12)
    at run (/usr/lib/trilium/resources/app.asar/src/routes/api/script.js:35:34)
    at Function.cb (/usr/lib/trilium/resources/app.asar/src/routes/routes.js:413:34)
    at Function.sqliteTransaction (/usr/lib/trilium/resources/app.asar/node_modules/better-sqlite3/lib/methods/transaction.js:65:24)
JS Error: 500 POST /api/script/run/HgXeirde76dJ - Load of script note "singlefile2trilium-handler.js" (HgXeirde76dJ) failed with: Cannot read properties of undefined (reading 'body')
Stack: Error
    at Object.N [as logError] (http://127.0.0.1:37840/assets/v0.60.4/app-dist/desktop.js:2:103948)
    at Object.throwError (http://127.0.0.1:37840/assets/v0.60.4/app-dist/desktop.js:2:89111)
    at h (http://127.0.0.1:37840/assets/v0.60.4/app-dist/desktop.js:2:85051)
    at async EventEmitter.<anonymous> (http://127.0.0.1:37840/assets/v0.60.4/app-dist/desktop.js:2:85932)



Slow query took 52ms: SELECT attributeId FROM attributes WHERE isDeleted = 0 AND type = 'label' AND name IN ('customRequestHandler', 'customResourceProvider')
Handling custom request "singlefile2trilium" with note HgXeirde76dJ
[Script HgXeirde76dJ] Slow query took 91ms: INSERT OR REPLACE INTO entity_changes ( entityName, entityId, hash, isErased, utcDateChanged, isSynced, changeId, componentId, instanceId ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
[Script HgXeirde76dJ] Slow query took 28ms: UPDATE branches SET notePosition = ? WHERE branchId = ?
[Script HgXeirde76dJ] Created new note 'ud1rKO9h3xe6', branch '0C2EuS63OQCu_ud1rKO9h3xe6' of type 'text', mime 'text/html'
[Script HgXeirde76dJ] Created new note 'EHjceDN080cN', branch 'ud1rKO9h3xe6_EHjceDN080cN' of type 'text', mime 'text/html'
[Script HgXeirde76dJ] Created new note '5GocirMxIwJb', branch 'EHjceDN080cN_5GocirMxIwJb' of type 'text', mime 'text/html'
[Script HgXeirde76dJ] Created new note '8sREu5sok3Xj', branch '5GocirMxIwJb_8sREu5sok3Xj' of type 'render', mime ''
[Script HgXeirde76dJ] Created new note 'V2rp1KMf1moY', branch '8sREu5sok3Xj_V2rp1KMf1moY' of type 'code', mime 'text/html'
express deprecated res.send(status): Use res.sendStatus(status) instead eval at <anonymous> (/usr/lib/trilium/resources/app.asar/src/services/script.js:79:32), <anonymous>:67:9

Let me know if you need any more information.

Searching within the content.html?

This is great, thank you for this script. Do you know how to enable a way to search within the content of the SingleFile? I see this is a render note, with the render file of content.html, but it doesn't seem like trilium's search feature is searching that file. Any thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.