[core] Get screenshot return only buffer
This commit is contained in:
1 parent
802da9f3b2
commit
a4e310a7f8
5 files changed
+15
-12
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user