yz-yuki-plugin 2.0.8-8 → 2.0.9-0
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/CHANGELOG.md +4 -0
- package/README.md +0 -3
- package/defaultConfig/bilibili/config.yaml +1 -0
- package/defaultConfig/help/help.yaml +0 -9
- package/defaultConfig/weibo/config.yaml +1 -0
- package/lib/apps/bilibili.js +36 -50
- package/lib/apps/weibo.js +19 -105
- package/lib/components/dynamic/Account.js +4 -4
- package/lib/components/dynamic/Content.js +4 -4
- package/lib/components/dynamic/Footer.js +4 -4
- package/lib/components/dynamic/ForwardContent.js +2 -2
- package/lib/components/dynamic/LogoText.js +2 -2
- package/lib/components/dynamic/MainPage.js +2 -2
- package/lib/components/help/Help.js +3 -3
- package/lib/components/loginQrcode/Page.js +2 -2
- package/lib/components/version/Version.js +2 -2
- package/lib/models/bilibili/bilibili.main.get.web.data.js +130 -59
- package/lib/models/bilibili/bilibili.main.query.js +16 -8
- package/lib/models/bilibili/bilibili.main.task.js +37 -11
- package/lib/models/bilibili/bilibili.risk.cookie.js +799 -0
- package/lib/models/weibo/weibo.main.api.js +7 -10
- package/lib/models/weibo/weibo.main.get.web.data.js +127 -69
- package/lib/models/weibo/weibo.main.task.js +14 -5
- package/lib/models/weibo/weibo.risk.cookie.js +979 -0
- package/package.json +5 -2
- package/resources/css/dynamic/MainPage.css +1 -1
- package/lib/models/bilibili/bilibili.main.models.js +0 -493
- package/lib/models/weibo/weibo.main.models.js +0 -347
|
@@ -8,7 +8,7 @@ class WeiboApi {
|
|
|
8
8
|
this.USER_AGENT = WeiboApi.WEIBO_USER_AGENT;
|
|
9
9
|
this.initialize();
|
|
10
10
|
}
|
|
11
|
-
static WEIBO_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
11
|
+
static WEIBO_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36';
|
|
12
12
|
//初始化User-Agent
|
|
13
13
|
async initialize() {
|
|
14
14
|
await this.initUserAgent();
|
|
@@ -22,25 +22,22 @@ class WeiboApi {
|
|
|
22
22
|
}
|
|
23
23
|
get WEIBO_API() {
|
|
24
24
|
return {
|
|
25
|
-
weiboGetIndex: 'https://m.weibo.cn/api/container/getIndex'
|
|
26
|
-
//通过关键词${upKeyword}搜索博主 parama = { q: 'Keyword'},
|
|
27
|
-
weiboAjaxSearch: 'https://weibo.com/ajax/side/search'
|
|
25
|
+
weiboGetIndex: 'https://m.weibo.cn/api/container/getIndex'
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
/**统一设置header */
|
|
31
29
|
get WEIBO_HEADERS() {
|
|
32
30
|
return {
|
|
33
31
|
'Accept': 'application/json, text/plain, */*',
|
|
34
|
-
'Accept-Language': 'zh-CN,en-US;q=0.5',
|
|
35
32
|
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'X-XSRF-TOKEN': '',
|
|
33
|
+
'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
34
|
+
'Connection': 'keep-alive',
|
|
39
35
|
'Sec-Fetch-Dest': 'empty',
|
|
40
36
|
'Sec-Fetch-Mode': 'cors',
|
|
41
37
|
'Sec-Fetch-Site': 'same-origin',
|
|
42
|
-
'
|
|
43
|
-
'
|
|
38
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
39
|
+
'MWeibo-Pwa': '1',
|
|
40
|
+
'User-Agent': this.USER_AGENT
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
43
|
get WEIBO_GET_X_CSRF_TOKEN_HEADERS() {
|
|
@@ -1,113 +1,171 @@
|
|
|
1
1
|
import WeiboApi from './weibo.main.api.js';
|
|
2
|
-
import { WeiboMainModels } from './weibo.main.models.js';
|
|
3
2
|
import { WeiboQuery } from './weibo.main.query.js';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import WeiboCookieManager from './weibo.risk.cookie.js';
|
|
4
|
+
import axioss from 'axios';
|
|
5
|
+
import { wrapper } from 'axios-cookiejar-support';
|
|
6
6
|
import lodash from 'lodash';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
10
|
-
let result = '';
|
|
11
|
-
for (let i = 0; i < length; i++) {
|
|
12
|
-
const randomIndex = randomInt(0, characters.length);
|
|
13
|
-
result += characters[randomIndex];
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
8
|
+
const axios = wrapper(axioss);
|
|
17
9
|
class WeiboWebDataFetcher {
|
|
18
10
|
e;
|
|
19
11
|
constructor(e) { }
|
|
20
12
|
/**通过uid获取博主信息 */
|
|
21
|
-
async getBloggerInfo(
|
|
22
|
-
const param = { containerid: '100505' +
|
|
13
|
+
async getBloggerInfo(uid) {
|
|
14
|
+
const param = { type: 'uid', value: `${uid}`, containerid: '100505' + `${uid}` };
|
|
23
15
|
const url = new URL(WeiboApi.WEIBO_API.weiboGetIndex);
|
|
24
16
|
url.search = new URLSearchParams(param).toString();
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
17
|
+
const jar = await WeiboCookieManager.getSessionCookieJar();
|
|
18
|
+
const X_XSRF_TOKEN = await WeiboCookieManager.getCookieValueByKeyFromString(jar, 'X-XSRF-TOKEN', url.toString());
|
|
19
|
+
// (1) 保存初始状态
|
|
20
|
+
const initialCookies = await new Promise((resolve, reject) => {
|
|
21
|
+
jar.store.getAllCookies((err, cookies) => {
|
|
22
|
+
if (err)
|
|
23
|
+
reject(err);
|
|
24
|
+
else
|
|
25
|
+
resolve(cookies || []);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
36
28
|
const resp = await axios(url.toString(), {
|
|
37
29
|
method: 'GET',
|
|
30
|
+
jar,
|
|
31
|
+
withCredentials: true,
|
|
38
32
|
timeout: 10000,
|
|
39
|
-
headers: lodash.merge(WeiboApi.WEIBO_HEADERS, {
|
|
33
|
+
headers: lodash.merge(WeiboApi.WEIBO_HEADERS, {
|
|
34
|
+
'Host': 'm.weibo.cn',
|
|
35
|
+
'X-XSRF-TOKEN': `${X_XSRF_TOKEN}`,
|
|
36
|
+
'Referer': `https://m.weibo.cn/u/${uid}`
|
|
37
|
+
})
|
|
40
38
|
});
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// (3) 获取请求完成后的 Cookie 状态
|
|
40
|
+
const updatedCookies = await new Promise((resolve, reject) => {
|
|
41
|
+
jar.store.getAllCookies((err, cookies) => {
|
|
42
|
+
if (err)
|
|
43
|
+
reject(err);
|
|
44
|
+
else
|
|
45
|
+
resolve(cookies || []);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
// 构建初始状态的 Map
|
|
49
|
+
const initialCookieMap = new Map(initialCookies.map(c => [`${c.key}:${c.domain}`, c]));
|
|
50
|
+
// 构建更新后的 Map
|
|
51
|
+
const updatedCookieMap = new Map(updatedCookies.map(c => [`${c.key}:${c.domain}`, c]));
|
|
52
|
+
// 比较两个 Map
|
|
53
|
+
for (const [key, updatedCookie] of updatedCookieMap.entries()) {
|
|
54
|
+
const initialCookie = initialCookieMap.get(key);
|
|
55
|
+
if (!initialCookie || initialCookie.value !== updatedCookie.value) {
|
|
56
|
+
console.log(`Weibo Cookie ${updatedCookie.key} was updated.`);
|
|
57
|
+
await WeiboCookieManager.saveCookiesToRedis(jar); // 更新同步到 Redis
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
return resp;
|
|
46
61
|
}
|
|
47
62
|
/**通过关键词搜索微博大v */
|
|
48
63
|
async searchBloggerInfo(keyword) {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const resp = await axios(url, {
|
|
64
|
+
const params = { containerid: '100103', type: '3', q: `${keyword}`, t: '', page_type: 'searchall' };
|
|
65
|
+
const url = new URL(WeiboApi.WEIBO_API.weiboGetIndex);
|
|
66
|
+
url.search = new URLSearchParams(params).toString();
|
|
67
|
+
const jar = await WeiboCookieManager.getSessionCookieJar();
|
|
68
|
+
const X_XSRF_TOKEN = await WeiboCookieManager.getCookieValueByKeyFromString(jar, 'X-XSRF-TOKEN', url.toString());
|
|
69
|
+
// (1) 保存初始状态
|
|
70
|
+
const initialCookies = await new Promise((resolve, reject) => {
|
|
71
|
+
jar.store.getAllCookies((err, cookies) => {
|
|
72
|
+
if (err)
|
|
73
|
+
reject(err);
|
|
74
|
+
else
|
|
75
|
+
resolve(cookies || []);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const resp = await axios(url.toString(), {
|
|
65
79
|
method: 'GET',
|
|
66
|
-
|
|
80
|
+
jar,
|
|
81
|
+
withCredentials: true,
|
|
67
82
|
timeout: 10000,
|
|
68
|
-
headers: lodash.merge(WeiboApi.WEIBO_HEADERS, {
|
|
83
|
+
headers: lodash.merge(WeiboApi.WEIBO_HEADERS, {
|
|
84
|
+
'X-XSRF-TOKEN': `${X_XSRF_TOKEN}`,
|
|
85
|
+
'Referer': 'https://m.weibo.cn/search?'
|
|
86
|
+
})
|
|
69
87
|
});
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
// (3) 获取请求完成后的 Cookie 状态
|
|
89
|
+
const updatedCookies = await new Promise((resolve, reject) => {
|
|
90
|
+
jar.store.getAllCookies((err, cookies) => {
|
|
91
|
+
if (err)
|
|
92
|
+
reject(err);
|
|
93
|
+
else
|
|
94
|
+
resolve(cookies || []);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
// 构建初始状态的 Map
|
|
98
|
+
const initialCookieMap = new Map(initialCookies.map(c => [`${c.key}:${c.domain}`, c]));
|
|
99
|
+
// 构建更新后的 Map
|
|
100
|
+
const updatedCookieMap = new Map(updatedCookies.map(c => [`${c.key}:${c.domain}`, c]));
|
|
101
|
+
// 比较两个 Map
|
|
102
|
+
for (const [key, updatedCookie] of updatedCookieMap.entries()) {
|
|
103
|
+
const initialCookie = initialCookieMap.get(key);
|
|
104
|
+
if (!initialCookie || initialCookie.value !== updatedCookie.value) {
|
|
105
|
+
console.log(`Weibo Cookie ${updatedCookie.key} was updated.`);
|
|
106
|
+
await WeiboCookieManager.saveCookiesToRedis(jar); // 更新同步到 Redis
|
|
107
|
+
}
|
|
73
108
|
}
|
|
74
109
|
return resp;
|
|
75
110
|
}
|
|
76
111
|
/**获取主页动态资源相关数组 */
|
|
77
|
-
async getBloggerDynamicList(
|
|
78
|
-
const params = { containerid: '107603' +
|
|
112
|
+
async getBloggerDynamicList(uid) {
|
|
113
|
+
const params = { containerid: '107603' + uid };
|
|
79
114
|
const url = new URL(WeiboApi.WEIBO_API.weiboGetIndex);
|
|
80
115
|
url.search = new URLSearchParams(params).toString();
|
|
81
116
|
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * (6500 - 1000 + 1) + 1000)));
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
117
|
+
const jar = await WeiboCookieManager.getSessionCookieJar();
|
|
118
|
+
const X_XSRF_TOKEN = await WeiboCookieManager.getCookieValueByKeyFromString(jar, 'X-XSRF-TOKEN', url.toString());
|
|
119
|
+
// (1) 保存初始状态
|
|
120
|
+
const initialCookies = await new Promise((resolve, reject) => {
|
|
121
|
+
jar.store.getAllCookies((err, cookies) => {
|
|
122
|
+
if (err)
|
|
123
|
+
reject(err);
|
|
124
|
+
else
|
|
125
|
+
resolve(cookies || []);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
93
128
|
try {
|
|
94
129
|
const response = await axios(url.toString(), {
|
|
95
130
|
method: 'GET',
|
|
131
|
+
jar,
|
|
132
|
+
withCredentials: true,
|
|
96
133
|
timeout: 10000,
|
|
97
|
-
headers: lodash.merge(WeiboApi.WEIBO_HEADERS, {
|
|
134
|
+
headers: lodash.merge(WeiboApi.WEIBO_HEADERS, {
|
|
135
|
+
'Host': 'm.weibo.cn',
|
|
136
|
+
'X-XSRF-TOKEN': `${X_XSRF_TOKEN}`,
|
|
137
|
+
'referer': `https://m.weibo.cn/u/${uid}`
|
|
138
|
+
})
|
|
98
139
|
});
|
|
99
|
-
// 处理 Set-Cookie 响应头
|
|
100
|
-
if (response.headers['set-cookie']) {
|
|
101
|
-
await WeiboMainModels.updateCookieWithSetCookie(response.headers['set-cookie'], mark);
|
|
102
|
-
}
|
|
103
140
|
const { ok, data, msg } = response?.data;
|
|
104
141
|
if (!ok && msg !== '这里还没有内容') {
|
|
105
142
|
throw new Error(response?.config.url);
|
|
106
143
|
}
|
|
144
|
+
// (3) 获取请求完成后的 Cookie 状态
|
|
145
|
+
const updatedCookies = await new Promise((resolve, reject) => {
|
|
146
|
+
jar.store.getAllCookies((err, cookies) => {
|
|
147
|
+
if (err)
|
|
148
|
+
reject(err);
|
|
149
|
+
else
|
|
150
|
+
resolve(cookies || []);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
// 构建初始状态的 Map
|
|
154
|
+
const initialCookieMap = new Map(initialCookies.map(c => [`${c.key}:${c.domain}`, c]));
|
|
155
|
+
// 构建更新后的 Map
|
|
156
|
+
const updatedCookieMap = new Map(updatedCookies.map(c => [`${c.key}:${c.domain}`, c]));
|
|
157
|
+
// 比较两个 Map
|
|
158
|
+
for (const [key, updatedCookie] of updatedCookieMap.entries()) {
|
|
159
|
+
const initialCookie = initialCookieMap.get(key);
|
|
160
|
+
if (!initialCookie || initialCookie.value !== updatedCookie.value) {
|
|
161
|
+
console.log(`Weibo Cookie ${updatedCookie.key} was updated.`);
|
|
162
|
+
await WeiboCookieManager.saveCookiesToRedis(jar); // 更新同步到 Redis
|
|
163
|
+
}
|
|
164
|
+
}
|
|
107
165
|
return data.cards.filter(WeiboQuery.filterCardTypeCustom);
|
|
108
166
|
}
|
|
109
167
|
catch (error) {
|
|
110
|
-
|
|
168
|
+
logger?.mark('微博推送:Error fetching sub list:', error);
|
|
111
169
|
return [];
|
|
112
170
|
}
|
|
113
171
|
}
|
|
@@ -156,7 +156,9 @@ class WeiboTask {
|
|
|
156
156
|
if (getWhiteWords && Array.isArray(getWhiteWords) && getWhiteWords.length > 0) {
|
|
157
157
|
// 构建白名单关键字正则表达式,转义特殊字符
|
|
158
158
|
const whiteWords = new RegExp(getWhiteWords.map(word => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'), 'g');
|
|
159
|
-
|
|
159
|
+
const content = `${data?.title}${data?.content}`;
|
|
160
|
+
if (!whiteWords.test(content)) {
|
|
161
|
+
logger.info(`博主 "${upName}" 微博动态:白名单关键词已开启,但动态消息未匹配,已跳过推送`);
|
|
160
162
|
return; // 如果动态消息不在白名单中,则直接返回
|
|
161
163
|
}
|
|
162
164
|
}
|
|
@@ -166,8 +168,11 @@ class WeiboTask {
|
|
|
166
168
|
if (getBanWords && Array.isArray(getBanWords) && getBanWords.length > 0) {
|
|
167
169
|
// 构建屏蔽关键字正则表达式,转义特殊字符
|
|
168
170
|
const banWords = new RegExp(getBanWords.map(word => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'), 'g');
|
|
169
|
-
|
|
170
|
-
|
|
171
|
+
const content = `${data?.title}${data?.content}`;
|
|
172
|
+
const matched = content.match(banWords);
|
|
173
|
+
if (matched) {
|
|
174
|
+
logger.info(`博主 "${upName}" 微博动态:触发屏蔽关键词 "${matched.join(', ')}" ,已跳过推送`);
|
|
175
|
+
return; // 如果动态消息包含屏蔽关键字,则直接返回
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
else if (getBanWords && !Array.isArray(getBanWords)) {
|
|
@@ -210,6 +215,7 @@ class WeiboTask {
|
|
|
210
215
|
// 构建白名单关键字正则表达式,转义特殊字符
|
|
211
216
|
const whiteWords = new RegExp(getWhiteWords.map(word => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'), 'g');
|
|
212
217
|
if (!whiteWords.test(dynamicMsg.msg.join(''))) {
|
|
218
|
+
logger.info(`博主 "${upName}" 微博动态:白名单关键词已开启,但动态消息未匹配,已跳过推送`);
|
|
213
219
|
return; // 如果动态消息不在白名单中,则直接返回
|
|
214
220
|
}
|
|
215
221
|
}
|
|
@@ -219,8 +225,11 @@ class WeiboTask {
|
|
|
219
225
|
if (getBanWords && Array.isArray(getBanWords) && getBanWords.length > 0) {
|
|
220
226
|
// 构建屏蔽关键字正则表达式,转义特殊字符
|
|
221
227
|
const banWords = new RegExp(getBanWords.map(word => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'), 'g');
|
|
222
|
-
|
|
223
|
-
|
|
228
|
+
const content = dynamicMsg.msg.join('');
|
|
229
|
+
const matched = content.match(banWords);
|
|
230
|
+
if (matched) {
|
|
231
|
+
logger.info(`博主 "${upName}" 微博动态:触发屏蔽关键词 "${matched.join(', ')}" ,已跳过推送`);
|
|
232
|
+
return; // 如果动态消息包含屏蔽关键字,则直接返回
|
|
224
233
|
}
|
|
225
234
|
}
|
|
226
235
|
else if (getBanWords && !Array.isArray(getBanWords)) {
|