Skip to content

Commit

Permalink
feat(nestjs-tools-file-storage): resolve boolean for fileExists
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Jul 12, 2024
1 parent bec11ec commit 6bad25f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/file-storage/src/lib/file-storage-fs.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class FileStorageLocal implements FileStorage {
async fileExists(args: FileStorageLocalFileExists): Promise<boolean> {
const { filePath, options = {}, request } = args;
const fileName = await this.transformFilePath(filePath, MethodTypes.READ, request, options);
return new Promise<boolean>((resolve, reject) => stat(fileName, (err) => (err ? reject(err) : resolve(true))));
return new Promise<boolean>((resolve) => stat(fileName, (err) => (err ? resolve(false) : resolve(true))));
}

async uploadFile(args: FileStorageLocalUploadFile): Promise<void> {
Expand Down
8 changes: 6 additions & 2 deletions packages/file-storage/src/lib/file-storage-s3.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ export class FileStorageS3 implements FileStorage {
const { filePath, options = {}, request } = args;
const { s3, bucket: Bucket } = this.config;
const Key = await this.transformFilePath(filePath, MethodTypes.READ, request, options);
await s3.headObject({ ...options, Key, Bucket });
return true;
try {
await s3.headObject({ ...options, Key, Bucket });
return true;
} catch (e) {
return false;
}
}

async uploadFile(args: FileStorageS3UploadFile): Promise<void> {
Expand Down

0 comments on commit 6bad25f

Please sign in to comment.