Browse Source

fix: avoid using existsSync

pull/9555/head
mertmit 3 months ago
parent
commit
2c5558ab3b
  1. 3
      packages/nocodb/src/controllers/attachments-secure.controller.ts
  2. 8
      packages/nocodb/src/controllers/attachments.controller.ts
  3. 5
      packages/nocodb/src/helpers/attachmentHelpers.ts

3
packages/nocodb/src/controllers/attachments-secure.controller.ts

@ -29,6 +29,7 @@ import { DataApiLimiterGuard } from '~/guards/data-api-limiter.guard';
import { TenantContext } from '~/decorators/tenant-context.decorator';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { NcError } from '~/helpers/catchError';
import { fileExists } from '~/helpers/attachmentHelpers'
@Controller()
export class AttachmentsSecureController {
@ -95,7 +96,7 @@ export class AttachmentsSecureController {
path: path.join('nc', filePath, fpath),
});
if (!fs.existsSync(file.path)) {
if (!(await fileExists(file.path))) {
return res.status(404).send('File not found');
}

8
packages/nocodb/src/controllers/attachments.controller.ts

@ -24,7 +24,7 @@ import { AttachmentsService } from '~/services/attachments.service';
import { PresignedUrl } from '~/models';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcContext, NcRequest } from '~/interface/config';
import { isPreviewAllowed } from '~/helpers/attachmentHelpers';
import { isPreviewAllowed, fileExists } from '~/helpers/attachmentHelpers';
import { DataTableService } from '~/services/data-table.service';
import { TenantContext } from '~/decorators/tenant-context.decorator';
import { DataApiLimiterGuard } from '~/guards/data-api-limiter.guard';
@ -85,7 +85,7 @@ export class AttachmentsController {
path: path.join('nc', 'uploads', filename),
});
if (!fs.existsSync(file.path)) {
if (!await fs.promises.stat(file.path)) {
return res.status(404).send('File not found');
}
@ -126,7 +126,7 @@ export class AttachmentsController {
),
});
if (!fs.existsSync(file.path)) {
if (!(await fileExists(file.path))) {
return res.status(404).send('File not found');
}
@ -172,7 +172,7 @@ export class AttachmentsController {
path: path.join('nc', filePath, fpath),
});
if (!fs.existsSync(file.path)) {
if (!(await fileExists(file.path))) {
return res.status(404).send('File not found');
}

5
packages/nocodb/src/helpers/attachmentHelpers.ts

@ -1,4 +1,5 @@
import path from 'path';
import fs from 'fs';
import mime from 'mime/lite';
import slash from 'slash';
import { getToolDir } from '~/utils/nc-config';
@ -64,3 +65,7 @@ export function getPathFromUrl(url: string, removePrefix = false) {
return decodeURI(`${pathName}${newUrl.search}${newUrl.hash}`);
}
export const fileExists = (path: string) => {
return fs.promises.access(path).then(() => true).catch(() => false);
}

Loading…
Cancel
Save