From 057af8af09ae01464e4d32d27a530db4dc72072a Mon Sep 17 00:00:00 2001 From: lyz05 <294068487@qq.com> Date: Tue, 8 Nov 2022 22:35:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9C=9F=E5=AE=9Eip=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- routes/airportsub.js | 2 +- routes/danmaku.js | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5c6061f..26917f3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "start": "node --max-old-space-size=200 ./bin/www", "dev": "nodemon --max-old-space-size=200 ./bin/www", - "test": "nyc -a mocha --recursive" + "test": "nyc -a mocha --recursive", + "deploy": "flyctl deploy" }, "dependencies": { "ali-oss": "^6.17.1", diff --git a/routes/airportsub.js b/routes/airportsub.js index b793098..5b7e6a6 100644 --- a/routes/airportsub.js +++ b/routes/airportsub.js @@ -99,7 +99,7 @@ router.get('/cache', async function (req, res, next) { const key = Object.keys(database.suburl)[i] messages.push({title: 'Download', key, status: res.status}) const userinfo = res.headers['subscription-userinfo'] - const base64userinfo = btoa(userinfo) + const base64userinfo = Buffer.from(userinfo).toString('base64') // 设置强制下载并设置文件名 headers = { 'Content-type': 'text/plain; charset=utf-8', diff --git a/routes/danmaku.js b/routes/danmaku.js index 049037d..f713274 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -10,6 +10,13 @@ function getscheme(req) { return req.headers['x-forwarded-proto'] || req.protocol; } +function getClientIp(req) { + return req.headers['x-forwarded-for'] || + req.connection.remoteAddress || + req.socket.remoteAddress || + req.connection.socket.remoteAddress; +} + async function build_response(url) { try { await axios.get(url) @@ -38,7 +45,7 @@ async function build_response(url) { /* GET home page. */ router.get('/', async function (req, res, next) { - leancloud.danmakuAccessAdd({ip: req.ip, url: req.query.url, ua: req.headers['user-agent']}) + leancloud.danmakuAccessAdd({ip: getClientIp(req), url: req.query.url, ua: req.headers['user-agent']}) //检查是否包含URL参数 if (!req.query.url) { var urls = [mgtv.example_urls[0], bilibili.example_urls[0], tencentvideo.example_urls[0], youku.example_urls[0], iqiyi.example_urls[0]];