|
|
@ -14,6 +14,8 @@ import { |
|
|
|
UseInterceptors, |
|
|
|
UseInterceptors, |
|
|
|
} from '@nestjs/common'; |
|
|
|
} from '@nestjs/common'; |
|
|
|
import { AnyFilesInterceptor } from '@nestjs/platform-express'; |
|
|
|
import { AnyFilesInterceptor } from '@nestjs/platform-express'; |
|
|
|
|
|
|
|
import { Request as RequestType, Response as ResponseType } from 'express'; |
|
|
|
|
|
|
|
import type { AttachmentReqType, FileType } from 'nocodb-sdk'; |
|
|
|
import { UploadAllowedInterceptor } from '~/interceptors/is-upload-allowed/is-upload-allowed.interceptor'; |
|
|
|
import { UploadAllowedInterceptor } from '~/interceptors/is-upload-allowed/is-upload-allowed.interceptor'; |
|
|
|
import { GlobalGuard } from '~/guards/global/global.guard'; |
|
|
|
import { GlobalGuard } from '~/guards/global/global.guard'; |
|
|
|
import { AttachmentsService } from '~/services/attachments.service'; |
|
|
|
import { AttachmentsService } from '~/services/attachments.service'; |
|
|
@ -29,13 +31,12 @@ export class AttachmentsController { |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
@UseInterceptors(UploadAllowedInterceptor, AnyFilesInterceptor()) |
|
|
|
@UseInterceptors(UploadAllowedInterceptor, AnyFilesInterceptor()) |
|
|
|
async upload( |
|
|
|
async upload( |
|
|
|
@UploadedFiles() files: Array<any>, |
|
|
|
@UploadedFiles() files: Array<FileType>, |
|
|
|
@Body() body: any, |
|
|
|
@Request() req: RequestType, |
|
|
|
@Request() req: any, |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
const attachments = await this.attachmentsService.upload({ |
|
|
|
const attachments = await this.attachmentsService.upload({ |
|
|
|
files: files, |
|
|
|
files: files, |
|
|
|
path: req.query?.path as string, |
|
|
|
path: req.query?.path?.toString(), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return attachments; |
|
|
|
return attachments; |
|
|
@ -45,7 +46,10 @@ export class AttachmentsController { |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
@UseInterceptors(UploadAllowedInterceptor) |
|
|
|
@UseInterceptors(UploadAllowedInterceptor) |
|
|
|
@UseGuards(MetaApiLimiterGuard, GlobalGuard) |
|
|
|
@UseGuards(MetaApiLimiterGuard, GlobalGuard) |
|
|
|
async uploadViaURL(@Body() body: any, @Query('path') path: string) { |
|
|
|
async uploadViaURL( |
|
|
|
|
|
|
|
@Body() body: Array<AttachmentReqType>, |
|
|
|
|
|
|
|
@Query('path') path: string, |
|
|
|
|
|
|
|
) { |
|
|
|
const attachments = await this.attachmentsService.uploadViaURL({ |
|
|
|
const attachments = await this.attachmentsService.uploadViaURL({ |
|
|
|
urls: body, |
|
|
|
urls: body, |
|
|
|
path, |
|
|
|
path, |
|
|
@ -58,7 +62,10 @@ export class AttachmentsController { |
|
|
|
// , getCacheMiddleware(), catchError(fileRead));
|
|
|
|
// , getCacheMiddleware(), catchError(fileRead));
|
|
|
|
@Get('/download/:filename(*)') |
|
|
|
@Get('/download/:filename(*)') |
|
|
|
// This route will match any URL that starts with
|
|
|
|
// This route will match any URL that starts with
|
|
|
|
async fileRead(@Param('filename') filename: string, @Response() res) { |
|
|
|
async fileRead( |
|
|
|
|
|
|
|
@Param('filename') filename: string, |
|
|
|
|
|
|
|
@Response() res: ResponseType, |
|
|
|
|
|
|
|
) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const file = await this.attachmentsService.getFile({ |
|
|
|
const file = await this.attachmentsService.getFile({ |
|
|
|
path: path.join('nc', 'uploads', filename), |
|
|
|
path: path.join('nc', 'uploads', filename), |
|
|
@ -77,7 +84,7 @@ export class AttachmentsController { |
|
|
|
@Param('param1') param1: string, |
|
|
|
@Param('param1') param1: string, |
|
|
|
@Param('param2') param2: string, |
|
|
|
@Param('param2') param2: string, |
|
|
|
@Param('filename') filename: string, |
|
|
|
@Param('filename') filename: string, |
|
|
|
@Response() res, |
|
|
|
@Response() res: ResponseType, |
|
|
|
) { |
|
|
|
) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const file = await this.attachmentsService.getFile({ |
|
|
|
const file = await this.attachmentsService.getFile({ |
|
|
@ -97,7 +104,10 @@ export class AttachmentsController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Get('/dltemp/:param(*)') |
|
|
|
@Get('/dltemp/:param(*)') |
|
|
|
async fileReadv3(@Param('param') param: string, @Response() res) { |
|
|
|
async fileReadv3( |
|
|
|
|
|
|
|
@Param('param') param: string, |
|
|
|
|
|
|
|
@Response() res: ResponseType, |
|
|
|
|
|
|
|
) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const fpath = await PresignedUrl.getPath(`dltemp/${param}`); |
|
|
|
const fpath = await PresignedUrl.getPath(`dltemp/${param}`); |
|
|
|
|
|
|
|
|
|
|
|