[core] engine info only in

GET /api/sessions/{name}
This commit is contained in:
devlikepro committed 2024-09-16 12:53:27 +07:00
1 parent 6d46ad44a1
commit 6aa141bb33
4 files changed
+29 -14

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ class SessionsController {
@SessionApiParam
@UsePipes(new WAHAValidationPipe())
async get(@Param('session') name: string): Promise<SessionInfo> {
const session = this.manager.getSessionInfo(name);
const session = await this.manager.getSessionInfo(name);
if (session === null) {
throw new NotFoundException('Session not found');
}
+2 -1
View File
@@ -6,6 +6,7 @@ import { EventEmitter } from 'events';
import { WAHAEngine, WAHAEvents } from '../../structures/enums.dto';
import {
SessionConfig,
SessionDetailedInfo,
SessionDTO,
SessionInfo,
} from '../../structures/sessions.dto';
@@ -50,7 +51,7 @@ export abstract class SessionManager implements BeforeApplicationShutdown {
abstract getSession(name: string): WhatsappSession;
abstract getSessionInfo(name: string): Promise<SessionInfo | null>;
abstract getSessionInfo(name: string): Promise<SessionDetailedInfo | null>;
abstract getSessions(all: boolean): Promise<SessionInfo[]>;
+23 -12
View File
@@ -19,6 +19,7 @@ import {
import {
ProxyConfig,
SessionConfig,
SessionDetailedInfo,
SessionDTO,
SessionInfo,
} from '../structures/sessions.dto';
@@ -270,11 +271,23 @@ export class SessionManagerCore extends SessionManager {
const session = this.session as WhatsappSession;
const me = session.getSessionMeInfo();
return [
{
name: session.name,
status: session.status,
config: session.sessionConfig,
me: me,
},
];
}
private async fetchEngineInfo() {
const session = this.session as WhatsappSession;
// Get engine info
let engineInfo = {};
if (session) {
try {
engineInfo = await promiseTimeout(10, session.getEngineInfo());
engineInfo = await promiseTimeout(1000, session.getEngineInfo());
} catch (error) {
this.log.warn(
{ session: this.session, error: error },
@@ -286,21 +299,19 @@ export class SessionManagerCore extends SessionManager {
engine: session?.engine,
...engineInfo,
};
return [
{
name: session.name,
status: session.status,
config: session.sessionConfig,
me: me,
engine: engine,
},
];
return engine;
}
async getSessionInfo(name: string): Promise<SessionInfo | null> {
async getSessionInfo(name: string): Promise<SessionDetailedInfo | null> {
if (name !== this.DEFAULT) {
return null;
}
return this.getSessions(true).then((sessions) => sessions[0]);
const sessions = await this.getSessions(true);
if (sessions.length === 0) {
return null;
}
const session = sessions[0];
const engine = await this.fetchEngineInfo();
return { ...session, engine: engine };
}
}
+3
View File
@@ -153,6 +153,9 @@ export class MeInfo {
export class SessionInfo extends SessionDTO {
me?: MeInfo;
}
export class SessionDetailedInfo extends SessionInfo {
engine?: any;
}