From f3ab189cf9b8c5df79fe292d5220e65d02a02dfb Mon Sep 17 00:00:00 2001 From: lyz05 <294068487@qq.com> Date: Thu, 16 Oct 2025 17:15:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=B9=E6=8D=AE=E9=87=8D=E5=AE=9A?= =?UTF-8?q?=E5=90=91=E5=90=8E=E7=9A=84=20URL=20=E7=A1=AE=E5=AE=9A=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=99=A8=E9=80=89=E6=8B=A9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/www | 10 +++++++++- routes/danmaku.js | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/bin/www b/bin/www index 386ddf9..1225211 100644 --- a/bin/www +++ b/bin/www @@ -6,6 +6,7 @@ const app = require('../app'); const debug = require('debug')('danmaku:server'); const http = require('http'); +const os = require('os'); /** * Get port from environment and store in Express. @@ -24,7 +25,14 @@ const server = http.createServer(app); server.listen(port, () => { console.log(`Listening on port ${port}`); - console.log(`visit: http://localhost:${port}`); + console.log(`Visit the server at the following addresses:`); + + const interfaces = os.networkInterfaces(); + for (const name in interfaces) { + for (const iface of interfaces[name]) { + console.log(`- http://${iface.address}:${port} (${name})`); + } + } }); server.on('error', onError); server.on('listening', onListening); diff --git a/routes/danmaku.js b/routes/danmaku.js index 572f4bb..d7bfeae 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -13,28 +13,28 @@ const { const list = [bilibili, mgtv, tencentvideo, youku, iqiyi, gamer]; const memory = require("../utils/memory"); const db = require("../utils/db"); +const UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"; // 返回对象{msg: "ok", title: "标题", content: []} async function build_response(url, req) { - // 循环找最终url - for (let q = new URLSearchParams(URL.parse(url).query); q.has("url");) { - console.log("Redirecting to", url); - url = q.get("url"); - q = new URLSearchParams(URL.parse(url).query); - } - console.log("Real url:", url); // 测试url是否能下载 try { - await axios.get(url, { - headers: { "Accept-Encoding": "gzip,deflate,compress" } + const response = await axios.get(url, { + headers: { + "Accept-Encoding": "gzip,deflate,compress", + "User-Agent": UA + }, + maxRedirects: 10 }); + url = response.request.res.responseUrl || url; + console.log("Real url:", url); } catch (e) { console.log(e); // 如果是 403 错误,不报错,继续执行 if (e.response && e.response.status === 403) { console.log("访问视频页面 403 错误,有可能被防火墙拦了"); } else { - return { msg: "传入的链接非法!请检查链接是否能在浏览器正常打开" }; + return { msg: "传入的链接非法!请检查链接能否能在浏览器正常打开" }; } } // 循环找到对应的解析器