更新依赖项,添加 flowme 插入触发器和监听器;重构数据库连接管理;优化用户路由和 SSE 处理

This commit is contained in:
2026-02-01 03:58:40 +08:00
parent 7c61bd3ac5
commit 82c9b834e9
16 changed files with 412 additions and 219 deletions

View File

@@ -13,6 +13,7 @@ import { getLoginUser } from '../modules/auth.ts';
import { rediretHome } from '../modules/user-app/index.ts';
import { logger } from '../modules/logger.ts';
import { UserV1Proxy } from '../modules/ws-proxy/proxy.ts';
import { UserV3Proxy } from '@/modules/v3/index.ts';
import { hasBadUser, userIsBanned, appIsBanned, userPathIsBanned } from '@/modules/off/index.ts';
import { robotsTxt } from '@/modules/html/index.ts';
import { isBun } from '@/utils/get-engine.ts';
@@ -194,8 +195,8 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
if (!domainApp) {
// 原始url地址
const urls = url.split('/');
const [_, _user, _app] = urls;
if (urls.length < 3) {
const [_, _user] = urls;
if (_user === 'robots.txt') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(robotsTxt);
@@ -212,8 +213,12 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
forBadUser(req, res);
}
return res.end();
} else {
if (userPathIsBanned(_user) || userPathIsBanned(_app)) {
logger.warn(`Bad user access from IP: ${dns.ip}, Host: ${dns.hostName}, URL: ${req.url}`);
return forBadUser(req, res);
}
}
const [_, _user, _app] = urls;
if (_app && urls.length === 3) {
// 重定向到
res.writeHead(302, { Location: `${url}/` });
@@ -250,6 +255,11 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
createNotFoundPage,
});
}
if (user !== 'api' && app === 'v3') {
return UserV3Proxy(req, res, {
createNotFoundPage,
});
}
const userApp = new UserApp({ user, app });
let isExist = await userApp.getExist();