mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
basic support for using api/images with canvas-note
http://localhost:8080/api/images/<noteId>/some-rando-text
This commit is contained in:
parent
82e278a2a2
commit
f354821f25
7577
package-lock.json
generated
7577
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -40,7 +40,8 @@
|
|||||||
"electron-find": "1.0.7",
|
"electron-find": "1.0.7",
|
||||||
"electron-window-state": "5.0.3",
|
"electron-window-state": "5.0.3",
|
||||||
"@electron/remote": "2.0.8",
|
"@electron/remote": "2.0.8",
|
||||||
"express": "4.17.3",
|
"excalidraw-to-svg": "3.0.0",
|
||||||
|
"express": "4.17.2",
|
||||||
"express-partial-content": "1.0.2",
|
"express-partial-content": "1.0.2",
|
||||||
"express-rate-limit": "6.3.0",
|
"express-rate-limit": "6.3.0",
|
||||||
"express-session": "1.17.2",
|
"express-session": "1.17.2",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const excalidrawToSvg = require("excalidraw-to-svg");
|
||||||
const imageService = require('../../services/image');
|
const imageService = require('../../services/image');
|
||||||
const becca = require('../../becca/becca');
|
const becca = require('../../becca/becca');
|
||||||
const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR;
|
const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR;
|
||||||
@ -11,7 +12,7 @@ function returnImage(req, res) {
|
|||||||
if (!image) {
|
if (!image) {
|
||||||
return res.sendStatus(404);
|
return res.sendStatus(404);
|
||||||
}
|
}
|
||||||
else if (image.type !== 'image') {
|
else if (!["image", "canvas-note"].includes(image.type)){
|
||||||
return res.sendStatus(400);
|
return res.sendStatus(400);
|
||||||
}
|
}
|
||||||
else if (image.isDeleted || image.data === null) {
|
else if (image.isDeleted || image.data === null) {
|
||||||
@ -19,10 +20,38 @@ function returnImage(req, res) {
|
|||||||
return res.send(fs.readFileSync(RESOURCE_DIR + '/db/image-deleted.png'));
|
return res.send(fs.readFileSync(RESOURCE_DIR + '/db/image-deleted.png'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* special "image" type. the canvas-note is actually type application/json but can be
|
||||||
|
* rendered on the fly to svg.
|
||||||
|
*/
|
||||||
|
if (image.type === 'canvas-note') {
|
||||||
|
// render the svg in node.js using excalidraw and jsdom
|
||||||
|
const content = image.getContent();
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(content)
|
||||||
|
const excalidrawData = {
|
||||||
|
type: "excalidraw",
|
||||||
|
version: 2,
|
||||||
|
source: "trilium",
|
||||||
|
elements: data.elements,
|
||||||
|
appState: data.appState,
|
||||||
|
files: data.files,
|
||||||
|
}
|
||||||
|
excalidrawToSvg(excalidrawData)
|
||||||
|
.then(svg => {
|
||||||
|
const svgHtml = svg.outerHTML;
|
||||||
|
res.set('Content-Type', "image/svg+xml");
|
||||||
|
res.set("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
res.send(svgHtml);
|
||||||
|
});
|
||||||
|
} catch(err) {
|
||||||
|
res.sendStatus(500);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
res.set('Content-Type', image.mime);
|
res.set('Content-Type', image.mime);
|
||||||
res.set("Cache-Control", "no-cache, no-store, must-revalidate");
|
res.set("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
|
||||||
res.send(image.getContent());
|
res.send(image.getContent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadImage(req) {
|
function uploadImage(req) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user