Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Merge branch 'release/v0.102.2'
Elian Doran109f06f8bbe6
diff --cc apps/server/src/routes/api/image.tsindex 026e069c0d,988921bdfd..746bad288f--- a/apps/server/src/routes/api/image.ts+++ b/apps/server/src/routes/api/image.ts@@@ -6,8 -8,9 +6,9 @@@ import type BNote from "../../becca/entimport type BRevision from "../../becca/entities/brevision.js";import imageService from "../../services/image.js";import { RESOURCE_DIR } from "../../services/resource_dir.js";+ import { sanitizeSvg } from "../../services/utils.js";-function returnImageFromNote(req: Request, res: Response) {+function returnImageFromNote(req: Request<{ noteId: string }>, res: Response) {const image = becca.getNote(req.params.noteId);return returnImageInt(image, res);@@@ -59,22 -65,10 +65,22 @@@ export function renderSvgAttachment(imares.set("Content-Type", "image/svg+xml");res.set("Cache-Control", "no-cache, no-store, must-revalidate");- res.send(svg);+ sendSanitizedSvg(res, svgContent);}-function returnAttachedImage(req: Request, res: Response) {+export function renderPngAttachment(image: BNote | BRevision, res: Response, attachmentName: string) {+ const attachment = image.getAttachmentByTitle(attachmentName);++ if (attachment) {+ res.set("Content-Type", "image/png");+ res.set("Cache-Control", "no-cache, no-store, must-revalidate");+ res.send(attachment.getContent());+ } else {+ res.sendStatus(404);+ }+}++function returnAttachedImage(req: Request<{ attachmentId: string }>, res: Response) {const attachment = becca.getAttachment(req.params.attachmentId);if (!attachment) {@@@ -88,10 -82,15 +94,15 @@@res.set("Content-Type", attachment.mime);res.set("Cache-Control", "no-cache, no-store, must-revalidate");- res.send(attachment.getContent());++ if (attachment.mime === "image/svg+xml") {+ sendSanitizedSvg(res, attachment.getContent());+ } else {+ res.send(attachment.getContent());+ }}-function updateImage(req: Request) {+function updateImage(req: Request<{ noteId: string }>) {const { noteId } = req.params;const { file } = req;diff --cc apps/server/src/share/routes.tsindex 69489c5522,41e57120c0..5b33103501--- a/apps/server/src/share/routes.ts+++ b/apps/server/src/share/routes.ts@@@ -1,25 -1,15 +1,24 @@@- import safeCompare from "safe-compare";-+import type { NextFunction, Request, Response, Router } from "express";+ import safeCompare from "safe-compare";-import type { Request, Response, Router } from "express";---import shaca from "./shaca/shaca.js";--import shacaLoader from "./shaca/shaca_loader.js";--import searchService from "../services/search/services/search.js";import SearchContext from "../services/search/search_context.js";--import type SNote from "./shaca/entities/snote.js";--import type SAttachment from "./shaca/entities/sattachment.js";-import { getDefaultTemplatePath, renderNoteContent } from "./content_renderer.js";++import searchService from "../services/search/services/search.js";+ import utils, { sanitizeSvg } from "../services/utils.js";+import { getDefaultTemplatePath, renderNoteContent } from "./content_renderer.js";- import utils from "../services/utils.js";++import type SAttachment from "./shaca/entities/sattachment.js";++import type SNote from "./shaca/entities/snote.js";++import shaca from "./shaca/shaca.js";++import shacaLoader from "./shaca/shaca_loader.js";+import { isShareDbReady } from "./sql.js";++function assertShareDbReady(_req: Request, res: Response, next: NextFunction) {+ if (!isShareDbReady()) {+ res.status(503).send("The application is still initializing. Please try again in a moment.");+ return;+ }++ next();+}function addNoIndexHeader(note: SNote, res: Response) {if (note.isLabelTruthy("shareDisallowRobotIndexing")) {@@@ -104,8 -94,8 +103,8 @@@ function renderImageAttachment(image: S&& possibleSvgContent !== null&& "svg" in possibleSvgContent&& typeof possibleSvgContent.svg === "string")-- ? possibleSvgContent.svg-- : null;++ ? possibleSvgContent.svg++ : null;if (contentSvg) {svgString = contentSvg;@@@ -320,7 -309,7 +320,7 @@@ function register(router: Router)return;}-- const searchContext = new SearchContext({ ancestorNoteId: ancestorNoteId });++ const searchContext = new SearchContext({ ancestorNoteId });const searchResults = searchService.findResultsWithQuery(search, searchContext);const filteredResults = searchResults.map((sr) => {const fullNote = shaca.notes[sr.noteId];diff --cc pnpm-lock.yamlindex e075d7fe45,87504dcfdf..305a045d8d--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@@ -448,10 -401,10 +448,10 @@@ importersdependencies:'@electron/remote':specifier: 2.1.3- version: 2.1.3([email protected])+ version: 2.1.3([email protected])better-sqlite3:- specifier: 12.6.2- version: 12.6.2+ specifier: 12.8.0+ version: 12.8.0electron-debug:specifier: 4.1.0version: 4.1.0@@@ -502,11 -461,11 +508,11 @@@specifier: 1.0.2version: 1.0.2copy-webpack-plugin:- specifier: 14.0.0- version: 14.0.0([email protected]([email protected]))+ specifier: 13.0.1- version: 13.0.1([email protected]([email protected]))++ version: 13.0.1([email protected]([email protected]))electron:- specifier: 41.1.0- version: 41.1.0+ specifier: 40.6.1+ version: 40.6.1prebuild-install:specifier: 7.1.3version: 7.1.3@@@ -7805,11 -7618,11 +7821,17 @@@ packagesresolution: {integrity: sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==}+ resolution: {integrity: sha512-J+YV3WfhY6W/Xf9h+J1znYuqTye2xkBUIGyTPWuBAT27qajBa5mR4f8WBmfDY3YjRftT2kqZZiLi1qf0H+UOFw==}+ engines: {node: '>= 18.12.0'}+ peerDependencies:- webpack: ^5.1.0++ webpack: '>=5.104.1'+++ resolution: {integrity: sha512-3JLW90aBGeaTLpM7mYQKpnVdgsUZRExY55giiZgLuX/xTQRUs1dOCwbBnWnvY6Q6rfZoXMNwzOQJCSZPppfqXA==}+ engines: {node: '>= 20.9.0'}+ peerDependencies:+ webpack: '>=5.104.1'resolution: {integrity: sha512-vDMm9B0xnqqZ8uSBpZ8sNtRtOdmfShrvT6h2TuQGLs0Is+cR0DYbj/KWP6ALVNbWPpqA/qPLoOuppJN07humpA==}@@@ -8490,11 -8424,11 +8512,16 @@@resolution: {integrity: sha512-bO3y10YikuUwUuDUQRM4KfwNkKhnpVO7IPdbsrejwN9/AABJzzTQ4GeHwyzNSrVO+tEH3/Np255a3sVZpZDjvg==}engines: {node: '>=8.0.0'}+ resolution: {integrity: sha512-u9YfoixttdauciHV9Ut9Zf3YipJoU093kR1GSYTTXTAXqhiXI0G1A0NnL/f0O2m2UULCXaXMf2W71PloR6V9pQ==}+ engines: {node: '>= 12.20.55'}+ hasBin: true++ resolution: {integrity: sha512-0XRFyxRqetmqtkkBvV++wGbHYJ7bD++f6EgJW8y9kX4pPRagwlmKDtzqXZhKiu0DIQppm3sXxzHWK9GYP91OKQ==}+ engines: {node: '>= 12.20.55'}+ hasBin: true+resolution: {integrity: sha512-f/ZeWvW/BCXbhGEf1Ujp29EASo/lk1FDnETgNKwJrsVvGZhUWCZyg3xLJjAsxfOmt8KjswHmI5EwCQcPMpOYhQ==}@@@ -16471,11 -17696,17 +16507,17 @@@ snapshotsdependencies:commander: 5.1.0glob: 7.2.3- minimatch: 3.1.2+ minimatch: 3.1.5+ '@electron/[email protected]':+ dependencies:+ chalk: 4.1.2+ fs-extra: 9.1.0+ minimist: 1.2.8+'@electron/[email protected]':dependencies:- debug: 4.4.3([email protected])+ debug: 4.4.3env-paths: 2.2.1fs-extra: 8.1.0got: 11.8.6@@@ -16598,10 -17829,10 +16640,14 @@@transitivePeerDependencies:- supports-color+ '@electron/[email protected]([email protected])':+ dependencies:+ electron: 40.6.1++ '@electron/[email protected]([email protected])':+ dependencies:+ electron: 41.1.0+'@electron/[email protected]':dependencies:'@electron/asar': 3.4.1@@@ -23286,7 -23548,7 +23332,16 @@@is-what: 3.14.1optional: true++ dependencies:++ glob-parent: 6.0.2++ normalize-path: 3.0.0++ schema-utils: 4.3.3++ serialize-javascript: 7.0.5++ tinyglobby: 0.2.15++ webpack: 5.105.4([email protected])++dependencies:glob-parent: 6.0.2normalize-path: 3.0.0@@@ -24075,10 -24504,10 +24130,18 @@@- supports-coloroptional: true+ dependencies:+ '@electron/get': 2.0.3- '@types/node': 24.10.13++ '@types/node': 24.12.0++ extract-zip: 2.0.1++ transitivePeerDependencies:++ - supports-color+++ dependencies:+ '@electron/get': 2.0.3+ '@types/node': 24.12.0extract-zip: 2.0.1transitivePeerDependencies:- supports-color