mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
fix: 获取推荐412(#182)
This commit is contained in:
parent
664e33b3a6
commit
223a6e13c9
2
.github/workflows/pkg.yml
vendored
2
.github/workflows/pkg.yml
vendored
@ -2,8 +2,6 @@ name: "Package Node.js project into an executable"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "lib/**"
|
||||
- "*.js"
|
||||
|
||||
@ -30,6 +30,7 @@ module.exports = Object.freeze({
|
||||
SPACE_MYINFO: 'https://api.bilibili.com/x/space/myinfo',
|
||||
TAG_INFO: 'https://api.bilibili.com/x/tag/info',
|
||||
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_NEW: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new',
|
||||
WEB_INTERFACE_CARD: 'https://api.bilibili.com/x/web-interface/card',
|
||||
|
||||
@ -888,27 +888,38 @@ const bili_client = {
|
||||
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]>>}
|
||||
*/
|
||||
async getTopRcmd() {
|
||||
const
|
||||
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 [];
|
||||
}
|
||||
return this._getTopRcmd.run()
|
||||
},
|
||||
/**
|
||||
* 分享视频
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "node main.js start",
|
||||
"test": "node test/index.js",
|
||||
"clear": "node main.js clear",
|
||||
"check": "node main.js check",
|
||||
"update": "node main.js update",
|
||||
|
||||
8
test/api.test.js
Normal file
8
test/api.test.js
Normal 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
12
test/index.js
Normal 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}`))
|
||||
Loading…
Reference in New Issue
Block a user