diff --git a/routes/airportsub.js b/routes/airportsub.js index 840efc5..b793098 100644 --- a/routes/airportsub.js +++ b/routes/airportsub.js @@ -112,7 +112,7 @@ router.get('/cache', async function (req, res, next) { for (let i = 0; i < values.length; i++) { const res = values[i]; const key = Object.keys(database.suburl)[i] - messages.push({title: 'Upload', key, status: res.status}) + messages.push({title: 'Upload', key, status: res.res.status}) } res.json(messages); }) diff --git a/routes/api/bilibili.js b/routes/api/bilibili.js index ef468e7..cf4ade2 100644 --- a/routes/api/bilibili.js +++ b/routes/api/bilibili.js @@ -24,7 +24,7 @@ function Bilibili() { // 获取视频分P信息 const p = q.query.p || 1; // 判断是否为旧版av号 - var params = {}; + var params; if (url.indexOf('BV') !== -1) { params = {'bvid': path.slice(-1)[0]}; } else { @@ -72,7 +72,7 @@ function Bilibili() { } this.work = async (url) => { - urls = await this.resolve(url); + const urls = await this.resolve(url); console.log(this.name,'api lens:',urls.length); if (!this.error_msg) this.content = await this.parse(urls); diff --git a/routes/api/tencentvideo.js b/routes/api/tencentvideo.js index fa97b9c..2c66e7f 100644 --- a/routes/api/tencentvideo.js +++ b/routes/api/tencentvideo.js @@ -60,7 +60,7 @@ function Tencentvideo() { } this.work = async (url) => { - promises = await this.resolve(url); + const promises = await this.resolve(url); console.log(this.name, 'api lens:', promises.length) this.content = await this.parse(promises); return { diff --git a/routes/danmaku.js b/routes/danmaku.js index 9569d41..cc540c7 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -1,7 +1,7 @@ const express = require('express'); const axios = require('axios'); const router = express.Router(); -const { bilibili, mgtv, tencentvideo, youku, iqiyi } = require('./api/base'); +const {bilibili, mgtv, tencentvideo, youku, iqiyi} = require('./api/base'); const list = [bilibili, mgtv, tencentvideo, youku, iqiyi]; const memory = require('../utils/memory') @@ -11,10 +11,10 @@ function getscheme(req) { async function build_response(url) { try { - const res = await axios.get(url) - } catch (error) { - console.log(error) - return {'msg': '传入的链接非法!请检查链接是否能在浏览器正常打开'} + await axios.get(url) + } catch (e) { + console.log(e) + return {msg: '传入的链接非法!请检查链接是否能在浏览器正常打开'} } var fc = undefined for (var item of list) { @@ -25,7 +25,14 @@ async function build_response(url) { if (fc === undefined) { return {'msg': '不支持的视频网址'} } - return await fc.work(url) + let ret; + try { + ret = await fc.work(url) + } catch (e) { + console.log(e) + return {msg: '弹幕解析过程中程序报错退出,请等待管理员修复!或者换条链接试试!'} + } + return ret } /* GET home page. */ diff --git a/test/App.test.js b/test/App.test.js index 645ad65..19d0f12 100644 --- a/test/App.test.js +++ b/test/App.test.js @@ -4,12 +4,13 @@ let app = require('../app'); const { bilibili, mgtv, tencentvideo, youku, iqiyi } = require('../routes/api/base'); const list = [bilibili, mgtv, tencentvideo, youku, iqiyi]; +let should = chai.should(); chai.use(chaiHttp); describe('App', () => { describe('弹幕解析模块测试', function () { - this.timeout(1000*60); + this.timeout(1000*30); it('主页测试', (done) => { chai.request(app) .get('/') @@ -76,7 +77,66 @@ describe('App', () => { }); }); }); - describe('airportsub modules',()=>{ - + describe('airportsub modules',function (){ + this.timeout(1000*5); + it('接口不带参数测试', (done) =>{ + chai.request(app) + .get('/sub') + .end((err,res) => { + res.should.have.status(400); + done(); + }); + }); + it('接口错误参数测试', (done) =>{ + chai.request(app) + .get('/sub?abc=123') + .end((err,res) => { + res.should.have.status(400); + done(); + }); + }); + it('接口带user参数测试', (done) =>{ + chai.request(app) + .get('/sub?user=congcong') + .end((err,res) => { + res.should.have.status(200); + done(); + }); + }); + it('接口错误user参数测试', (done) =>{ + chai.request(app) + .get('/sub?user=123') + .end((err,res) => { + res.should.have.status(404); + done(); + }); + }); + it('接口带user与ctype参数测试', (done) =>{ + chai.request(app) + .get('/sub?user=congcong&ctype=v2ray') + .end((err,res) => { + res.should.have.status(200); + done(); + }); + }); + it('缓存测试', (done) =>{ + chai.request(app) + .get('/sub/cache') + .end((err,res) => { + res.should.have.status(200); + done(); + }); + }); + it('软件下载测试', (done) =>{ + chai.request(app) + .get('/sub/download') + .end((err,res) => { + res.should.have.status(200); + res.text.should.have.string('clash'); + res.text.should.have.string('v2ray'); + res.text.should.have.string('shadowsocks'); + done(); + }); + }); }); }); \ No newline at end of file