This commit is contained in:
sdarbinyan
2026-06-01 00:47:26 +04:00
parent 49f69f6af0
commit 4d8dc6b59c
22 changed files with 1266 additions and 353 deletions

View File

@@ -672,7 +672,7 @@ function respond<T>(body: T, delayMs = 150) {
}
// ─── Mock Auth State ───
let mockQrPollCount = 0;
const mockWebSessionChecks = new Map<string, number>();
// ─── The Interceptor ───
@@ -688,38 +688,39 @@ export const mockDataInterceptor: HttpInterceptorFn = (req, next) => {
return respond({ message: 'pong (mock)' });
}
// ── GET /auth/session
if (url.includes('/auth/session') && req.method === 'GET') {
return respond({ active: false }, 100);
// ── POST /users/sessions
if (url.endsWith('/users/sessions') && req.method === 'POST') {
const body = req.body as { webSessionID?: string } | null;
const webSessionID = body?.webSessionID || req.headers.get('WebSessionID') || 'mock-web-session';
mockWebSessionChecks.set(webSessionID, 0);
return respond({ webSessionID, status: false }, 200);
}
// ── POST /auth/qr/create
if (url.includes('/auth/qr/create') && req.method === 'POST') {
const token = 'mock-qr-token-' + Date.now();
const botUsername = (environment as Record<string, unknown>)['telegramBot'] as string || 'DexarSupport_bot';
mockQrPollCount = 0;
return respond({
token,
url: `https://t.me/${botUsername}?start=qr_${token}`
}, 200);
}
// ── GET /users/sessions/:webSessionID
const userSessionMatch = url.match(/\/users\/sessions\/([^/?]+)$/);
if (userSessionMatch && req.method === 'GET') {
const webSessionID = decodeURIComponent(userSessionMatch[1]);
const checks = (mockWebSessionChecks.get(webSessionID) ?? 0) + 1;
mockWebSessionChecks.set(webSessionID, checks);
// ── GET /auth/qr/poll
if (url.includes('/auth/qr/poll') && req.method === 'GET') {
mockQrPollCount++;
// Simulate confirmed after 3 polls (~9 seconds)
if (mockQrPollCount >= 3) {
if (checks >= 3) {
return respond({
status: 'confirmed',
session: {
sessionId: 'mock-session-' + Date.now(),
active: true,
displayName: 'Telegram User',
expiresAt: new Date(Date.now() + 3600000).toISOString()
}
webSessionID,
status: true,
telegramUserID: 123456,
username: 'telegram_user',
displayName: 'Telegram User',
expiresAt: new Date(Date.now() + 3600000).toISOString()
}, 200);
}
return respond({ status: 'pending' }, 200);
return respond({ webSessionID, status: false }, 200);
}
// ── DELETE /users/sessions/:webSessionID
if (userSessionMatch && req.method === 'DELETE') {
mockWebSessionChecks.delete(decodeURIComponent(userSessionMatch[1]));
return respond({ status: true }, 100);
}
// ── GET /category (all categories flat list)