Browse Source

refactor: move multer config to module

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
0f23180e02
  1. 35
      packages/nocodb-nest/src/modules/attachments/attachments.controller.ts
  2. 11
      packages/nocodb-nest/src/modules/attachments/attachments.module.ts
  3. 1
      packages/nocodb-nest/src/modules/hooks/hooks.controller.ts
  4. 18
      packages/nocodb-nest/src/modules/public-datas/public-datas.controller.ts
  5. 2
      packages/nocodb-nest/src/modules/public-datas/public-datas.module.ts

35
packages/nocodb-nest/src/modules/attachments/attachments.controller.ts

@ -13,10 +13,7 @@ import {
UseGuards, UseGuards,
UseInterceptors, UseInterceptors,
} from '@nestjs/common'; } from '@nestjs/common';
import multer from 'multer';
import { AnyFilesInterceptor } from '@nestjs/platform-express'; import { AnyFilesInterceptor } from '@nestjs/platform-express';
import { AuthGuard } from '@nestjs/passport';
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants';
import { GlobalGuard } from '../../guards/global/global.guard'; import { GlobalGuard } from '../../guards/global/global.guard';
import { UploadAllowedInterceptor } from '../../interceptors/is-upload-allowed/is-upload-allowed.interceptor'; import { UploadAllowedInterceptor } from '../../interceptors/is-upload-allowed/is-upload-allowed.interceptor';
import { AttachmentsService } from './attachments.service'; import { AttachmentsService } from './attachments.service';
@ -26,31 +23,9 @@ export class AttachmentsController {
constructor(private readonly attachmentsService: AttachmentsService) {} constructor(private readonly attachmentsService: AttachmentsService) {}
@UseGuards(GlobalGuard) @UseGuards(GlobalGuard)
@Post( @Post('/api/v1/db/storage/upload')
'/api/v1/db/storage/upload',
// multer({
// storage: multer.diskStorage({}),
// limits: {
// fieldSize: NC_ATTACHMENT_FIELD_SIZE,
// },
// }).any(),
// [
// extractProjectIdAndAuthenticate,
// catchError(isUploadAllowedMw),
// catchError(upload),
// ]
// );
)
@HttpCode(200) @HttpCode(200)
@UseInterceptors( @UseInterceptors(UploadAllowedInterceptor, AnyFilesInterceptor())
UploadAllowedInterceptor,
AnyFilesInterceptor({
storage: multer.diskStorage({}),
limits: {
fieldSize: NC_ATTACHMENT_FIELD_SIZE,
},
}),
)
async upload( async upload(
@UploadedFiles() files: Array<any>, @UploadedFiles() files: Array<any>,
@Body() body: any, @Body() body: any,
@ -68,12 +43,6 @@ export class AttachmentsController {
@Post('/api/v1/db/storage/upload-by-url') @Post('/api/v1/db/storage/upload-by-url')
@HttpCode(200) @HttpCode(200)
@UseInterceptors(UploadAllowedInterceptor) @UseInterceptors(UploadAllowedInterceptor)
// [
// extractProjectIdAndAuthenticate,
// catchError(isUploadAllowedMw),
// catchError(uploadViaURL),
// ]
// );
@UseGuards(GlobalGuard) @UseGuards(GlobalGuard)
async uploadViaURL(@Body() body: any, @Query('path') path: string) { async uploadViaURL(@Body() body: any, @Query('path') path: string) {
const attachments = await this.attachmentsService.uploadViaURL({ const attachments = await this.attachmentsService.uploadViaURL({

11
packages/nocodb-nest/src/modules/attachments/attachments.module.ts

@ -1,8 +1,19 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { MulterModule } from '@nestjs/platform-express';
import multer from 'multer';
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants';
import { AttachmentsService } from './attachments.service'; import { AttachmentsService } from './attachments.service';
import { AttachmentsController } from './attachments.controller'; import { AttachmentsController } from './attachments.controller';
@Module({ @Module({
imports: [
MulterModule.register({
storage: multer.diskStorage({}),
limits: {
fieldSize: NC_ATTACHMENT_FIELD_SIZE,
},
}),
],
controllers: [AttachmentsController], controllers: [AttachmentsController],
providers: [AttachmentsService], providers: [AttachmentsService],
}) })

1
packages/nocodb-nest/src/modules/hooks/hooks.controller.ts

@ -11,7 +11,6 @@ import {
UseGuards, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common';
import { HookReqType, HookTestReqType } from 'nocodb-sdk'; import { HookReqType, HookTestReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import { GlobalGuard } from '../../guards/global/global.guard'; import { GlobalGuard } from '../../guards/global/global.guard';
import { PagedResponseImpl } from '../../helpers/PagedResponse'; import { PagedResponseImpl } from '../../helpers/PagedResponse';
import { import {

18
packages/nocodb-nest/src/modules/public-datas/public-datas.controller.ts

@ -45,15 +45,21 @@ export class PublicDatasController {
return groupedData; return groupedData;
} }
// todo: multer
// router.post(
// '/api/v1/db/public/shared-view/:sharedViewUuid/rows',
// multer({
// storage: multer.diskStorage({}),
// limits: {
// fieldSize: NC_ATTACHMENT_FIELD_SIZE,
// },
// }).any(),
// catchError(dataInsert)
// );
@Post('/api/v1/db/public/shared-view/:sharedViewUuid/rows') @Post('/api/v1/db/public/shared-view/:sharedViewUuid/rows')
@HttpCode(200) @HttpCode(200)
@UseInterceptors( @UseInterceptors(
AnyFilesInterceptor({ AnyFilesInterceptor(),
storage: multer.diskStorage({}),
limits: {
fieldSize: NC_ATTACHMENT_FIELD_SIZE,
},
}),
) )
async dataInsert( async dataInsert(
@Request() req, @Request() req,

2
packages/nocodb-nest/src/modules/public-datas/public-datas.module.ts

@ -10,7 +10,7 @@ import { PublicDatasController } from './public-datas.controller';
MulterModule.register({ MulterModule.register({
storage: multer.diskStorage({}), storage: multer.diskStorage({}),
limits: { limits: {
fileSize: NC_ATTACHMENT_FIELD_SIZE, fieldSize: NC_ATTACHMENT_FIELD_SIZE,
}, },
}), }),
], ],

Loading…
Cancel
Save