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
feat(server): use custom temporary directory within trilium-data
Elian Doran0f28bbb1be95
diff --git a/src/routes/api/files.ts b/src/routes/api/files.tsindex b212f2b552..7ec05dc6a4 100644--- a/src/routes/api/files.ts+++ b/src/routes/api/files.ts@@ -14,6 +14,7 @@ import ValidationError from "../../errors/validation_error.js";import type { Request, Response } from "express";import type BNote from "../../becca/entities/bnote.js";import type BAttachment from "../../becca/entities/battachment.js";+import dataDirs from "../../services/data_dir.js";function updateFile(req: Request) {const note = becca.getNoteOrThrow(req.params.noteId);@@ -167,7 +168,10 @@ function saveAttachmentToTmpDir(req: Request) {const createdTemporaryFiles = new Set<string>();function saveToTmpDir(fileName: string, content: string | Buffer, entityType: string, entityId: string) {- const tmpObj = tmp.fileSync({ postfix: fileName });+ const tmpObj = tmp.fileSync({+ postfix: fileName,+ tmpdir: dataDirs.TMP_DIR+ });if (typeof content === "string") {fs.writeSync(tmpObj.fd, content);diff --git a/src/services/data_dir.ts b/src/services/data_dir.tsindex 2e0c2f522e..4f277736bd 100644--- a/src/services/data_dir.ts+++ b/src/services/data_dir.ts@@ -47,10 +47,13 @@ export function getDataDirs(TRILIUM_DATA_DIR: string) {DOCUMENT_PATH: process.env.TRILIUM_DOCUMENT_PATH || pathJoin(TRILIUM_DATA_DIR, "document.db"),BACKUP_DIR: process.env.TRILIUM_BACKUP_DIR || pathJoin(TRILIUM_DATA_DIR, "backup"),LOG_DIR: process.env.TRILIUM_LOG_DIR || pathJoin(TRILIUM_DATA_DIR, "log"),+ TMP_DIR: process.env.TRILIUM_TMP_DIR || pathJoin(TRILIUM_DATA_DIR, "tmp"),ANONYMIZED_DB_DIR: process.env.TRILIUM_ANONYMIZED_DB_DIR || pathJoin(TRILIUM_DATA_DIR, "anonymized-db"),CONFIG_INI_PATH: process.env.TRILIUM_CONFIG_INI_PATH || pathJoin(TRILIUM_DATA_DIR, "config.ini")} as const;+ createDirIfNotExisting(dataDirs.TMP_DIR);+Object.freeze(dataDirs);return dataDirs;}