diff --git a/docsfera.json b/docsfera.json index 1366d0e..33988d7 100644 --- a/docsfera.json +++ b/docsfera.json @@ -8378,18 +8378,18 @@ "textColor": { "type": "string" }, - "logoWhite": { + "logo": { "type": "string" }, - "logoBlack": { + "logoLogin": { "type": "string" } }, "required": [ "backgroundColor", "textColor", - "logoWhite", - "logoBlack" + "logo", + "logoLogin" ] }, "CustomerThemeResponse": { diff --git a/package-lock.json b/package-lock.json index 60dbd2d..9539649 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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.4", + "@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.4", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.37.0-beta.4.tgz", - "integrity": "sha512-es4OIgv4/X2dYMtveW2Q3/nTOSR7ARnX25241wnuvGEx7XdQGq+ahxHXDG36Yznl+bz51miQHkjpKUw3wut6cQ==", + "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", diff --git a/package.json b/package.json index 8a2b7c1..072bfb6 100644 --- a/package.json +++ b/package.json @@ -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.4", + "@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", diff --git a/src/modules/theme/dtos/customers.ts b/src/modules/theme/dtos/customers.ts index 5d87b8b..05f5305 100644 --- a/src/modules/theme/dtos/customers.ts +++ b/src/modules/theme/dtos/customers.ts @@ -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 { diff --git a/src/modules/theme/theme.controller.ts b/src/modules/theme/theme.controller.ts index dba694e..94335e7 100644 --- a/src/modules/theme/theme.controller.ts +++ b/src/modules/theme/theme.controller.ts @@ -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'); diff --git a/src/modules/theme/theme.service.ts b/src/modules/theme/theme.service.ts index 4c5f33f..64583e7 100644 --- a/src/modules/theme/theme.service.ts +++ b/src/modules/theme/theme.service.ts @@ -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,16 +94,11 @@ export class ThemeService implements OnModuleInit { } private async sendFile(file: Express.Multer.File, stream$: ReplaySubject) { - 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); 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); stream$.next({ @@ -119,15 +113,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); + } + } +}