Add GET /screenshot

This commit is contained in:
allburov committed 2020-10-21 12:22:00 +07:00
1 parent e01df06789
commit 4f29f82f22
3 files changed
+31 -2

No files matched your search

File renamed without changes.
+28
View File
@@ -0,0 +1,28 @@
import {Controller, Get, Inject, Res} from '@nestjs/common';
import {ApiTags} from "@nestjs/swagger";
import {Whatsapp} from "venom-bot";
import {Readable} from "stream";
import {Response} from 'express';
@Controller('api')
@ApiTags('screenshot')
export class ScreenshotController {
constructor(@Inject('WHATSAPP') private whatsapp: Whatsapp) {
}
@Get('/screenshot')
async screenshot(@Res() res: Response,) {
const buffer = await this.whatsapp.page.screenshot();
const stream = new Readable();
stream.push(buffer);
stream.push(null);
res.set({
'Content-Type': 'image/png',
'Content-Length': buffer.length,
});
stream.pipe(res)
}
}
+3 -2
View File
@@ -1,11 +1,12 @@
import {Module} from '@nestjs/common';
import {ChattingController} from './api/chattingController';
import {ChattingController} from './api/chatting.controller';
import {DeviceController} from "./api/device.controller";
import {whatsappProvider, WhatsappService} from "./whatsapp.service";
import {ScreenshotController} from "./api/screenshot.controller";
@Module({
imports: [],
controllers: [ChattingController, DeviceController],
controllers: [ChattingController, DeviceController, ScreenshotController],
providers: [whatsappProvider, WhatsappService],
})
export class AppModule {