yz-yuki-plugin 2.0.4-9 → 2.0.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.puppeteerrc.cjs +1 -1
- package/CHANGELOG.md +4 -0
- package/README.md +19 -3
- package/defaultConfig/bilibili/config.yaml +7 -3
- package/defaultConfig/help/help.yaml +51 -51
- package/defaultConfig/weibo/config.yaml +2 -2
- package/lib/apps/bilibili.js +88 -84
- package/lib/apps/help.js +3 -3
- package/lib/apps/version.js +4 -4
- package/lib/apps/weibo.js +47 -47
- package/lib/components/dynamic/Account.js +3 -3
- package/lib/components/dynamic/Content.js +2 -2
- package/lib/components/dynamic/Footer.js +3 -3
- package/lib/components/dynamic/LogoText.js +2 -2
- package/lib/components/dynamic/MainPage.js +2 -2
- package/lib/components/loginQrcode/Page.js +1 -1
- package/lib/index.js +7 -9
- package/lib/models/bilibili/bilibili.api.d.ts +4 -4
- package/lib/models/bilibili/bilibili.api.js +13 -13
- package/lib/models/bilibili/bilibili.get.web.data.js +32 -18
- package/lib/models/bilibili/bilibili.models.d.ts +9 -9
- package/lib/models/bilibili/bilibili.models.js +248 -192
- package/lib/models/bilibili/bilibili.query.d.ts +5 -5
- package/lib/models/bilibili/bilibili.query.js +135 -114
- package/lib/models/bilibili/bilibili.task.d.ts +2 -2
- package/lib/models/bilibili/bilibili.task.js +46 -44
- package/lib/models/bilibili/bilibili.ticket.js +3 -3
- package/lib/models/bilibili/bilibili.wbi.js +10 -12
- package/lib/models/help/help.js +2 -2
- package/lib/models/weibo/weibo.api.js +2 -2
- package/lib/models/weibo/weibo.get.web.data.js +6 -7
- package/lib/models/weibo/weibo.query.d.ts +4 -4
- package/lib/models/weibo/weibo.query.js +66 -69
- package/lib/models/weibo/weibo.task.d.ts +1 -1
- package/lib/models/weibo/weibo.task.js +43 -38
- package/lib/utils/config.d.ts +2 -2
- package/lib/utils/config.js +8 -8
- package/lib/utils/paths.js +1 -1
- package/lib/utils/puppeteer.render.js +20 -22
- package/package.json +8 -4
- package/resources/css/dynamic/Account.css +1 -1
- package/resources/css/dynamic/Content.box.grid.4.css +2 -2
- package/resources/css/dynamic/Content.box.grid.9.css +2 -2
- package/resources/css/dynamic/Content.css +1 -1
- package/resources/css/dynamic/Footer.css +1 -1
- package/resources/css/dynamic/ForwardContent.css +1 -1
- package/resources/css/dynamic/LogoText.css +2 -2
- package/resources/css/dynamic/MainPage.css +4 -5
- package/resources/css/help/help.css +18 -11
- package/resources/css/loginQrcode/Page.css +7 -11
- package/resources/css/version/version.css +8 -6
|
@@ -12,9 +12,9 @@ class BiliTask {
|
|
|
12
12
|
privateKey;
|
|
13
13
|
e;
|
|
14
14
|
constructor(e) {
|
|
15
|
-
this.taskName =
|
|
16
|
-
this.groupKey =
|
|
17
|
-
this.privateKey =
|
|
15
|
+
this.taskName = 'biliTask';
|
|
16
|
+
this.groupKey = 'Yz:yuki:bili:upPush:group:';
|
|
17
|
+
this.privateKey = 'Yz:yuki:bili:upPush:private:';
|
|
18
18
|
}
|
|
19
19
|
async hendleEventDynamicData(uid, count = 0) {
|
|
20
20
|
const resp = await new BiliGetWebData().getBiliDynamicListDataByUid(uid);
|
|
@@ -40,13 +40,12 @@ class BiliTask {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
async runTask() {
|
|
43
|
-
let biliConfigData = await Config.getUserConfig(
|
|
44
|
-
let biliPushData = await Config.getUserConfig(
|
|
45
|
-
let interval = biliConfigData
|
|
46
|
-
let lastLiveStatus = JSON.parse(await Redis.get("yuki:bililive:lastlivestatus")) || {};
|
|
43
|
+
let biliConfigData = await Config.getUserConfig('bilibili', 'config');
|
|
44
|
+
let biliPushData = await Config.getUserConfig('bilibili', 'push');
|
|
45
|
+
let interval = biliConfigData?.interval || 7200;
|
|
47
46
|
const uidMap = new Map(); // 存放group 和 private 对应所属 uid 与推送信息的映射
|
|
48
47
|
const dynamicList = {}; // 存放获取的所有动态,键为 uid,值为动态数组
|
|
49
|
-
await this.processBiliData(biliPushData, uidMap, dynamicList
|
|
48
|
+
await this.processBiliData(biliPushData, biliConfigData, uidMap, dynamicList);
|
|
50
49
|
let now = Date.now() / 1000; // 时间戳(秒)
|
|
51
50
|
await this.pushDynamicMessages(uidMap, dynamicList, now, interval, biliConfigData);
|
|
52
51
|
}
|
|
@@ -57,9 +56,11 @@ class BiliTask {
|
|
|
57
56
|
* @param dynamicList 动态列表
|
|
58
57
|
* @param lastLiveStatus 最后直播状态
|
|
59
58
|
*/
|
|
60
|
-
async processBiliData(biliPushData, uidMap, dynamicList
|
|
59
|
+
async processBiliData(biliPushData, biliConfigData, uidMap, dynamicList) {
|
|
60
|
+
let getDataRandomDelay = biliConfigData?.getDataRandomDelay || 8000; // 获取相邻up动态数据的随机延时间隔
|
|
61
61
|
const requestedDataOfUids = new Map(); // 存放已请求的 uid 映射
|
|
62
|
-
for (let chatType in biliPushData) {
|
|
62
|
+
for (let chatType in biliPushData) {
|
|
63
|
+
// 遍历 group 和 private
|
|
63
64
|
if (!uidMap.has(chatType)) {
|
|
64
65
|
uidMap.set(chatType, new Map());
|
|
65
66
|
}
|
|
@@ -67,9 +68,6 @@ class BiliTask {
|
|
|
67
68
|
for (let chatId in biliPushData[chatType]) {
|
|
68
69
|
const subUpsOfChat = Array.prototype.slice.call(biliPushData[chatType][chatId] || []);
|
|
69
70
|
for (let subInfoOfup of subUpsOfChat) {
|
|
70
|
-
if (!lastLiveStatus[subInfoOfup.uid]) {
|
|
71
|
-
lastLiveStatus[subInfoOfup.uid] = 0;
|
|
72
|
-
}
|
|
73
71
|
let resp;
|
|
74
72
|
// 检查是否已经请求过该 uid
|
|
75
73
|
if (requestedDataOfUids.has(subInfoOfup.uid)) {
|
|
@@ -101,7 +99,7 @@ class BiliTask {
|
|
|
101
99
|
const bot_id = subInfoOfup.bot_id || [];
|
|
102
100
|
const { name, type } = subInfoOfup;
|
|
103
101
|
chatTypeMap.set(subInfoOfup.uid, { chatIds, bot_id, upName: name, type });
|
|
104
|
-
await this.randomDelay(
|
|
102
|
+
await this.randomDelay(2000, getDataRandomDelay); // 随机延时
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
}
|
|
@@ -133,7 +131,7 @@ class BiliTask {
|
|
|
133
131
|
logger.debug(`超过间隔,跳过 [ ${author?.name} : ${author?.mid} ] ${author?.pub_time} 的动态`);
|
|
134
132
|
continue;
|
|
135
133
|
} // 如果超过推送时间间隔,跳过当前循环
|
|
136
|
-
if (dynamicItem.type ===
|
|
134
|
+
if (dynamicItem.type === 'DYNAMIC_TYPE_FORWARD' && !biliConfigData.pushTransmit)
|
|
137
135
|
continue; // 如果关闭了转发动态的推送,跳过当前循环
|
|
138
136
|
willPushDynamicList.push(dynamicItem);
|
|
139
137
|
}
|
|
@@ -158,11 +156,11 @@ class BiliTask {
|
|
|
158
156
|
async sendDynamic(chatId, bot_id, upName, pushDynamicData, biliConfigData, chatType) {
|
|
159
157
|
const id_str = pushDynamicData.id_str;
|
|
160
158
|
let sended, markKey;
|
|
161
|
-
if (chatType ===
|
|
159
|
+
if (chatType === 'group') {
|
|
162
160
|
markKey = this.groupKey;
|
|
163
161
|
sended = await Redis.get(`${markKey}${chatId}:${id_str}`);
|
|
164
162
|
}
|
|
165
|
-
else if (chatType ===
|
|
163
|
+
else if (chatType === 'private') {
|
|
166
164
|
markKey = this.privateKey;
|
|
167
165
|
sended = await Redis.get(`${markKey}${chatId}:${id_str}`);
|
|
168
166
|
}
|
|
@@ -172,54 +170,54 @@ class BiliTask {
|
|
|
172
170
|
const { data, uid } = await BiliQuery.formatDynamicData(pushDynamicData); // 处理动态数据
|
|
173
171
|
const extentData = { ...data };
|
|
174
172
|
const eval2 = eval;
|
|
175
|
-
let banWords = eval2(`/${biliConfigData.banWords.join(
|
|
173
|
+
let banWords = eval2(`/${biliConfigData.banWords.join('|')}/g`); // 构建屏蔽关键字正则表达式
|
|
176
174
|
if (new RegExp(banWords).test(`${extentData?.title}${extentData?.content}`)) {
|
|
177
|
-
return
|
|
175
|
+
return 'return'; // 如果动态包含屏蔽关键字,则直接返回
|
|
178
176
|
}
|
|
179
177
|
let boxGrid = !!biliConfigData.boxGrid === false ? false : true; // 是否启用九宫格样式,默认为 true
|
|
180
178
|
let isSplit = !!biliConfigData.isSplit === false ? false : true; // 是否启用分片截图,默认为 true
|
|
181
179
|
let style = isSplit ? '' : `.unfold { max-height: ${biliConfigData?.noSplitHeight ?? 7500}px; }`; // 不启用分片截图模式的样式
|
|
182
|
-
let splitHeight = biliConfigData?.splitHeight
|
|
180
|
+
let splitHeight = biliConfigData?.splitHeight || 8000; // 分片截图高度,默认 8000, 单位 px,启用分片截图时生效
|
|
183
181
|
const urlQrcodeData = await QRCode.toDataURL(extentData?.url);
|
|
184
182
|
let renderData = this.buildRenderData(extentData, urlQrcodeData, boxGrid);
|
|
185
183
|
const ScreenshotOptionsData = {
|
|
186
184
|
addStyle: style,
|
|
187
|
-
header: {
|
|
185
|
+
header: { Referer: 'https://space.bilibili.com/' },
|
|
188
186
|
isSplit: isSplit,
|
|
189
187
|
modelName: 'bilibili',
|
|
190
188
|
SOptions: {
|
|
191
189
|
type: 'webp',
|
|
192
|
-
quality: 98
|
|
190
|
+
quality: 98
|
|
193
191
|
},
|
|
194
192
|
saveHtmlfile: false,
|
|
195
|
-
pageSplitHeight: splitHeight
|
|
193
|
+
pageSplitHeight: splitHeight
|
|
196
194
|
};
|
|
197
195
|
let imgs = await this.renderDynamicCard(uid, renderData, ScreenshotOptionsData);
|
|
198
196
|
if (!imgs)
|
|
199
197
|
return;
|
|
200
|
-
Redis.set(`${markKey}${chatId}:${id_str}`,
|
|
201
|
-
(logger ?? Bot.logger)?.mark(
|
|
198
|
+
Redis.set(`${markKey}${chatId}:${id_str}`, '1', { EX: 3600 * 10 }); // 设置已发送标记
|
|
199
|
+
(logger ?? Bot.logger)?.mark('优纪插件:B站动态执行推送');
|
|
202
200
|
for (let i = 0; i < imgs.length; i++) {
|
|
203
201
|
const image = imgs[i];
|
|
204
202
|
await this.sendMessage(chatId, bot_id, chatType, Segment.image(image));
|
|
205
203
|
await this.randomDelay(1000, 2000); // 随机延时1-2秒
|
|
206
204
|
}
|
|
207
|
-
await new Promise(
|
|
205
|
+
await new Promise(resolve => setTimeout(resolve, 1000)); // 休眠1秒
|
|
208
206
|
}
|
|
209
207
|
else {
|
|
210
208
|
const dynamicMsg = await BiliQuery.formatTextDynamicData(upName, pushDynamicData, false, biliConfigData); // 构建图文动态消息
|
|
211
|
-
Redis.set(`${markKey}${chatId}:${id_str}`,
|
|
212
|
-
if (dynamicMsg ==
|
|
213
|
-
return
|
|
209
|
+
Redis.set(`${markKey}${chatId}:${id_str}`, '1', { EX: 3600 * 10 }); // 设置已发送标记
|
|
210
|
+
if (dynamicMsg == 'continue') {
|
|
211
|
+
return 'return'; // 如果动态消息构建失败,则直接返回
|
|
214
212
|
}
|
|
215
213
|
if (biliConfigData.banWords.length > 0) {
|
|
216
|
-
const banWords = new RegExp(biliConfigData.banWords.join(
|
|
217
|
-
if (banWords.test(dynamicMsg.join(
|
|
218
|
-
return
|
|
214
|
+
const banWords = new RegExp(biliConfigData.banWords.join('|'), 'g'); // 构建屏蔽关键字正则表达式
|
|
215
|
+
if (banWords.test(dynamicMsg.join(''))) {
|
|
216
|
+
return 'return'; // 如果动态消息包含屏蔽关键字,则直接返回
|
|
219
217
|
}
|
|
220
218
|
}
|
|
221
219
|
await this.sendMessage(chatId, bot_id, chatType, dynamicMsg);
|
|
222
|
-
await new Promise(
|
|
220
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
223
221
|
}
|
|
224
222
|
}
|
|
225
223
|
/**
|
|
@@ -230,10 +228,10 @@ class BiliTask {
|
|
|
230
228
|
* @returns 渲染数据
|
|
231
229
|
*/
|
|
232
230
|
buildRenderData(extentData, urlQrcodeData, boxGrid) {
|
|
233
|
-
if (extentData.orig &&
|
|
231
|
+
if (extentData.orig && extentData.orig.length !== 0) {
|
|
234
232
|
return {
|
|
235
233
|
data: {
|
|
236
|
-
appName:
|
|
234
|
+
appName: 'bilibili',
|
|
237
235
|
boxGrid: boxGrid,
|
|
238
236
|
type: extentData?.type,
|
|
239
237
|
face: extentData?.face,
|
|
@@ -256,7 +254,7 @@ class BiliTask {
|
|
|
256
254
|
title: extentData?.orig?.data?.title,
|
|
257
255
|
content: extentData?.orig?.data?.content,
|
|
258
256
|
pics: extentData?.orig?.data?.pics,
|
|
259
|
-
category: extentData?.orig?.data?.category
|
|
257
|
+
category: extentData?.orig?.data?.category
|
|
260
258
|
}
|
|
261
259
|
}
|
|
262
260
|
}
|
|
@@ -265,7 +263,7 @@ class BiliTask {
|
|
|
265
263
|
else {
|
|
266
264
|
return {
|
|
267
265
|
data: {
|
|
268
|
-
appName:
|
|
266
|
+
appName: 'bilibili',
|
|
269
267
|
boxGrid: boxGrid,
|
|
270
268
|
type: extentData?.type,
|
|
271
269
|
face: extentData?.face,
|
|
@@ -277,7 +275,7 @@ class BiliTask {
|
|
|
277
275
|
urlImgData: urlQrcodeData,
|
|
278
276
|
created: extentData?.created,
|
|
279
277
|
pics: extentData?.pics,
|
|
280
|
-
category: extentData?.category
|
|
278
|
+
category: extentData?.category
|
|
281
279
|
}
|
|
282
280
|
};
|
|
283
281
|
}
|
|
@@ -290,7 +288,7 @@ class BiliTask {
|
|
|
290
288
|
* @returns 图片数据
|
|
291
289
|
*/
|
|
292
290
|
async renderDynamicCard(uid, renderData, ScreenshotOptionsData) {
|
|
293
|
-
const dynamicMsg = await renderPage(uid,
|
|
291
|
+
const dynamicMsg = await renderPage(uid, 'MainPage', renderData, ScreenshotOptionsData); // 渲染动态卡片
|
|
294
292
|
if (dynamicMsg !== false) {
|
|
295
293
|
return dynamicMsg.img; // 缓存图片数据
|
|
296
294
|
}
|
|
@@ -306,14 +304,18 @@ class BiliTask {
|
|
|
306
304
|
* @param message 消息内容
|
|
307
305
|
*/
|
|
308
306
|
async sendMessage(chatId, bot_id, chatType, message) {
|
|
309
|
-
if (chatType ===
|
|
310
|
-
await (Bot[bot_id] ?? Bot)
|
|
307
|
+
if (chatType === 'group') {
|
|
308
|
+
await (Bot[bot_id] ?? Bot)
|
|
309
|
+
?.pickGroup(String(chatId))
|
|
310
|
+
.sendMsg(message) // 发送群聊
|
|
311
311
|
.catch((error) => {
|
|
312
312
|
(logger ?? Bot.logger)?.error(`群组[${chatId}]推送失败:${JSON.stringify(error)}`);
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
|
-
else if (chatType ===
|
|
316
|
-
await (Bot[bot_id] ?? Bot)
|
|
315
|
+
else if (chatType === 'private') {
|
|
316
|
+
await (Bot[bot_id] ?? Bot)
|
|
317
|
+
?.pickFriend(String(chatId))
|
|
318
|
+
.sendMsg(message)
|
|
317
319
|
.catch((error) => {
|
|
318
320
|
(logger ?? Bot.logger)?.error(`用户[${chatId}]推送失败:${JSON.stringify(error)}`);
|
|
319
321
|
}); // 发送好友私聊
|
|
@@ -325,7 +327,7 @@ class BiliTask {
|
|
|
325
327
|
* @param max 最大延时时间
|
|
326
328
|
*/
|
|
327
329
|
async randomDelay(min, max) {
|
|
328
|
-
await new Promise(
|
|
330
|
+
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * (max - min + 1) + min)));
|
|
329
331
|
}
|
|
330
332
|
}
|
|
331
333
|
|
|
@@ -22,10 +22,10 @@ async function getBiliTicket(csrf) {
|
|
|
22
22
|
const hexSign = hmacSha256('XgwSnGZ1p', `ts${ts}`);
|
|
23
23
|
const url = 'https://api.bilibili.com/bapis/bilibili.api.ticket.v1.Ticket/GenWebTicket';
|
|
24
24
|
const params = new URLSearchParams({
|
|
25
|
-
key_id: 'ec02',
|
|
26
|
-
hexsign: hexSign,
|
|
25
|
+
'key_id': 'ec02',
|
|
26
|
+
'hexsign': hexSign,
|
|
27
27
|
'context[ts]': String(ts),
|
|
28
|
-
csrf: csrf ?? '' // 使用空字符串代替null
|
|
28
|
+
'csrf': csrf ?? '' // 使用空字符串代替null
|
|
29
29
|
});
|
|
30
30
|
try {
|
|
31
31
|
const response = await fetch(`${url}?${params}`, {
|
|
@@ -2,15 +2,13 @@ import md5 from 'md5';
|
|
|
2
2
|
import fetch from 'node-fetch';
|
|
3
3
|
|
|
4
4
|
const mixinKeyEncTab = [
|
|
5
|
-
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
|
|
6
|
-
|
|
7
|
-
61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11,
|
|
8
|
-
36, 20, 34, 44, 52
|
|
5
|
+
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26,
|
|
6
|
+
17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11, 36, 20, 34, 44, 52
|
|
9
7
|
];
|
|
10
8
|
// 对 imgKey 和 subKey 进行字符顺序打乱编码
|
|
11
9
|
const getMixinKey = (orig) => mixinKeyEncTab
|
|
12
|
-
.map(
|
|
13
|
-
.join(
|
|
10
|
+
.map(n => orig[n])
|
|
11
|
+
.join('')
|
|
14
12
|
.slice(0, 32);
|
|
15
13
|
// 为请求参数进行 wbi 签名
|
|
16
14
|
function encWbi(params, img_key, sub_key) {
|
|
@@ -19,12 +17,12 @@ function encWbi(params, img_key, sub_key) {
|
|
|
19
17
|
// 按照 key 重排参数
|
|
20
18
|
const query = Object.keys(params)
|
|
21
19
|
.sort()
|
|
22
|
-
.map(
|
|
20
|
+
.map(key => {
|
|
23
21
|
// 过滤 value 中的 "!'()*" 字符
|
|
24
|
-
const value = params[key].toString().replace(chr_filter,
|
|
22
|
+
const value = params[key].toString().replace(chr_filter, '');
|
|
25
23
|
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
26
24
|
})
|
|
27
|
-
.join(
|
|
25
|
+
.join('&');
|
|
28
26
|
const wbi_sign = md5(query + mixin_key); // 计算 w_rid
|
|
29
27
|
//return query + "&w_rid=" + wbi_sign;
|
|
30
28
|
return {
|
|
@@ -38,12 +36,12 @@ async function getWbiKeys(headers, cookie) {
|
|
|
38
36
|
const res = await fetch('https://api.bilibili.com/x/web-interface/nav', {
|
|
39
37
|
headers: {
|
|
40
38
|
// SESSDATA 字段
|
|
41
|
-
Cookie: cookie,
|
|
39
|
+
'Cookie': cookie,
|
|
42
40
|
'User-Agent': headers['User-Agent'],
|
|
43
|
-
Referer: 'https://www.bilibili.com/' //对于直接浏览器调用可能不适用
|
|
41
|
+
'Referer': 'https://www.bilibili.com/' //对于直接浏览器调用可能不适用
|
|
44
42
|
}
|
|
45
43
|
});
|
|
46
|
-
const { data: { wbi_img: { img_url, sub_url }
|
|
44
|
+
const { data: { wbi_img: { img_url, sub_url } } } = (await res.json());
|
|
47
45
|
return {
|
|
48
46
|
img_key: img_url.slice(img_url.lastIndexOf('/') + 1, img_url.lastIndexOf('.')),
|
|
49
47
|
sub_key: sub_url.slice(sub_url.lastIndexOf('/') + 1, sub_url.lastIndexOf('.'))
|
package/lib/models/help/help.js
CHANGED
|
@@ -4,7 +4,7 @@ class Help {
|
|
|
4
4
|
e;
|
|
5
5
|
model;
|
|
6
6
|
constructor(e) {
|
|
7
|
-
this.model =
|
|
7
|
+
this.model = 'help';
|
|
8
8
|
this.e = e;
|
|
9
9
|
}
|
|
10
10
|
static async get(e) {
|
|
@@ -12,7 +12,7 @@ class Help {
|
|
|
12
12
|
return await helpData.getData();
|
|
13
13
|
}
|
|
14
14
|
async getData() {
|
|
15
|
-
let helpData = Config.getDefaultConfig(
|
|
15
|
+
let helpData = Config.getDefaultConfig('help', 'help');
|
|
16
16
|
return helpData;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -2,7 +2,7 @@ class WeiboApi {
|
|
|
2
2
|
static WEIBO_API = {
|
|
3
3
|
weiboGetIndex: 'https://m.weibo.cn/api/container/getIndex',
|
|
4
4
|
//通过关键词${upKeyword}搜索博主 parama = { q: 'Keyword'},
|
|
5
|
-
weiboAjaxSearch: 'https://weibo.com/ajax/side/search'
|
|
5
|
+
weiboAjaxSearch: 'https://weibo.com/ajax/side/search'
|
|
6
6
|
};
|
|
7
7
|
/**统一设置header */
|
|
8
8
|
static WEIBO_HEADERS = {
|
|
@@ -14,7 +14,7 @@ class WeiboApi {
|
|
|
14
14
|
'Sec-fetch-mode': 'same-origin',
|
|
15
15
|
'Sec-fetch-site': 'same-origin',
|
|
16
16
|
'Upgrade-insecure-requests': '1',
|
|
17
|
-
'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
|
|
17
|
+
'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -5,8 +5,7 @@ import { WeiboQuery } from './weibo.query.js';
|
|
|
5
5
|
|
|
6
6
|
class WeiboGetWebData {
|
|
7
7
|
e;
|
|
8
|
-
constructor(e) {
|
|
9
|
-
}
|
|
8
|
+
constructor(e) { }
|
|
10
9
|
/**通过uid获取博主信息 */
|
|
11
10
|
async getBloggerInfo(target) {
|
|
12
11
|
const param = { containerid: '100505' + target };
|
|
@@ -14,7 +13,7 @@ class WeiboGetWebData {
|
|
|
14
13
|
url.search = new URLSearchParams(param).toString();
|
|
15
14
|
const resp = await axios.get(url.toString(), {
|
|
16
15
|
timeout: 10000,
|
|
17
|
-
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
|
|
16
|
+
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
|
|
18
17
|
});
|
|
19
18
|
return resp;
|
|
20
19
|
}
|
|
@@ -22,12 +21,12 @@ class WeiboGetWebData {
|
|
|
22
21
|
async searchBloggerInfo(keyword) {
|
|
23
22
|
const url = WeiboApi.WEIBO_API.weiboAjaxSearch;
|
|
24
23
|
const params = {
|
|
25
|
-
q: keyword
|
|
24
|
+
q: keyword
|
|
26
25
|
};
|
|
27
26
|
const resp = await axios.get(url, {
|
|
28
27
|
params,
|
|
29
28
|
timeout: 10000,
|
|
30
|
-
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://s.weibo.com' }
|
|
29
|
+
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://s.weibo.com' }
|
|
31
30
|
});
|
|
32
31
|
return resp;
|
|
33
32
|
}
|
|
@@ -36,11 +35,11 @@ class WeiboGetWebData {
|
|
|
36
35
|
const params = { containerid: '107603' + target };
|
|
37
36
|
const url = new URL(WeiboApi.WEIBO_API.weiboGetIndex);
|
|
38
37
|
url.search = new URLSearchParams(params).toString();
|
|
39
|
-
await new Promise(
|
|
38
|
+
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * (6500 - 1000 + 1) + 1000)));
|
|
40
39
|
try {
|
|
41
40
|
const response = await axios.get(url.toString(), {
|
|
42
41
|
timeout: 15000,
|
|
43
|
-
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
|
|
42
|
+
headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
|
|
44
43
|
});
|
|
45
44
|
const { ok, data, msg } = response.data;
|
|
46
45
|
if (!ok && msg !== '这里还没有内容') {
|
|
@@ -17,10 +17,10 @@ export declare class WeiboQuery {
|
|
|
17
17
|
};
|
|
18
18
|
}>;
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
* 动态内容富文本节点解析
|
|
21
|
+
* @param nodes - 动态内容富文本节点
|
|
22
|
+
* @returns 解析后的动态内容富文本
|
|
23
|
+
*/
|
|
24
24
|
static parseRichTextNodes: (nodes: any[] | string | any) => any;
|
|
25
25
|
/**
|
|
26
26
|
* 生成动态消息文字内容
|