From 79756437652d26a41478181ef0d8e06d59197f67 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 17 Apr 2024 17:36:35 +0200 Subject: [PATCH] fix: absolute storage imports path. --- .env.example | 1 - .../server/src/api/controllers/Import/_utils.ts | 4 +++- .../server/src/services/Import/ImportFileUpload.ts | 2 -- packages/server/src/services/Import/_utils.ts | 14 +++++++++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 87ed7d2260..7621a6a096 100644 --- a/.env.example +++ b/.env.example @@ -96,7 +96,6 @@ PLAID_LINK_WEBHOOK= PLAID_SANDBOX_REDIRECT_URI= PLAID_DEVELOPMENT_REDIRECT_URI= - # https://docs.lemonsqueezy.com/guides/developer-guide/getting-started#create-an-api-key LEMONSQUEEZY_API_KEY= LEMONSQUEEZY_STORE_ID= diff --git a/packages/server/src/api/controllers/Import/_utils.ts b/packages/server/src/api/controllers/Import/_utils.ts index 3ad867941b..5629a55c6a 100644 --- a/packages/server/src/api/controllers/Import/_utils.ts +++ b/packages/server/src/api/controllers/Import/_utils.ts @@ -1,5 +1,6 @@ import Multer from 'multer'; import { ServiceError } from '@/exceptions'; +import { getImportsStoragePath } from '@/services/Import/_utils'; export function allowSheetExtensions(req, file, cb) { if ( @@ -16,7 +17,8 @@ export function allowSheetExtensions(req, file, cb) { const storage = Multer.diskStorage({ destination: function (req, file, cb) { - cb(null, './public/imports'); + const path = getImportsStoragePath(); + cb(null, path); }, filename: function (req, file, cb) { // Add the creation timestamp to clean up temp files later. diff --git a/packages/server/src/services/Import/ImportFileUpload.ts b/packages/server/src/services/Import/ImportFileUpload.ts index 9a1661ec99..bc7cb71635 100644 --- a/packages/server/src/services/Import/ImportFileUpload.ts +++ b/packages/server/src/services/Import/ImportFileUpload.ts @@ -38,8 +38,6 @@ export class ImportFileUploadService { filename: string, params: Record ): Promise { - console.log(filename, 'filename'); - try { return await this.importUnhandled( tenantId, diff --git a/packages/server/src/services/Import/_utils.ts b/packages/server/src/services/Import/_utils.ts index 8e1b5fe591..e99b8658bc 100644 --- a/packages/server/src/services/Import/_utils.ts +++ b/packages/server/src/services/Import/_utils.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import * as R from 'ramda'; import { Knex } from 'knex'; import fs from 'fs/promises'; +import path from 'path'; import { defaultTo, upperFirst, @@ -353,7 +354,6 @@ export const parseKey = R.curry( _key = `${fieldKey}`; } } - console.log(_key); return _key; } ); @@ -432,13 +432,19 @@ export const sanitizeSheetData = (json) => { export const getMapToPath = (to: string, group = '') => group ? `${group}.${to}` : to; +export const getImportsStoragePath = () => { + return path.join(global.__storage_dir, `/imports`); +} + /** * Deletes the imported file from the storage and database. * @param {string} filename */ export const deleteImportFile = async (filename: string) => { + const filePath = getImportsStoragePath(); + // Deletes the imported file. - await fs.unlink(`public/imports/${filename}`); + await fs.unlink(`${filePath}/${filename}`); }; /** @@ -447,5 +453,7 @@ export const deleteImportFile = async (filename: string) => { * @returns {Promise} */ export const readImportFile = (filename: string) => { - return fs.readFile(`public/imports/${filename}`); + const filePath = getImportsStoragePath(); + + return fs.readFile(`${filePath}/${filename}`); };