mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-02 17:59:53 +08:00
feat: 添加tg代理支持
This commit is contained in:
5
app.js
5
app.js
@@ -4,14 +4,16 @@ const path = require('path');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const logger = require('morgan');
|
||||
|
||||
|
||||
// 引入环境变量
|
||||
require('dotenv').config();
|
||||
|
||||
// 引入一个个路由模块
|
||||
const danmakuRouter = require('./routes/danmaku');
|
||||
const usersRouter = require('./routes/users');
|
||||
const ipinfoRouter = require('./routes/ipinfo');
|
||||
const airportsubRouter = require('./routes/airportsub');
|
||||
// 引入定时任务模块
|
||||
const schedule = require('./schedule/schedule');
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -27,7 +29,6 @@ app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
app.use('/', danmakuRouter);
|
||||
app.use('/users', usersRouter);
|
||||
app.use('/ipinfo', ipinfoRouter);
|
||||
app.use('/sub', airportsubRouter);
|
||||
|
||||
|
||||
24
package-lock.json
generated
24
package-lock.json
generated
@@ -24,6 +24,7 @@
|
||||
"lib-qqwry": "^1.3.2",
|
||||
"moment": "^2.29.4",
|
||||
"morgan": "~1.9.1",
|
||||
"node-cron": "^3.0.2",
|
||||
"pako": "^1.0.11",
|
||||
"whacko": "^0.19.1",
|
||||
"xml-js": "^1.6.11",
|
||||
@@ -4137,6 +4138,17 @@
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-cron": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.2.tgz",
|
||||
"integrity": "sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ==",
|
||||
"dependencies": {
|
||||
"uuid": "8.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-preload": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz",
|
||||
@@ -5706,7 +5718,6 @@
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
@@ -9171,6 +9182,14 @@
|
||||
"resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz",
|
||||
"integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg=="
|
||||
},
|
||||
"node-cron": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.2.tgz",
|
||||
"integrity": "sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ==",
|
||||
"requires": {
|
||||
"uuid": "8.3.2"
|
||||
}
|
||||
},
|
||||
"node-preload": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz",
|
||||
@@ -10386,8 +10405,7 @@
|
||||
"uuid": {
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||
"dev": true
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||
},
|
||||
"vary": {
|
||||
"version": "1.1.2",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"lib-qqwry": "^1.3.2",
|
||||
"moment": "^2.29.4",
|
||||
"morgan": "~1.9.1",
|
||||
"node-cron": "^3.0.2",
|
||||
"pako": "^1.0.11",
|
||||
"whacko": "^0.19.1",
|
||||
"xml-js": "^1.6.11",
|
||||
|
||||
@@ -8,10 +8,8 @@ const moment = require('moment');
|
||||
const axios = require('axios');
|
||||
const leancloud = require('../utils/leancloud')
|
||||
|
||||
function getscheme(req) {
|
||||
return req.headers['x-forwarded-proto'] || req.protocol;
|
||||
}
|
||||
|
||||
// TODO 迁移到leancloud
|
||||
function getuserinfo(headers) {
|
||||
if (!headers)
|
||||
return undefined
|
||||
@@ -43,10 +41,9 @@ async function updateDatabase() {
|
||||
}
|
||||
|
||||
/* GET users listing. */
|
||||
// TODO TG代理 日志生成
|
||||
router.get('/', async function (req, res, next) {
|
||||
const database = await updateDatabase();
|
||||
leancloud.add('SubAccess',{
|
||||
leancloud.add('SubAccess', {
|
||||
ip: req.ip,
|
||||
ua: req.headers['user-agent'],
|
||||
user: req.query.user,
|
||||
@@ -74,7 +71,8 @@ router.get('/', async function (req, res, next) {
|
||||
res.status(404).send('Not Found 找不到这种订阅类型');
|
||||
}
|
||||
} else {
|
||||
const path = getscheme(req) + '://' + req.headers.host + req.originalUrl;
|
||||
const path = req.protocol + '://' + req.headers.host + req.originalUrl;
|
||||
const tgproxys = database.telegram;
|
||||
const ctypes = Object.keys(database.suburl)
|
||||
let ret = {}
|
||||
for (key of ctypes) {
|
||||
@@ -82,7 +80,7 @@ router.get('/', async function (req, res, next) {
|
||||
ret[key] = getuserinfo(headers)
|
||||
// ret[key] = getuserinfotxt(getuserinfo(headers))
|
||||
}
|
||||
res.render('airportsub', {ret, path, expire: userinfo.expire});
|
||||
res.render('airportsub', {ret, path, tgproxys, expire: userinfo.expire});
|
||||
}
|
||||
} else {
|
||||
res.send('您的订阅已过期,请联系管理员');
|
||||
|
||||
@@ -6,10 +6,6 @@ const list = [bilibili, mgtv, tencentvideo, youku, iqiyi];
|
||||
const memory = require('../utils/memory')
|
||||
const leancloud = require('../utils/leancloud')
|
||||
|
||||
function getscheme(req) {
|
||||
return req.headers['x-forwarded-proto'] || req.protocol;
|
||||
}
|
||||
|
||||
async function build_response(url, req) {
|
||||
try {
|
||||
await axios.get(url)
|
||||
@@ -45,7 +41,7 @@ router.get('/', async function (req, res, next) {
|
||||
//检查是否包含URL参数
|
||||
if (!req.query.url) {
|
||||
const urls = [mgtv.example_urls[0], bilibili.example_urls[0], tencentvideo.example_urls[0], youku.example_urls[0], iqiyi.example_urls[0]];
|
||||
const path = getscheme(req) + '://' + req.headers.host + req.originalUrl;
|
||||
const path = req.protocol + '://' + req.headers.host + req.originalUrl;
|
||||
res.render('danmaku', {path, urls});
|
||||
} else {
|
||||
const url = req.query.url;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
/* GET users listing. */
|
||||
router.get('/', function(req, res, next) {
|
||||
res.send('respond with a resource');
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
8
schedule/schedule.js
Normal file
8
schedule/schedule.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const cron = require("node-cron");
|
||||
const leancloud = require("../utils/leancloud");
|
||||
|
||||
|
||||
cron.schedule('* * * * *', () => {
|
||||
// leancloud.add('Schedule',{})
|
||||
console.log("running a task every minute");
|
||||
});
|
||||
@@ -63,18 +63,6 @@ describe('App', () => {
|
||||
}
|
||||
|
||||
});
|
||||
describe('users modules', () => {
|
||||
it('should GET the users response', (done) => {
|
||||
chai.request(app)
|
||||
.get('/users')
|
||||
.end((err, res) => {
|
||||
res.should.have.status(200);
|
||||
res.text.should.equal('respond with a resource');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond status 404', (done) => {
|
||||
chai.request(app)
|
||||
.get('/wrongUrl')
|
||||
|
||||
@@ -39,7 +39,6 @@ async function danmakuQuery(date) {
|
||||
return await query.count()
|
||||
}
|
||||
|
||||
//TODO 订阅access.log
|
||||
function add(className,obj) {
|
||||
const classInstance = AV.Object.extend(className);
|
||||
const record = new classInstance();
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
相关软件<a href="/sub/download">下载链接</a><br>
|
||||
</p>
|
||||
|
||||
<p class="card-heading">Telegram 代理</p>
|
||||
<h3 class="card-heading">Telegram 代理:</h3>
|
||||
<p>
|
||||
<a href="tg://proxy?server=vipserv.ccloud.live&port=443&secret=dddd561961fea026e517764b084bd64072">域名</a>
|
||||
<a href="tg://proxy?server=167.235.77.32&port=443&secret=dddd561961fea026e517764b084bd64072">IPV4</a>
|
||||
<a href="tg://proxy?server=2a01:4f8:1c1e:eeb6::1&port=443&secret=dddd561961fea026e517764b084bd64072">IPV6</a>
|
||||
<% for (const tgproxy of tgproxys) { %>
|
||||
<a href="<%= tgproxy.url %>"><%= tgproxy.name %></a>
|
||||
<% } %>
|
||||
</p>
|
||||
|
||||
<h3>Your Subscribe:</h3>
|
||||
|
||||
Reference in New Issue
Block a user