some final fixes on session manager

This commit is contained in:
Boki 2025-06-29 17:15:55 -04:00
parent 966f6ac612
commit 8f1613697c
2 changed files with 24 additions and 5 deletions

View file

@ -132,7 +132,7 @@ export class QMSessionManager {
createdAt: session.createdAt instanceof Date ? session.createdAt.toISOString() : session.createdAt, createdAt: session.createdAt instanceof Date ? session.createdAt.toISOString() : session.createdAt,
id: session.uuid, id: session.uuid,
sessionType, sessionType,
} as any; };
await this.cacheProvider.set(sessionKey, cachedSession, 86400); // 24 hour TTL await this.cacheProvider.set(sessionKey, cachedSession, 86400); // 24 hour TTL
@ -261,8 +261,20 @@ export class QMSessionManager {
/** /**
* Get statistics about sessions * Get statistics about sessions
*/ */
async getStats(): Promise<Record<string, any>> { async getStats(): Promise<Record<string, {
const stats: Record<string, any> = {}; total: number;
valid: number;
failed: number;
successfulCalls: number;
failedCalls: number;
}>> {
const stats: Record<string, {
total: number;
valid: number;
failed: number;
successfulCalls: number;
failedCalls: number;
}> = {};
for (const [sessionType, sessionId] of Object.entries(QM_SESSION_IDS)) { for (const [sessionType, sessionId] of Object.entries(QM_SESSION_IDS)) {
const sessions = await this.getSessions(sessionId); const sessions = await this.getSessions(sessionId);

View file

@ -3,7 +3,7 @@
*/ */
export interface QMSession { export interface QMSession {
uuid?: string; // Unique identifier for the session uuid: string; // Unique identifier for the session
proxy: string; proxy: string;
headers: HeadersInit; headers: HeadersInit;
successfulCalls: number; successfulCalls: number;
@ -46,7 +46,14 @@ export interface QMAuthResponse {
error?: string; error?: string;
} }
export interface CachedSession extends QMSession { export interface CachedSession {
uuid: string;
proxy: string;
headers: HeadersInit;
successfulCalls: number;
failedCalls: number;
lastUsed: string; // ISO string for Redis storage
createdAt: string; // ISO string for Redis storage
id: string; id: string;
sessionType: string; sessionType: string;
} }