From 22ef2c287dce41190148370a1ec9e36c5aae518e Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Thu, 21 Mar 2024 15:03:52 -0700 Subject: [PATCH] folder mgmt, use STORAGE_DIR --- server/endpoints/document.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/server/endpoints/document.js b/server/endpoints/document.js index 4ed5ae07..7d65b551 100644 --- a/server/endpoints/document.js +++ b/server/endpoints/document.js @@ -1,5 +1,5 @@ const { Document } = require("../models/documents"); -const { normalizePath } = require("../utils/files"); +const { normalizePath, documentsPath } = require("../utils/files"); const { reqBody } = require("../utils/http"); const { flexUserRoleValid, @@ -17,11 +17,7 @@ function documentEndpoints(app) { async (request, response) => { try { const { name } = reqBody(request); - const storagePath = path.join( - __dirname, - "../storage/documents", - normalizePath(name) - ); + const storagePath = path.join(documentsPath, normalizePath(name)); if (fs.existsSync(storagePath)) { response.status(500).json({ @@ -58,16 +54,8 @@ function documentEndpoints(app) { ); const movePromises = moveableFiles.map(({ from, to }) => { - const sourcePath = path.join( - __dirname, - "../storage/documents", - normalizePath(from) - ); - const destinationPath = path.join( - __dirname, - "../storage/documents", - normalizePath(to) - ); + const sourcePath = path.join(documentsPath, normalizePath(from)); + const destinationPath = path.join(documentsPath, normalizePath(to)); return new Promise((resolve, reject) => { fs.rename(sourcePath, destinationPath, (err) => {