refactor: replace node-fetch to got (#2937)
This commit is contained in:
parent
18a5195505
commit
3530e13508
|
|
@ -1,6 +1,7 @@
|
|||
const cheerio = require('cheerio');
|
||||
const cache = require('./cache');
|
||||
const fetch = require('node-fetch');
|
||||
const got = require('@/utils/got');
|
||||
const zlib = require('zlib');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const aid = ctx.params.aid;
|
||||
|
|
@ -10,8 +11,19 @@ module.exports = async (ctx) => {
|
|||
|
||||
const videoName = await cache.getVideoNameFromAid(ctx, aid);
|
||||
|
||||
const danmakuResponse = await fetch(`https://comment.bilibili.com/${cid}.xml`);
|
||||
const danmakuText = await danmakuResponse.text();
|
||||
const danmakuResponse = await got.get(`https://comment.bilibili.com/${cid}.xml`, {
|
||||
decompress: false,
|
||||
responseType: 'buffer',
|
||||
});
|
||||
|
||||
let danmakuText = danmakuResponse.body;
|
||||
|
||||
if ((danmakuText[0] & 0x0f) === 0x08) {
|
||||
danmakuText = await zlib.inflateSync(danmakuText);
|
||||
} else {
|
||||
danmakuText = await zlib.inflateRawSync(danmakuText);
|
||||
}
|
||||
|
||||
let danmakuList = [];
|
||||
const $ = cheerio.load(danmakuText, { xmlMode: true });
|
||||
$('d').each((index, item) => {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,6 @@
|
|||
"mailparser": "2.7.1",
|
||||
"markdown-it": "9.1.0",
|
||||
"module-alias": "2.2.1",
|
||||
"node-fetch": "2.6.0",
|
||||
"path-to-regexp": "3.0.0",
|
||||
"pidusage": "2.0.17",
|
||||
"plist": "3.0.1",
|
||||
|
|
|
|||
|
|
@ -7283,7 +7283,7 @@ node-abi@^2.7.0:
|
|||
dependencies:
|
||||
semver "^5.4.1"
|
||||
|
||||
node-fetch@2.6.0, node-fetch@^2.3.0:
|
||||
node-fetch@^2.3.0:
|
||||
version "2.6.0"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
|
||||
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
|
||||
|
|
|
|||
Loading…
Reference in New Issue