fix: 获取推荐412(#182)

This commit is contained in:
shanmite 2022-08-22 20:58:12 +08:00
parent 664e33b3a6
commit 223a6e13c9
6 changed files with 49 additions and 18 deletions

View File

@ -2,8 +2,6 @@ name: "Package Node.js project into an executable"
on: on:
push: push:
branches:
- main
paths: paths:
- "lib/**" - "lib/**"
- "*.js" - "*.js"

View File

@ -30,6 +30,7 @@ module.exports = Object.freeze({
SPACE_MYINFO: 'https://api.bilibili.com/x/space/myinfo', SPACE_MYINFO: 'https://api.bilibili.com/x/space/myinfo',
TAG_INFO: 'https://api.bilibili.com/x/tag/info', TAG_INFO: 'https://api.bilibili.com/x/tag/info',
TOP_RCMD: "https://api.bilibili.com/x/web-interface/index/top/rcmd", TOP_RCMD: "https://api.bilibili.com/x/web-interface/index/top/rcmd",
TOP_FEED_RCMD: "https://api.bilibili.com/x/web-interface/index/top/feed/rcmd",
TOPIC_SVR_TOPIC_HISTORY: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_history', TOPIC_SVR_TOPIC_HISTORY: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_history',
TOPIC_SVR_TOPIC_NEW: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new', TOPIC_SVR_TOPIC_NEW: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new',
WEB_INTERFACE_CARD: 'https://api.bilibili.com/x/web-interface/card', WEB_INTERFACE_CARD: 'https://api.bilibili.com/x/web-interface/card',

View File

@ -888,27 +888,38 @@ const bili_client = {
return true return true
} }
}, },
_getTopRcmd: new Line('获取推荐', [
() => new Promise((resolve) => {
send({
url: API.TOP_RCMD,
method: 'GET',
headers: {
"accept": 'application/json, text/plain, */*',
"cookie": GlobalVar.get("cookie") + ";buvid3=1"
},
success: res => resolve(res.body),
failure: err => resolve(err)
})
}),
() => get({
url: API.TOP_FEED_RCMD
})
], responseText => {
const res = strToJson(responseText);
if (res.code === 0) {
return [false, res.data.item.map(it => {
return [it.owner.mid, it.id];
}), "成功"];
} else {
return [true, [], `获取推荐失败\n${responseText}`];
}
}),
/** /**
* 获取推荐 * 获取推荐
* @returns {Promise<Array<[number, number]>>} * @returns {Promise<Array<[number, number]>>}
*/ */
async getTopRcmd() { async getTopRcmd() {
const return this._getTopRcmd.run()
responseText = await get(
{
url: API.TOP_RCMD,
}
),
res = strToJson(responseText);
if (res.code === 0) {
log.info('获取推荐', `成功`);
return res.data.item.map(it => {
return [it.owner.mid, it.id];
});
} else {
log.error('获取推荐', `获取推荐失败\n${responseText}`);
return [];
}
}, },
/** /**
* 分享视频 * 分享视频

View File

@ -5,6 +5,7 @@
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"start": "node main.js start", "start": "node main.js start",
"test": "node test/index.js",
"clear": "node main.js clear", "clear": "node main.js clear",
"check": "node main.js check", "check": "node main.js check",
"update": "node main.js update", "update": "node main.js update",

8
test/api.test.js Normal file
View File

@ -0,0 +1,8 @@
const assert = require('assert');
const bili_client = require("../lib/net/bili");
(async () => {
assert(await bili_client.getMyinfo())
assert.equal((await bili_client.getTopRcmd()).length, 10)
console.log("api.test ... ok!");
})()

12
test/index.js Normal file
View File

@ -0,0 +1,12 @@
const env = require("../lib/data/env");
const global_var = require("../lib/data/global_var");
const { log } = require('../lib/utils');
const fs = require('fs');
log._level = 1
env.init()
global_var.init(process.env["COOKIE"], 1)
fs.readdirSync(module.path)
.filter(file => file.endsWith(".test.js"))
.forEach(file => require(`${module.path}/${file}`))