mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 02:52:27 +08:00
feat(server): use custom temporary directory within trilium-data
This commit is contained in:
parent
45b7d51db9
commit
0f28bbb1be
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user