61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { Router } from 'express';
|
|
import type { WebContext } from '../context.js';
|
|
|
|
export function createDebugRouter(ctx: WebContext): Router {
|
|
const router = Router();
|
|
|
|
// Dumps the browser context's cookies (names + metadata only — values are
|
|
// hashed) so we can tell which session/OAuth cookies are set after the
|
|
// extension import and which the chat surface might be missing.
|
|
router.get('/debug/cookies', async (req, res) => {
|
|
const browser = ctx.services.browser;
|
|
if (!browser) {
|
|
res.status(500).json({ error: 'Browser client not initialized' });
|
|
return;
|
|
}
|
|
const context = browser.getContext();
|
|
if (!context) {
|
|
res.status(500).json({ error: 'Browser context not available' });
|
|
return;
|
|
}
|
|
try {
|
|
const urls = ['https://www.reddit.com', 'https://chat.reddit.com', 'https://matrix.redditspace.com'];
|
|
const out: Record<string, unknown> = {};
|
|
for (const u of urls) {
|
|
const cookies = await context.cookies(u);
|
|
out[u] = cookies.map((c) => ({
|
|
name: c.name,
|
|
domain: c.domain,
|
|
path: c.path,
|
|
httpOnly: c.httpOnly,
|
|
secure: c.secure,
|
|
sameSite: c.sameSite,
|
|
expires: c.expires,
|
|
valueLen: c.value.length,
|
|
}));
|
|
}
|
|
res.json(out);
|
|
} catch (error) {
|
|
ctx.logger.error('Cookie dump failed:', error);
|
|
res.status(500).json({ error: String(error) });
|
|
}
|
|
});
|
|
|
|
router.post('/debug/check-responses', async (_req, res) => {
|
|
if (!ctx.services.responseChecker) {
|
|
res.status(500).json({ error: 'Response checker not initialized' });
|
|
return;
|
|
}
|
|
try {
|
|
ctx.logger.info('Manual response check triggered via API');
|
|
const results = await ctx.services.responseChecker.checkForResponses();
|
|
res.json({ success: true, results });
|
|
} catch (error) {
|
|
ctx.logger.error('Manual response check failed:', error);
|
|
res.status(500).json({ error: String(error) });
|
|
}
|
|
});
|
|
|
|
return router;
|
|
}
|