mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-01 20:28:17 +00:00
Compare commits
34
Commits
+9
-5
@@ -5619,6 +5619,9 @@
|
|||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"themeEnabled": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -5627,7 +5630,8 @@
|
|||||||
"name",
|
"name",
|
||||||
"tier",
|
"tier",
|
||||||
"scheduleLimit",
|
"scheduleLimit",
|
||||||
"links"
|
"links",
|
||||||
|
"themeEnabled"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"AuthUser": {
|
"AuthUser": {
|
||||||
@@ -8374,18 +8378,18 @@
|
|||||||
"textColor": {
|
"textColor": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"logoWhite": {
|
"logo": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"logoBlack": {
|
"logoLogin": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"backgroundColor",
|
"backgroundColor",
|
||||||
"textColor",
|
"textColor",
|
||||||
"logoWhite",
|
"logo",
|
||||||
"logoBlack"
|
"logoLogin"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"CustomerThemeResponse": {
|
"CustomerThemeResponse": {
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ spec:
|
|||||||
value: {{ .Values.maestro.tr_factory_url }}
|
value: {{ .Values.maestro.tr_factory_url }}
|
||||||
- name: UPLOAD_FILE_AGENT_CONNECTION
|
- name: UPLOAD_FILE_AGENT_CONNECTION
|
||||||
value: {{ .Values.maestro.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
|
- name: JWT_PRIVATE_KEY
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
|
|||||||
Generated
+4
-4
@@ -12,7 +12,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@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/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
@@ -1403,9 +1403,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.37.0-beta.3",
|
"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.3.tgz",
|
"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-9YSgzkXVqe9QsBxJjfxYxttAiyCXxgq49Xjs3OvnTLCXRDn3XtTlPaC+yHrTEUgCkQyhlDZuswe6f6oBImqIRQ==",
|
"integrity": "sha512-dtHMzMU2Qa9c6DpygWr7fib19l1zqbYgBi2wGkiJ6uMAvl1CGu9V0p+JA1FwGTQ0QRy7EkkRVi6X6sH5u/ICpA==",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@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/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@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;
|
scheduleLimit: string;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
links: Link[];
|
links: Link[];
|
||||||
|
@ApiProperty()
|
||||||
|
themeEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AuthSignInReq implements AuthSignInRequest {
|
export class AuthSignInReq implements AuthSignInRequest {
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ export class CustomersService implements OnModuleInit {
|
|||||||
const res = await lastValueFrom(
|
const res = await lastValueFrom(
|
||||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||||
{
|
{
|
||||||
dashboard_id: '45',
|
dashboard_id: '98',
|
||||||
exp: '15m',
|
exp: '15m',
|
||||||
metabase_customer_name: 'dadosferatech',
|
metabase_customer_name: 'dadosferatech',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
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 { ApiCreatedResponse, ApiHeaders, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
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 { Language } from 'src/decorators/language.decorator';
|
||||||
import { OpenDataService } from './open-data.service';
|
import { OpenDataService } from './open-data.service';
|
||||||
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
||||||
import { CORSGuard, SetOrigin } from 'src/decorators/set-origin.decorator';
|
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { request } from 'http';
|
import { request } from 'http';
|
||||||
@@ -31,8 +30,6 @@ export class OpenDataController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post("/sharing-ocean-data")
|
@Post("/sharing-ocean-data")
|
||||||
// @SetOrigin('devsbm.dadosfera.io')
|
|
||||||
// @UseGuards(CORSGuard)
|
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@Header('content-type', 'application/json')
|
@Header('content-type', 'application/json')
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@@ -44,22 +41,16 @@ export class OpenDataController {
|
|||||||
@Req()
|
@Req()
|
||||||
request: Request,
|
request: Request,
|
||||||
) {
|
) {
|
||||||
this.logger.info('createUser for open data'
|
if (!request.headers['user-agent'].includes('WordPress/6.7.1; https://devsbm.dadosfera.io')) {
|
||||||
+ JSON.stringify({
|
throw new ForbiddenException();
|
||||||
origin: request.headers.origin,
|
}
|
||||||
language,
|
this.logger.info('createUser for open data');
|
||||||
body
|
|
||||||
}));
|
|
||||||
|
|
||||||
// "401573bb-334f-44b2-b30e-88d4cea31ae9"
|
this.logger.info('user-agent', request.headers['user-agent']);
|
||||||
// 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("OPENDATA_CUSTOMER_ID: " + process.env.OPEN_CUSTOMER_ID)
|
const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
||||||
this.logger.info("OPEN_GROUP_ID: " + process.env.OPEN_GROUP_ID)
|
const OPENDATA_GROUP_ID = process.env.OPEN_GROUP_ID;
|
||||||
const roles = ["e3f98a2f-7748-4981-8505-7695c8ca8218"];
|
const roles = [process.env.OPEN_GROUP_ID];
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
language: language || 'en-us'
|
language: language || 'en-us'
|
||||||
});
|
});
|
||||||
@@ -77,7 +68,6 @@ export class OpenDataController {
|
|||||||
this.logger.error('user data ' + e.message);
|
this.logger.error('user data ' + e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const user: CreateUserOpenDataDTO = {
|
const user: CreateUserOpenDataDTO = {
|
||||||
email: data["email"],
|
email: data["email"],
|
||||||
enquiryType: data["enquiry_type"],
|
enquiryType: data["enquiry_type"],
|
||||||
@@ -85,11 +75,11 @@ export class OpenDataController {
|
|||||||
lastName: data["last_name"],
|
lastName: data["last_name"],
|
||||||
organization: data["organization"]
|
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 {
|
try {
|
||||||
await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles, metadata);
|
const id = await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles, metadata);
|
||||||
this.logger.info('user created with sucessfull data');
|
this.logger.info('user created with id: '+ id);
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
status: 'success',
|
status: 'success',
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ export class OpenDataService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await lastValueFrom(
|
const { user } = await lastValueFrom(
|
||||||
this.usersClientService.SimpleUserCreate(body, metadata),
|
this.usersClientService.SimpleUserCreate(body, metadata),
|
||||||
);
|
);
|
||||||
return "User created";
|
return user.id;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
const res = await lastValueFrom(
|
const res = await lastValueFrom(
|
||||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||||
{
|
{
|
||||||
dashboard_id: '83',
|
dashboard_id: '95',
|
||||||
exp: '15m',
|
exp: '15m',
|
||||||
metabase_customer_name: 'dadosferatech',
|
metabase_customer_name: 'dadosferatech',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ export class CustomerTheme implements Theme {
|
|||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
textColor: string;
|
textColor: string;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
logoWhite: string;
|
logo: string;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
logoBlack: string;
|
logoLogin: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CustomerThemeResponse {
|
export class CustomerThemeResponse {
|
||||||
|
|||||||
@@ -59,22 +59,22 @@ export class ThemeController {
|
|||||||
id,
|
id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const logoWhite = files.find(file => file.fieldname === 'logoWhite');
|
const logo = files.find(file => file.fieldname === 'logo');
|
||||||
const logoBlack = files.find(file => file.fieldname === 'logoBlack');
|
const logoLogin = files.find(file => file.fieldname === 'logoLogin');
|
||||||
|
|
||||||
this.validFileSize(logoWhite);
|
this.validFileSize(logo);
|
||||||
this.validFileSize(logoBlack);
|
this.validFileSize(logoLogin);
|
||||||
this.validMimeType(logoWhite);
|
this.validMimeType(logo);
|
||||||
this.validMimeType(logoBlack);
|
this.validMimeType(logoLogin);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const theme = await this.themeService.createThemeByCustomer(id, {
|
const theme = await this.themeService.createThemeByCustomer(id, {
|
||||||
...data,
|
...data,
|
||||||
logoWhite,
|
logo,
|
||||||
logoBlack
|
logoLogin
|
||||||
});
|
});
|
||||||
this.logger.info('saveCustomertheme' + JSON.stringify(theme));
|
this.logger.info('saveCustomertheme' + JSON.stringify(theme));
|
||||||
return { theme: theme };
|
return theme;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||||
this.logger.error('Error - saveCustomertheme - Expect 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'];
|
const mimeTypesValid = ['image/jpeg', 'image/jpg', 'image/png'];
|
||||||
|
|
||||||
if (file && !mimeTypesValid.includes(file.mimetype)) {
|
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 {
|
try {
|
||||||
const data = await this.themeService.getThemeByCustomer(id);
|
const data = await this.themeService.getThemeByCustomer(id);
|
||||||
this.logger.info('Success - getCustomerTheme with id'+ id);
|
this.logger.info('Success - getCustomerTheme'+ JSON.stringify(data));
|
||||||
return data;
|
if (data?.theme) return data;
|
||||||
|
|
||||||
|
return { theme: null };
|
||||||
}catch (err) {
|
}catch (err) {
|
||||||
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||||
this.logger.error('Error - getCustomerTheme - Expect CUSTOMER.NOT_FOUND');
|
this.logger.error('Error - getCustomerTheme - Expect CUSTOMER.NOT_FOUND');
|
||||||
|
|||||||
@@ -21,11 +21,10 @@ import { resolve } from 'path';
|
|||||||
import { Readable } from 'stream';
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
type Files = {
|
type Files = {
|
||||||
logoWhite: Express.Multer.File,
|
logo: Express.Multer.File,
|
||||||
logoBlack: Express.Multer.File,
|
logoLogin: Express.Multer.File,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function will accept any string, which may result in a bug.
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ThemeService implements OnModuleInit {
|
export class ThemeService implements OnModuleInit {
|
||||||
private themeService: ThemeProtoService;
|
private themeService: ThemeProtoService;
|
||||||
@@ -63,12 +62,12 @@ export class ThemeService implements OnModuleInit {
|
|||||||
chunk: Buffer.alloc(0)
|
chunk: Buffer.alloc(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
if(theme.logoBlack) {
|
if(theme.logo) {
|
||||||
await this.sendFile(theme.logoBlack, customerThemeRequest$);
|
await this.sendFile(theme.logo, customerThemeRequest$);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(theme.logoWhite) {
|
if(theme.logoLogin) {
|
||||||
await this.sendFile(theme.logoWhite, customerThemeRequest$);
|
await this.sendFile(theme.logoLogin, customerThemeRequest$);
|
||||||
}
|
}
|
||||||
customerThemeRequest$.complete();
|
customerThemeRequest$.complete();
|
||||||
|
|
||||||
@@ -95,18 +94,20 @@ export class ThemeService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async sendFile(file: Express.Multer.File, stream$: ReplaySubject<ThemeRequest>) {
|
private async sendFile(file: Express.Multer.File, stream$: ReplaySubject<ThemeRequest>) {
|
||||||
const bufferStream = new Readable({
|
const chunkSize = 4 * 1024 * 1024;
|
||||||
highWaterMark: 1024 * 1024, // 1 MB por chunk
|
const bufferStream = new CustomBufferStream(file.buffer, chunkSize);
|
||||||
read() {}
|
const parseMimitypeForExtension = {
|
||||||
});
|
'image/jpeg': '.jpeg',
|
||||||
bufferStream.push(file.buffer);
|
'image/jpg': '.jpg',
|
||||||
bufferStream.push(null);
|
'image/png': '.png',
|
||||||
|
'image/svg+xml': '.svg',
|
||||||
|
}
|
||||||
|
|
||||||
|
const extension = parseMimitypeForExtension[file.mimetype];
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
bufferStream.on('data', (chunk) => {
|
bufferStream.on('data', (chunk) => {
|
||||||
console.log('enviando chunk', file.fieldname)
|
const filename = file.fieldname.concat(extension);
|
||||||
const mimetype = file.mimetype.split('/')[1]; // example image/jpeg
|
|
||||||
const filename = file.fieldname.concat(".", mimetype);
|
|
||||||
stream$.next({
|
stream$.next({
|
||||||
customerId: '',
|
customerId: '',
|
||||||
displayName: '',
|
displayName: '',
|
||||||
@@ -119,15 +120,39 @@ export class ThemeService implements OnModuleInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
bufferStream.on('end', () => {
|
bufferStream.on('end', () => {
|
||||||
console.log('terminou de enviar')
|
|
||||||
resolve(file.filename)
|
resolve(file.filename)
|
||||||
});
|
});
|
||||||
|
|
||||||
bufferStream.on('error', (err) => {
|
bufferStream.on('error', (err) => {
|
||||||
console.error('Erro no stream:', err);
|
|
||||||
reject(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