Skip to content
Snippets Groups Projects
Commit 373c833a authored by timothycarambat's avatar timothycarambat
Browse files

path API document mgmt with STORAGE_DIR

parent 22ef2c28
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,10 @@ const { handleUploads } = setupMulter(); ...@@ -13,6 +13,10 @@ const { handleUploads } = setupMulter();
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const { Document } = require("../../../models/documents"); const { Document } = require("../../../models/documents");
const documentsPath =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, "../../../storage/documents")
: path.resolve(process.env.STORAGE_DIR, `documents`);
function apiDocumentEndpoints(app) { function apiDocumentEndpoints(app) {
if (!app) return; if (!app) return;
...@@ -600,11 +604,7 @@ function apiDocumentEndpoints(app) { ...@@ -600,11 +604,7 @@ function apiDocumentEndpoints(app) {
*/ */
try { try {
const { name } = reqBody(request); const { name } = reqBody(request);
const storagePath = path.join( const storagePath = path.join(documentsPath, normalizePath(name));
__dirname,
"../../../storage/documents",
normalizePath(name)
);
if (fs.existsSync(storagePath)) { if (fs.existsSync(storagePath)) {
response.status(500).json({ response.status(500).json({
...@@ -681,16 +681,8 @@ function apiDocumentEndpoints(app) { ...@@ -681,16 +681,8 @@ function apiDocumentEndpoints(app) {
({ from }) => !embeddedFiles.includes(from) ({ from }) => !embeddedFiles.includes(from)
); );
const movePromises = moveableFiles.map(({ from, to }) => { const movePromises = moveableFiles.map(({ from, to }) => {
const sourcePath = path.join( const sourcePath = path.join(documentsPath, normalizePath(from));
__dirname, const destinationPath = path.join(documentsPath, normalizePath(to));
"../../../storage/documents",
normalizePath(from)
);
const destinationPath = path.join(
__dirname,
"../../../storage/documents",
normalizePath(to)
);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.rename(sourcePath, destinationPath, (err) => { fs.rename(sourcePath, destinationPath, (err) => {
if (err) { if (err) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment