Browse Source

fix: PR requested change & refactor helper name

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

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

@ -1,5 +1,4 @@
import path from 'path';
import fs from 'fs';
import {
Body,
Controller,
@ -29,7 +28,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'
import { localFileExists } from '~/helpers/attachmentHelpers';
@Controller()
export class AttachmentsSecureController {
@ -96,7 +95,7 @@ export class AttachmentsSecureController {
path: path.join('nc', filePath, fpath),
});
if (!(await fileExists(file.path))) {
if (!(await localFileExists(file.path))) {
return res.status(404).send('File not found');
}

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

@ -1,5 +1,4 @@
import path from 'path';
import fs from 'fs';
import {
Body,
Controller,
@ -24,7 +23,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, fileExists } from '~/helpers/attachmentHelpers';
import { isPreviewAllowed, localFileExists } 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 +84,7 @@ export class AttachmentsController {
path: path.join('nc', 'uploads', filename),
});
if (!await fs.promises.stat(file.path)) {
if (!(await localFileExists(file.path))) {
return res.status(404).send('File not found');
}
@ -126,7 +125,7 @@ export class AttachmentsController {
),
});
if (!(await fileExists(file.path))) {
if (!(await localFileExists(file.path))) {
return res.status(404).send('File not found');
}
@ -172,7 +171,7 @@ export class AttachmentsController {
path: path.join('nc', filePath, fpath),
});
if (!(await fileExists(file.path))) {
if (!(await localFileExists(file.path))) {
return res.status(404).send('File not found');
}

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

@ -66,6 +66,9 @@ 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);
}
export const localFileExists = (path: string) => {
return fs.promises
.access(path)
.then(() => true)
.catch(() => false);
};

Loading…
Cancel
Save