diff --git a/src/app.controller.ts b/src/app.controller.ts index 2792727..fea0d6b 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,19 +1,19 @@ import {Controller, Get, Post} from '@nestjs/common'; import {AppService} from './app.service'; import {XCookieAccountDto} from "./x-poster/dto/x-cookie-account.dto"; -import {XBrowserService} from "./x-poster/x-browser.service"; +import {XPosterRouterService} from "./x-poster/x-poster.router.service"; @Controller() export class AppController { constructor( private readonly appService: AppService, - private readonly xBrowserService: XBrowserService, + private readonly xPosterRouterService: XPosterRouterService, ) { } @Get() getHello() { - return this.xBrowserService.verifyCookie(); + return this.xPosterRouterService.verifyCookie(); } @Post('/set-x-cookies') diff --git a/src/x-poster/x-browser.service.ts b/src/x-poster/x-browser.service.ts index e51e335..157a469 100644 --- a/src/x-poster/x-browser.service.ts +++ b/src/x-poster/x-browser.service.ts @@ -152,9 +152,9 @@ export class XBrowserService implements OnModuleInit, OnModuleDestroy { await page.waitForTimeout(2000 + (Math.random() + Math.random()) * 3000); await page.mouse.wheel(0, rand(300, 500)); // Detect login/challenge screen - if (page.url().includes('/login') || page.url().includes('/flow')) { - this.logger.error('Cookies is die, please get news'); - return false; + if (page.url().includes('/home')) { + this.logger.log('Cookies live'); + return true; // return { // success: false, // error: 'Redirected to login', diff --git a/src/x-poster/x-poster.router.service.ts b/src/x-poster/x-poster.router.service.ts index 8edf103..fa6acb1 100644 --- a/src/x-poster/x-poster.router.service.ts +++ b/src/x-poster/x-poster.router.service.ts @@ -61,7 +61,7 @@ export class XPosterRouterService { } async verifyCookie(): Promise { - console.debug('==> Verify Cookie'); + this.logger.debug('==> Verify Cookie'); // const isAlive = await this.cookieSvc.verifyCookie(); const isAlive = await this.browserSvc.verifyCookie(); if (!isAlive) { @@ -69,8 +69,7 @@ export class XPosterRouterService { await this.notifyService.sendUrgentMessageToTele('❌Cookie đã hết hạn vui lòng cập nhập để sử dụng.') } await this.xCacheService.setStateXCookiesIsSillALive(); - this.notifyService.sendMessageToTele('✅Verify cookie pass').catch((err) => { - }); + await this.notifyService.sendMessageToTele('✅Verify cookie pass') return isAlive; }