mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-01 12:18:15 +00:00
Compare commits
33
Commits
+9
-5
@@ -5619,6 +5619,9 @@
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"themeEnabled": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -5627,7 +5630,8 @@
|
||||
"name",
|
||||
"tier",
|
||||
"scheduleLimit",
|
||||
"links"
|
||||
"links",
|
||||
"themeEnabled"
|
||||
]
|
||||
},
|
||||
"AuthUser": {
|
||||
@@ -8374,18 +8378,18 @@
|
||||
"textColor": {
|
||||
"type": "string"
|
||||
},
|
||||
"logoWhite": {
|
||||
"logo": {
|
||||
"type": "string"
|
||||
},
|
||||
"logoBlack": {
|
||||
"logoLogin": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"backgroundColor",
|
||||
"textColor",
|
||||
"logoWhite",
|
||||
"logoBlack"
|
||||
"logo",
|
||||
"logoLogin"
|
||||
]
|
||||
},
|
||||
"CustomerThemeResponse": {
|
||||
|
||||
@@ -95,6 +95,10 @@ spec:
|
||||
value: {{ .Values.maestro.tr_factory_url }}
|
||||
- name: UPLOAD_FILE_AGENT_CONNECTION
|
||||
value: {{ .Values.maestro.upload_file_agent_connection }}
|
||||
- name: OPEN_CUSTOMER_ID
|
||||
value: {{ .Values.maestro.open_customer_id }}
|
||||
- name: OPEN_GROUP_ID
|
||||
value: {{ .Values.maestro.open_group_id }}
|
||||
- name: JWT_PRIVATE_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
||||
Generated
+4
-4
@@ -12,7 +12,7 @@
|
||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||
"@dadosfera/protospack": "2.5.3",
|
||||
"@dadosfera/protospack-v2": "3.37.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "3.37.0-beta.5",
|
||||
"@grpc/grpc-js": "^1.9.3",
|
||||
"@grpc/proto-loader": "^0.7.9",
|
||||
"@nestjs/cli": "^9.5.0",
|
||||
@@ -1403,9 +1403,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@dadosfera/protospack-v2": {
|
||||
"version": "3.37.0-beta.3",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.37.0-beta.3.tgz",
|
||||
"integrity": "sha512-9YSgzkXVqe9QsBxJjfxYxttAiyCXxgq49Xjs3OvnTLCXRDn3XtTlPaC+yHrTEUgCkQyhlDZuswe6f6oBImqIRQ==",
|
||||
"version": "3.37.0-beta.5",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.37.0-beta.5.tgz",
|
||||
"integrity": "sha512-dtHMzMU2Qa9c6DpygWr7fib19l1zqbYgBi2wGkiJ6uMAvl1CGu9V0p+JA1FwGTQ0QRy7EkkRVi6X6sH5u/ICpA==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.9.3",
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||
"@dadosfera/protospack": "2.5.3",
|
||||
"@dadosfera/protospack-v2": "3.37.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "3.37.0-beta.5",
|
||||
"@grpc/grpc-js": "^1.9.3",
|
||||
"@grpc/proto-loader": "^0.7.9",
|
||||
"@nestjs/cli": "^9.5.0",
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import { Injectable, CanActivate, ExecutionContext, ForbiddenException } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
|
||||
export const SetOrigin = (origin: string) => SetMetadata('allowedOrigin', origin);
|
||||
|
||||
@Injectable()
|
||||
export class CORSGuard implements CanActivate {
|
||||
constructor(private reflector: Reflector) {}
|
||||
|
||||
canActivate(context: ExecutionContext): boolean {
|
||||
const response = context.switchToHttp().getResponse();
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const origin = request.headers.origin;
|
||||
|
||||
// Obter a origem permitida através do decorador
|
||||
const allowedOrigin = this.reflector.get<string>('allowedOrigin', context.getHandler());
|
||||
if (process.env.ENV === "local") {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Verifica se a origem da requisição é permitida
|
||||
if (allowedOrigin && origin !== allowedOrigin) {
|
||||
throw new ForbiddenException('Acesso não permitido pela política CORS');
|
||||
}
|
||||
|
||||
response.setHeader('Access-Control-Allow-Origin', allowedOrigin);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ export class AuthCustomer {
|
||||
scheduleLimit: string;
|
||||
@ApiProperty()
|
||||
links: Link[];
|
||||
@ApiProperty()
|
||||
themeEnabled: boolean;
|
||||
}
|
||||
|
||||
export class AuthSignInReq implements AuthSignInRequest {
|
||||
|
||||
@@ -145,7 +145,7 @@ export class CustomersService implements OnModuleInit {
|
||||
const res = await lastValueFrom(
|
||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||
{
|
||||
dashboard_id: '45',
|
||||
dashboard_id: '98',
|
||||
exp: '15m',
|
||||
metabase_customer_name: 'dadosferatech',
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||
import { Body, Controller, Header, HttpCode, Inject, Param, Post, Query, Req, UseFilters, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, ForbiddenException, Header, HttpCode, Inject, Param, Post, Query, Req, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
import { ApiCreatedResponse, ApiHeaders, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||
@@ -8,7 +8,6 @@ import { UsersService } from '../users/users.service';
|
||||
import { Language } from 'src/decorators/language.decorator';
|
||||
import { OpenDataService } from './open-data.service';
|
||||
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
||||
import { CORSGuard, SetOrigin } from 'src/decorators/set-origin.decorator';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||
import { request } from 'http';
|
||||
@@ -31,8 +30,6 @@ export class OpenDataController {
|
||||
}
|
||||
|
||||
@Post("/sharing-ocean-data")
|
||||
// @SetOrigin('devsbm.dadosfera.io')
|
||||
// @UseGuards(CORSGuard)
|
||||
@HttpCode(200)
|
||||
@Header('content-type', 'application/json')
|
||||
@ApiOkResponse()
|
||||
@@ -44,22 +41,16 @@ export class OpenDataController {
|
||||
@Req()
|
||||
request: Request,
|
||||
) {
|
||||
this.logger.info('createUser for open data'
|
||||
+ JSON.stringify({
|
||||
origin: request.headers.origin,
|
||||
language,
|
||||
body
|
||||
}));
|
||||
if (!request.headers['user-agent'].includes('WordPress/6.7.1; https://devsbm.dadosfera.io')) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
this.logger.info('createUser for open data');
|
||||
|
||||
// "401573bb-334f-44b2-b30e-88d4cea31ae9"
|
||||
// const OPENDATA_PUBLIC_USERS_GROUP_ID = process.env.OPEN_GROUP_ID;
|
||||
// ""f239718a-a271-4ef9-ae7e-02a2f0f3aa6e""
|
||||
// const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
||||
const OPENDATA_CUSTOMER_ID = "b3e3dfe5-b992-4586-a73c-c0b0c00f615d";
|
||||
this.logger.info('user-agent', request.headers['user-agent']);
|
||||
|
||||
this.logger.info("OPENDATA_CUSTOMER_ID: " + process.env.OPEN_CUSTOMER_ID)
|
||||
this.logger.info("OPEN_GROUP_ID: " + process.env.OPEN_GROUP_ID)
|
||||
const roles = ["e3f98a2f-7748-4981-8505-7695c8ca8218"];
|
||||
const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
||||
const OPENDATA_GROUP_ID = process.env.OPEN_GROUP_ID;
|
||||
const roles = [process.env.OPEN_GROUP_ID];
|
||||
const metadata = PackTheMetadata({
|
||||
language: language || 'en-us'
|
||||
});
|
||||
@@ -77,7 +68,6 @@ export class OpenDataController {
|
||||
this.logger.error('user data ' + e.message);
|
||||
}
|
||||
|
||||
|
||||
const user: CreateUserOpenDataDTO = {
|
||||
email: data["email"],
|
||||
enquiryType: data["enquiry_type"],
|
||||
@@ -85,11 +75,11 @@ export class OpenDataController {
|
||||
lastName: data["last_name"],
|
||||
organization: data["organization"]
|
||||
}
|
||||
this.logger.info('user request' + JSON.stringify({ user, roles, customer: OPENDATA_CUSTOMER_ID }));
|
||||
this.logger.info(`user request to group ${OPENDATA_CUSTOMER_ID} with role ${OPENDATA_GROUP_ID}`);
|
||||
|
||||
try {
|
||||
await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles, metadata);
|
||||
this.logger.info('user created with sucessfull data');
|
||||
const id = await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles, metadata);
|
||||
this.logger.info('user created with id: '+ id);
|
||||
return {
|
||||
success: true,
|
||||
status: 'success',
|
||||
|
||||
@@ -40,10 +40,10 @@ export class OpenDataService implements OnModuleInit {
|
||||
}
|
||||
|
||||
try {
|
||||
await lastValueFrom(
|
||||
const { user } = await lastValueFrom(
|
||||
this.usersClientService.SimpleUserCreate(body, metadata),
|
||||
);
|
||||
return "User created";
|
||||
return user.id;
|
||||
} catch(err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ export class PipelinesService implements OnModuleInit {
|
||||
const res = await lastValueFrom(
|
||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||
{
|
||||
dashboard_id: '83',
|
||||
dashboard_id: '95',
|
||||
exp: '15m',
|
||||
metabase_customer_name: 'dadosferatech',
|
||||
},
|
||||
|
||||
@@ -27,9 +27,9 @@ export class CustomerTheme implements Theme {
|
||||
@ApiProperty()
|
||||
textColor: string;
|
||||
@ApiProperty()
|
||||
logoWhite: string;
|
||||
logo: string;
|
||||
@ApiProperty()
|
||||
logoBlack: string;
|
||||
logoLogin: string;
|
||||
}
|
||||
|
||||
export class CustomerThemeResponse {
|
||||
|
||||
@@ -59,22 +59,22 @@ export class ThemeController {
|
||||
id,
|
||||
}));
|
||||
|
||||
const logoWhite = files.find(file => file.fieldname === 'logoWhite');
|
||||
const logoBlack = files.find(file => file.fieldname === 'logoBlack');
|
||||
const logo = files.find(file => file.fieldname === 'logo');
|
||||
const logoLogin = files.find(file => file.fieldname === 'logoLogin');
|
||||
|
||||
this.validFileSize(logoWhite);
|
||||
this.validFileSize(logoBlack);
|
||||
this.validMimeType(logoWhite);
|
||||
this.validMimeType(logoBlack);
|
||||
this.validFileSize(logo);
|
||||
this.validFileSize(logoLogin);
|
||||
this.validMimeType(logo);
|
||||
this.validMimeType(logoLogin);
|
||||
|
||||
try {
|
||||
const theme = await this.themeService.createThemeByCustomer(id, {
|
||||
...data,
|
||||
logoWhite,
|
||||
logoBlack
|
||||
logo,
|
||||
logoLogin
|
||||
});
|
||||
this.logger.info('saveCustomertheme' + JSON.stringify(theme));
|
||||
return { theme: theme };
|
||||
return theme;
|
||||
} catch (err) {
|
||||
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
|
||||
@@ -98,7 +98,7 @@ export class ThemeController {
|
||||
const mimeTypesValid = ['image/jpeg', 'image/jpg', 'image/png'];
|
||||
|
||||
if (file && !mimeTypesValid.includes(file.mimetype)) {
|
||||
throw new HttpException(`O Arquivo ${file.fieldname} deve ser jpeg, jpg ou png`, HttpStatus.BAD_REQUEST);
|
||||
throw new HttpException(`O Arquivo ${file.fieldname} deve ser jpeg, jpg, ou png`, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,10 @@ export class ThemeController {
|
||||
|
||||
try {
|
||||
const data = await this.themeService.getThemeByCustomer(id);
|
||||
this.logger.info('Success - getCustomerTheme with id'+ id);
|
||||
return data;
|
||||
this.logger.info('Success - getCustomerTheme'+ JSON.stringify(data));
|
||||
if (data?.theme) return data;
|
||||
|
||||
return { theme: null };
|
||||
}catch (err) {
|
||||
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||
this.logger.error('Error - getCustomerTheme - Expect CUSTOMER.NOT_FOUND');
|
||||
|
||||
@@ -21,11 +21,10 @@ import { resolve } from 'path';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
type Files = {
|
||||
logoWhite: Express.Multer.File,
|
||||
logoBlack: Express.Multer.File,
|
||||
logo: Express.Multer.File,
|
||||
logoLogin: Express.Multer.File,
|
||||
}
|
||||
|
||||
// This function will accept any string, which may result in a bug.
|
||||
@Injectable()
|
||||
export class ThemeService implements OnModuleInit {
|
||||
private themeService: ThemeProtoService;
|
||||
@@ -63,12 +62,12 @@ export class ThemeService implements OnModuleInit {
|
||||
chunk: Buffer.alloc(0)
|
||||
})
|
||||
|
||||
if(theme.logoBlack) {
|
||||
await this.sendFile(theme.logoBlack, customerThemeRequest$);
|
||||
if(theme.logo) {
|
||||
await this.sendFile(theme.logo, customerThemeRequest$);
|
||||
}
|
||||
|
||||
if(theme.logoWhite) {
|
||||
await this.sendFile(theme.logoWhite, customerThemeRequest$);
|
||||
if(theme.logoLogin) {
|
||||
await this.sendFile(theme.logoLogin, customerThemeRequest$);
|
||||
}
|
||||
customerThemeRequest$.complete();
|
||||
|
||||
@@ -95,18 +94,20 @@ export class ThemeService implements OnModuleInit {
|
||||
}
|
||||
|
||||
private async sendFile(file: Express.Multer.File, stream$: ReplaySubject<ThemeRequest>) {
|
||||
const bufferStream = new Readable({
|
||||
highWaterMark: 1024 * 1024, // 1 MB por chunk
|
||||
read() {}
|
||||
});
|
||||
bufferStream.push(file.buffer);
|
||||
bufferStream.push(null);
|
||||
const chunkSize = 4 * 1024 * 1024;
|
||||
const bufferStream = new CustomBufferStream(file.buffer, chunkSize);
|
||||
const parseMimitypeForExtension = {
|
||||
'image/jpeg': '.jpeg',
|
||||
'image/jpg': '.jpg',
|
||||
'image/png': '.png',
|
||||
'image/svg+xml': '.svg',
|
||||
}
|
||||
|
||||
const extension = parseMimitypeForExtension[file.mimetype];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
bufferStream.on('data', (chunk) => {
|
||||
console.log('enviando chunk', file.fieldname)
|
||||
const mimetype = file.mimetype.split('/')[1]; // example image/jpeg
|
||||
const filename = file.fieldname.concat(".", mimetype);
|
||||
const filename = file.fieldname.concat(extension);
|
||||
stream$.next({
|
||||
customerId: '',
|
||||
displayName: '',
|
||||
@@ -119,15 +120,39 @@ export class ThemeService implements OnModuleInit {
|
||||
});
|
||||
|
||||
bufferStream.on('end', () => {
|
||||
console.log('terminou de enviar')
|
||||
resolve(file.filename)
|
||||
});
|
||||
|
||||
bufferStream.on('error', (err) => {
|
||||
console.error('Erro no stream:', err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CustomBufferStream extends Readable {
|
||||
buffer: Buffer;
|
||||
offset: number;
|
||||
chunkSize: number;
|
||||
|
||||
constructor(buffer: Buffer, chunkSize: number) {
|
||||
super({ highWaterMark: chunkSize }); // Configura o tamanho do chunk
|
||||
this.buffer = buffer;
|
||||
this.offset = 0;
|
||||
this.chunkSize = chunkSize;
|
||||
}
|
||||
|
||||
_read() {
|
||||
if (this.offset < this.buffer.length) {
|
||||
const end = Math.min(this.offset + this.chunkSize, this.buffer.length);
|
||||
|
||||
const copiedBuf = Uint8Array.prototype.slice.call(this.buffer);
|
||||
const chunk = copiedBuf.slice(this.offset, end);
|
||||
this.offset = end;
|
||||
this.push(chunk);
|
||||
} else {
|
||||
this.push(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user