mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 15:11:15 +00:00
Introduced new interface definitions in napcat-common for logging, status, and subscription. Refactored napcat-webui-backend to use these interfaces, decoupling it from napcat-core and napcat-onebot. Moved OneBot config schema to backend and updated imports. Updated framework and shell to pass subscriptions to InitWebUi. Improved type safety and modularity across backend and shared packages.
20 lines
752 B
TypeScript
20 lines
752 B
TypeScript
import { statusHelperSubscription } from '@/napcat-webui-backend';
|
|
import { RequestHandler } from 'express';
|
|
import { SystemStatus } from 'napcat-common/src/status-interface';
|
|
export const StatusRealTimeHandler: RequestHandler = async (req, res) => {
|
|
res.setHeader('Content-Type', 'text/event-stream');
|
|
res.setHeader('Connection', 'keep-alive');
|
|
const sendStatus = (status: SystemStatus) => {
|
|
try {
|
|
res.write(`data: ${JSON.stringify(status)}\n\n`);
|
|
} catch (e) {
|
|
console.error(`An error occurred when writing sendStatus data to client: ${e}`);
|
|
}
|
|
};
|
|
statusHelperSubscription.on('statusUpdate', sendStatus);
|
|
req.on('close', () => {
|
|
statusHelperSubscription.off('statusUpdate', sendStatus);
|
|
res.end();
|
|
});
|
|
};
|