ai-query对接新版freesun-agent接口的分支
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
2.7 KiB

/**
* 52监测网论坛页面代理 + 清理 UI 元素
* 职责范围:
* 1. 代理论坛页面(带 cookie 转发)
* 2. 注入 JS 清理相关帖子、发表新帖、页脚等元素
*
*
* 维护说明:
* - 如需增删清理的元素,修改 injectedScript 中的选择器列表
*/
const request = require("superagent");
const FORUM_HOST = "http://bbs.52jiance.cn";
// 注入的清理脚本 — 只保留正文,移除所有论坛 UI
const injectedScript = `
<style>
/* 隐藏所有论坛 UI 区域 */
#toptb, #hd, .nexsidetls, .nex_plugin_reserved,
#pt, #pgt, .vwthdtit, .pi, .foldcount, .pob,
#p_btn, .nex_mean, #f_pst, .nexfooter, .sd, .nex_author,
.nex_sdbox, .nex_fabuanniu, .nex_fabu, .pgs, .pgb, .ad,
.p_pop, .h_pop, .bm, .bm_c, .tip, .tip_4, .modact,
header, footer, nav, aside, form:not(.t_f form),
.pls, .signature, .xg1, .xg2, .pstatus, .attach_nopermission, .attach_tips, a[href*='member.php?mod=logging'], .comiis_header, .comiis_footer,
.mu, .nv, .wp .footer, #ft, #scrolltop, .showbox, .popup,
.fastlg, .nex_prompt, .prompt, .notice, .nexlogin, .nexDL_part,
.nexbd_mains, .nexdl_avator, .nexbd_mls, .nexbd_mrs,
#um, #um_menu, .hdc, .nexlogo, .nexsearch, .nexDL_before
{ display: none !important; }
/* 只保留正文 */
.plc, .pct, .pcb, .pcbs, .t_f, #postlist, #ct
{ display: block !important; }
body { margin: 0; padding: 12px; background: #fff; }
.t_f { font-size: 14px; line-height: 1.8; color: #333; }
img { max-width: 100%; height: auto; }
</style>`;
module.exports.bbs52Proxy =
module.exports.bbs52Proxy = async (ctx) => {
try {
const pathname = ctx.path.replace(/^\/_bbs52/, "") || "/";
const targetUrl = FORUM_HOST + pathname + (ctx.querystring ? "?" + ctx.querystring : "");
const res = await request
.get(targetUrl)
.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
.set("Cookie", ctx.get("cookie") || "")
.redirects(0)
.ok((r) => r.status < 400);
const contentType = res.headers["content-type"] || "";
// 仅对 HTML 响应做注入
if (contentType.includes("text/html")) {
let html = res.text;
// 论坛页面是混淆 JS,没有 </head>,直接在内容前注入
html = injectedScript + html;
ctx.set("Content-Type", "text/html; charset=utf-8");
ctx.body = html;
} else {
// 非 HTML(图片、CSS 等)直接透传
ctx.set("Content-Type", contentType);
ctx.body = res.body;
}
ctx.status = res.status || 200;
} catch (error) {
console.error("bbs52 proxy error:", error.message);
// 如果代理失败,回退到原始 _bbs52 尝试
ctx.status = 502;
ctx.body = "代理请求失败";
}
};