mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-17 07:49:08 +00:00
FIX: Create VPN using multipart form data to fetch file
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ async function bootstrap() {
|
||||
.addBearerAuth()
|
||||
.addServer(
|
||||
process.env.ENV === 'local'
|
||||
? 'http://127.0.0.1:3333'
|
||||
? 'http://localhost:3333'
|
||||
: 'https://maestro.dev.dadosfera.ai',
|
||||
)
|
||||
.build();
|
||||
|
||||
@@ -81,9 +81,18 @@ export class CreateNetworkConfigReq extends PickType(NetworkConfigDto, [
|
||||
'description',
|
||||
'type',
|
||||
'network_type_id',
|
||||
'plugin',
|
||||
]) {
|
||||
@ApiProperty()
|
||||
properties: NetworkConfigOpenVpnProperties;
|
||||
@ApiProperty({
|
||||
type: 'file',
|
||||
properties: {
|
||||
file: {
|
||||
type: 'string',
|
||||
format: 'binary',
|
||||
},
|
||||
},
|
||||
})
|
||||
OVPN_FILE: any;
|
||||
}
|
||||
export class CreateNetworkConfigRes {
|
||||
@ApiProperty()
|
||||
|
||||
@@ -9,10 +9,12 @@ import {
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { NetworkConfigService } from './network-config.service';
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { ApiConsumes, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||
import {
|
||||
CreateNetworkConfigReq,
|
||||
@@ -22,6 +24,7 @@ import {
|
||||
UpdateNetworkConfigReq,
|
||||
UpdateNetworkConfigRes,
|
||||
} from './dto/network-config';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
|
||||
@ApiTags('Network Config')
|
||||
@Controller('network-config')
|
||||
@@ -87,15 +90,18 @@ export class NetworkConfigController {
|
||||
|
||||
@Post()
|
||||
@ApiOkResponse({ type: CreateNetworkConfigRes })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FileInterceptor('OVPN_FILE'))
|
||||
async createNetworkConfigs(
|
||||
@User() user: RequestUser,
|
||||
@Body() body: CreateNetworkConfigReq,
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
) {
|
||||
this.logger.info('POST /network-config', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.createNetworkConfig(body, {
|
||||
return this.networkConfigService.createNetworkConfig(body, file, {
|
||||
customer_name: user.customer_name,
|
||||
customer_id: user.customer_id,
|
||||
});
|
||||
|
||||
@@ -88,9 +88,13 @@ export class NetworkConfigService {
|
||||
|
||||
async createNetworkConfig(
|
||||
body: CreateNetworkConfigReq,
|
||||
file: Express.Multer.File,
|
||||
{ customer_name, customer_id },
|
||||
): Promise<CreateNetworkConfigRes> {
|
||||
const { description, name, properties, type, network_type_id } = body;
|
||||
const { description, name, type, network_type_id, plugin } = body;
|
||||
|
||||
const OVPN_FILE_STRING = Buffer.from(file.buffer).toString();
|
||||
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', customer_id);
|
||||
meta.add('customer_name', customer_name);
|
||||
@@ -100,7 +104,10 @@ export class NetworkConfigService {
|
||||
customer_name,
|
||||
description,
|
||||
name,
|
||||
properties: JSON.stringify(properties),
|
||||
properties: JSON.stringify({
|
||||
OVPN_FILE: OVPN_FILE_STRING,
|
||||
plugin,
|
||||
}),
|
||||
type,
|
||||
network_type_id,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user