Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: absolute storage imports path. #408

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/api/controllers/Import/_utils.ts
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/services/Import/ImportFileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class ImportFileUploadService {
filename: string,
params: Record<string, number | string>
): Promise<ImportFileUploadPOJO> {
console.log(filename, 'filename');

try {
return await this.importUnhandled(
tenantId,
Expand Down
14 changes: 11 additions & 3 deletions packages/server/src/services/Import/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -353,7 +354,6 @@ export const parseKey = R.curry(
_key = `${fieldKey}`;
}
}
console.log(_key);
return _key;
}
);
Expand Down Expand Up @@ -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}`);
};

/**
Expand All @@ -447,5 +453,7 @@ export const deleteImportFile = async (filename: string) => {
* @returns {Promise<Buffer>}
*/
export const readImportFile = (filename: string) => {
return fs.readFile(`public/imports/${filename}`);
const filePath = getImportsStoragePath();

return fs.readFile(`${filePath}/${filename}`);
};
Loading