mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-15 10:59:08 +00:00
FEAT: upload 50MB file
This commit is contained in:
+26
-2
@@ -2381,6 +2381,30 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pipelinesV2/upload": {
|
||||
"post": {
|
||||
"operationId": "PipelinesController_uploadFile",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"PipelinesV2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/inputs/available-entities/{plugin}": {
|
||||
"get": {
|
||||
"operationId": "InputsController_getAvailableEntities",
|
||||
@@ -3233,9 +3257,9 @@
|
||||
}
|
||||
},
|
||||
"info": {
|
||||
"title": "Maestro - main",
|
||||
"title": "Maestro - feat/upload-csv",
|
||||
"description": "Documentation for Maestro gateway",
|
||||
"version": "1.12.2022 - 14:46",
|
||||
"version": "1.0.0",
|
||||
"contact": {}
|
||||
},
|
||||
"tags": [],
|
||||
|
||||
@@ -16,10 +16,10 @@ export class PipelinesClientConfiguration {
|
||||
options: {
|
||||
url: process.env.PIFACTORY_URL,
|
||||
package: [ProtoPackages.ReadPackage, ProtoPackages.WritePackage],
|
||||
credentials:
|
||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
||||
? undefined
|
||||
: credentials.createSsl(),
|
||||
// credentials:
|
||||
// process.env.LOCAL_ENV || process.env.ENV === 'local'
|
||||
// ? undefined
|
||||
// : credentials.createSsl(),
|
||||
protoPath: [ProtoPaths.ReadFilePath, ProtoPaths.WriteFilePath],
|
||||
loader: {
|
||||
keepCase: true,
|
||||
|
||||
@@ -13,13 +13,19 @@ import {
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Patch,
|
||||
UseInterceptors,
|
||||
UploadedFiles,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ApiConsumes,
|
||||
ApiCreatedResponse,
|
||||
ApiNoContentResponse,
|
||||
ApiTags,
|
||||
} from '@nestjs/swagger';
|
||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
||||
import {
|
||||
AuthenticateCondition,
|
||||
RequireAllPermissions,
|
||||
} from 'src/authentication/authentication.decorator';
|
||||
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||
import { PipelinesService } from './pipelines.service';
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
@@ -30,6 +36,7 @@ import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||
import { PipelinesService as OldPipelineService } from 'src/modules/pipelines/pipelines.service';
|
||||
import { ICreatePipelineV2Req, IPipelineV2 } from './interfaces';
|
||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||
import { FilesInterceptor } from '@nestjs/platform-express';
|
||||
|
||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||
@ApiTags('PipelinesV2')
|
||||
@@ -240,4 +247,25 @@ export class PipelinesController {
|
||||
await this.pipelinesClientService.remove({ id, metadata, user });
|
||||
this.logger.info('PipelinesController - delete: OK');
|
||||
}
|
||||
|
||||
@Post('/upload')
|
||||
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE)
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FilesInterceptor('file'))
|
||||
async uploadFile(@User() user: RequestUser, @UploadedFiles() files) {
|
||||
this.logger.info('/upload - Upload Connector Route');
|
||||
const metadata = PackTheMetadata({ ...user });
|
||||
const promises = files.map(async (file) => {
|
||||
return await this.pipelinesClientService.uploadFile(
|
||||
{
|
||||
file,
|
||||
name: file.originalname.split('.')[0],
|
||||
},
|
||||
metadata,
|
||||
);
|
||||
});
|
||||
|
||||
const response = await Promise.all(promises);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
InternalServerErrorException,
|
||||
OnModuleInit,
|
||||
@@ -238,4 +240,23 @@ export class PipelinesService implements OnModuleInit {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async uploadFile(uploadFile, metadata) {
|
||||
const body: Messages.PipelineV2UploadFileRequest = {
|
||||
file: {
|
||||
buffer: uploadFile.file.buffer,
|
||||
mimetypes: uploadFile.file.mimetype,
|
||||
},
|
||||
name: uploadFile.name,
|
||||
};
|
||||
|
||||
return lastValueFrom(
|
||||
this.pipelineWriteService.PipelineV2UploadFile(body, metadata),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user