[core] Get screenshot return only buffer

This commit is contained in:
allburov committed 2023-11-30 18:01:49 +07:00
1 parent 802da9f3b2
commit a4e310a7f8
5 files changed
+15 -12

No files matched your search

+7 -7
View File
@@ -1,4 +1,4 @@
import { Controller, Get, Query, Res } from '@nestjs/common';
import { Controller, Get, Query, Res, StreamableFile } from '@nestjs/common';
import { ApiSecurity, ApiTags } from '@nestjs/swagger';
import { Response } from 'express';
import { Readable } from 'stream';
@@ -13,17 +13,17 @@ export class ScreenshotController {
constructor(private manager: SessionManager) {}
@Get('/screenshot')
async screenshot(@Res() res: Response, @Query() sessionQuery: SessionQuery) {
async screenshot(
@Res({ passthrough: true }) res: Response,
@Query() sessionQuery: SessionQuery,
) {
const whatsappService = this.manager.getSession(sessionQuery.session);
const buffer = await whatsappService.getScreenshot();
const stream = new Readable();
stream.push(buffer);
stream.push(null);
const file = new StreamableFile(buffer);
res.set({
'Content-Type': 'image/png',
'Content-Length': buffer.length,
});
stream.pipe(res);
return file;
}
}
+1 -1
View File
@@ -206,7 +206,7 @@ export abstract class WhatsappSession {
throw new NotImplementedByEngineError();
}
abstract getScreenshot(): Promise<Buffer | string>;
abstract getScreenshot(): Promise<Buffer>;
public getSessionMeInfo(): Promise<MeInfo | null> {
throw new NotImplementedByEngineError();
+1 -1
View File
@@ -288,7 +288,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
return { code: codeRepr };
}
async getScreenshot(): Promise<Buffer | string> {
async getScreenshot(): Promise<Buffer> {
if (this.status === WAHASessionStatus.STARTING) {
throw new UnprocessableEntityException(
`The session is starting, please try again after few seconds`,
+1 -1
View File
@@ -126,7 +126,7 @@ export class WhatsappSessionVenomCore extends WhatsappSession {
/**
* START - Methods for API
*/
getScreenshot(): Promise<Buffer | string> {
getScreenshot(): Promise<Buffer> {
if (this.status === WAHASessionStatus.STARTING) {
throw new UnprocessableEntityException(
`The session is starting, please try again after few seconds`,
+5 -2
View File
@@ -177,13 +177,16 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
return Promise.resolve(this.qr.get());
}
async getScreenshot(): Promise<Buffer | string> {
async getScreenshot(): Promise<Buffer> {
if (this.status === WAHASessionStatus.FAILED) {
throw new UnprocessableEntityException(
`The session under FAILED status. Please try to restart it.`,
);
}
return await this.whatsapp.pupPage.screenshot();
const screenshot = await this.whatsapp.pupPage.screenshot({
encoding: 'binary',
});
return screenshot as Buffer;
}
async checkNumberStatus(