From 6ac462ae2c6aadbc71e80f9721246085d2bef5ab Mon Sep 17 00:00:00 2001 From: lyz05 <294068487@qq.com> Date: Wed, 9 Nov 2022 19:17:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E8=85=BE=E8=AE=AF=E8=A7=86=E9=A2=91=E3=80=81=E7=88=B1=E5=A5=87?= =?UTF-8?q?=E8=89=BA=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF=20fix:=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=E8=BF=94=E5=9B=9EObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/airportsub.js | 1 + routes/api/iqiyi.js | 8 ++------ routes/api/tencentvideo.js | 17 +++++++++++++---- routes/danmaku.js | 2 +- test/App.test.js | 2 +- utils/leancloud.js | 6 ++++-- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/routes/airportsub.js b/routes/airportsub.js index 229988d..acf9ea0 100644 --- a/routes/airportsub.js +++ b/routes/airportsub.js @@ -42,6 +42,7 @@ async function updateDatabase() { } /* GET users listing. */ +// TODO TG代理 日志生成 router.get('/', async function (req, res, next) { const database = await updateDatabase(); if (req.query.user) { diff --git a/routes/api/iqiyi.js b/routes/api/iqiyi.js index 7f999fb..616fac8 100644 --- a/routes/api/iqiyi.js +++ b/routes/api/iqiyi.js @@ -62,10 +62,8 @@ function Iqiyi() { const json = await xml2js.parseStringPromise(xml) // console.log(json) global.gc() - for (const entry of json.danmu.data[0].entry) { - if (!entry.list[0].bulletInfo) - continue - for (const bulletInfo of entry.list[0].bulletInfo){ + for (const entry of json.danmu.data[0].entry??[]) { + for (const bulletInfo of entry.list[0].bulletInfo??[]){ // console.log(bulletInfo) const content = JSON.parse(JSON.stringify(content_template)); content.timepoint = bulletInfo['showTime'][0]//showTime @@ -76,8 +74,6 @@ function Iqiyi() { } } memory() - // $('bulletInfo').each(function () { - // }) } contents = make_response(contents) return contents diff --git a/routes/api/tencentvideo.js b/routes/api/tencentvideo.js index 2304d7b..d4d8213 100644 --- a/routes/api/tencentvideo.js +++ b/routes/api/tencentvideo.js @@ -28,7 +28,14 @@ function Tencentvideo() { let res = await axios.get(url); const $ = whacko.load(res.data, null, false); this.title = $("title")[0].children[0].data; - res = await axios.get(api_danmaku_base + vid); + try { + res = await axios.get(api_danmaku_base + vid); + } catch (e) { + if (e.response.status === 404) { + this.error_msg = '好像没有弹幕哦' + return + } else throw e + } let promises = [] let list = Object.values(res.data.segment_index) @@ -61,12 +68,14 @@ function Tencentvideo() { this.work = async (url) => { const promises = await this.resolve(url); - console.log(this.name, 'api lens:', promises.length) - this.content = await this.parse(promises); + if (!this.error_msg) { + console.log(this.name, 'api lens:', promises.length) + this.content = await this.parse(promises) + } return { title: this.title, content: this.content, - msg: 'ok' + msg: this.error_msg ? this.error_msg : 'ok' } } diff --git a/routes/danmaku.js b/routes/danmaku.js index 3892bf5..4a3d5e3 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -38,7 +38,7 @@ async function build_response(url,req) { ret = await fc.work(url) } catch (e) { console.log(e) - leancloud.danmakuErrorAdd({ip: getClientIp(req), url: url, error: e}) + leancloud.danmakuErrorAdd({ip: getClientIp(req), url: url, err: e}) return {msg: '弹幕解析过程中程序报错退出,请等待管理员修复!或者换条链接试试!'} } return ret diff --git a/test/App.test.js b/test/App.test.js index 41110d7..5bdc8ce 100644 --- a/test/App.test.js +++ b/test/App.test.js @@ -101,7 +101,7 @@ describe('App', () => { }); }); }); - describe('airportsub modules',function (){ + describe('机场订阅模块',function (){ this.timeout(1000*5); it('接口不带参数测试', (done) =>{ chai.request(app) diff --git a/utils/leancloud.js b/utils/leancloud.js index 8ca94b7..e92b989 100644 --- a/utils/leancloud.js +++ b/utils/leancloud.js @@ -51,13 +51,15 @@ async function danmakuQuery(date) { } function danmakuErrorAdd(obj) { - const {ip, url, error} = obj; + let {ip, url, err} = obj; const DanmakuErrorObject = AV.Object.extend('DanmakuError'); const record = new DanmakuErrorObject(); record.set('remoteIP', ip); record.set('url', url); //TODO: 转换成object - record.set('error', JSON.stringify(error)); + err = JSON.stringify(err, Object.getOwnPropertyNames(err)) + err = JSON.parse(err) + record.set('err', err); record.save().then() }