Skip to content

Commit

Permalink
Merge pull request #91 from getlarge/fix-update-invalid-paths-default…
Browse files Browse the repository at this point in the history
…-fs-factory

fix(nestjs-tools-file-storage): improve directory handling in write method
  • Loading branch information
getlarge authored Sep 13, 2024
2 parents bfcd277 + 1659eca commit 3ba2fcf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/file-storage/src/lib/file-storage-fs.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
unlink,
} from 'node:fs';
import { access, mkdir, readdir, readFile, rename, rm, stat as statPromise, writeFile } from 'node:fs/promises';
import { normalize, resolve as resolvePath, sep } from 'node:path';
import { dirname, normalize, resolve as resolvePath, sep } from 'node:path';
import { finished, Readable } from 'node:stream';

import type { FileStorage } from './file-storage.class';
Expand Down Expand Up @@ -41,10 +41,13 @@ function config(setup: FileStorageLocalSetup) {
}

if (methodType === MethodTypes.WRITE) {
const storageExists = await access(storagePath).catch(() => false);
!storageExists && (await mkdir(storagePath, { recursive: true }));
const storageDir = dirname(fullPath);
const storageExists = await access(storageDir)
.then(() => true)
.catch(() => false);
!storageExists && (await mkdir(storageDir, { recursive: true }));
}
return Promise.resolve(resolvePath(storagePath, fileName));
return Promise.resolve(fullPath);
};
const limits = { fileSize: maxPayloadSize * 1024 * 1024 };
return { filePath, limits };
Expand Down

0 comments on commit 3ba2fcf

Please sign in to comment.