yz-yuki-plugin 1.0.1-rc.1 → 1.0.2
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/lib/components/dynamic/Content.js +2 -2
- package/lib/models/bilibili/bilibili.api.js +19 -0
- package/lib/models/bilibili/bilibili.query.js +47 -3
- package/lib/models/bilibili/bilibili.task.js +1 -1
- package/lib/models/weibo/weibo.task.js +1 -1
- package/lib/types/models/bilibili/bilibili.api.d.ts +19 -0
- package/lib/types/models/bilibili/bilibili.query.d.ts +4 -2
- package/lib/utils/puppeteer.render.js +1 -1
- package/package.json +1 -1
- package/resources/css/dynamic/Content.css +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,8 @@ const Content = ({ data }) => {
|
|
|
10
10
|
}
|
|
11
11
|
return null;
|
|
12
12
|
})));
|
|
13
|
+
const boxGrid_4 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.4.css') });
|
|
14
|
+
const boxGrid_9 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.9.css') });
|
|
13
15
|
function getBoxGridStyle(pics) {
|
|
14
16
|
if (!Array.isArray(pics) || pics.length === 0) {
|
|
15
17
|
return null;
|
|
@@ -62,8 +64,6 @@ const Content = ({ data }) => {
|
|
|
62
64
|
return null;
|
|
63
65
|
}
|
|
64
66
|
const boxGrid = data.boxGrid && (data.pics && getBoxGridStyle(data.pics));
|
|
65
|
-
const boxGrid_4 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.4.css') });
|
|
66
|
-
const boxGrid_9 = React.createElement("link", { key: "0", rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.box.grid.9.css') });
|
|
67
67
|
const contentCss = React.createElement("link", { rel: "stylesheet", href: require('./../../../resources/css/dynamic/Content.css') });
|
|
68
68
|
switch (data.type) {
|
|
69
69
|
case 'DYNAMIC_TYPE_LIVE_RCMD':
|
|
@@ -44,6 +44,25 @@ class BiliApi {
|
|
|
44
44
|
'Sec-Fetch-User': '?1',
|
|
45
45
|
'TE': 'trailers',
|
|
46
46
|
};
|
|
47
|
+
static BILIBILI_ARTICLE_HEADERS = {
|
|
48
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8',
|
|
49
|
+
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
|
|
50
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
51
|
+
'Content-type': 'text/html; charset=utf-8',
|
|
52
|
+
Cookie: '',
|
|
53
|
+
'pragma': "no-cache",
|
|
54
|
+
"Cache-control": "no-cache",
|
|
55
|
+
'DNT': '1',
|
|
56
|
+
'Sec-GPC': '1',
|
|
57
|
+
'sec-ch-ua-mobile': '?0',
|
|
58
|
+
'Sec-Fetch-Dest': 'document',
|
|
59
|
+
'Sec-Fetch-Mode': 'navigate',
|
|
60
|
+
'Sec-Fetch-Site': 'same-site',
|
|
61
|
+
'Sec-Fetch-User': '?1',
|
|
62
|
+
'TE': 'trailers',
|
|
63
|
+
"Upgrade-Insecure-Requests": '1',
|
|
64
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
|
|
65
|
+
};
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
export { BiliApi };
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
2
|
import { Bot, Segment } from 'yunzai';
|
|
3
|
+
import { readSyncCookie } from './bilibili.models.js';
|
|
4
|
+
import { BiliApi } from './bilibili.api.js';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import lodash from 'lodash';
|
|
3
7
|
|
|
4
8
|
class BiliQuery {
|
|
5
|
-
static formatDynamicData(data) {
|
|
9
|
+
static async formatDynamicData(data) {
|
|
6
10
|
const BiliDrawDynamicLinkUrl = "https://m.bilibili.com/dynamic/";
|
|
7
11
|
let desc, pics = [], majorType;
|
|
8
12
|
let formatData = { data: {} };
|
|
@@ -71,8 +75,19 @@ class BiliQuery {
|
|
|
71
75
|
pics = desc?.pics;
|
|
72
76
|
pics = pics.map((item) => { return { url: item?.url, width: item?.width, height: item?.height }; }) || [];
|
|
73
77
|
formatData.data.title = desc?.title;
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
if ((desc?.summary?.text)?.length >= 480) {
|
|
79
|
+
const readInfo = await this.getFullArticleContent(this.formatUrl(desc?.jump_url));
|
|
80
|
+
formatData.data.content = this.praseFullArticleContent(readInfo?.content);
|
|
81
|
+
formatData.data.pics = [];
|
|
82
|
+
if ((formatData.data.content) === null) {
|
|
83
|
+
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
|
|
84
|
+
formatData.data.pics = pics;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
|
|
89
|
+
formatData.data.pics = pics;
|
|
90
|
+
}
|
|
76
91
|
}
|
|
77
92
|
else {
|
|
78
93
|
desc = data?.modules?.module_dynamic?.major?.article || {};
|
|
@@ -158,6 +173,35 @@ class BiliQuery {
|
|
|
158
173
|
return nodes;
|
|
159
174
|
}
|
|
160
175
|
};
|
|
176
|
+
static async getFullArticleContent(postUrl) {
|
|
177
|
+
const Cookie = await readSyncCookie();
|
|
178
|
+
try {
|
|
179
|
+
const response = await axios.get(postUrl, {
|
|
180
|
+
headers: lodash.merge(BiliApi.BILIBILI_ARTICLE_HEADERS, { "Cookie": `${Cookie}`, "Host": "www.bilibili.com" }),
|
|
181
|
+
responseType: 'text'
|
|
182
|
+
});
|
|
183
|
+
const text = response.data;
|
|
184
|
+
const match = text.match(/"readInfo":([\s\S]+?),"readViewInfo":/);
|
|
185
|
+
if (match) {
|
|
186
|
+
const full_json_text = match[1];
|
|
187
|
+
const readInfo = JSON.parse(full_json_text);
|
|
188
|
+
return readInfo;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
logger?.error(`优纪插件:获取B站完整文章内容失败 [ ${postUrl} ] : ${err}`);
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
static praseFullArticleContent(content) {
|
|
197
|
+
content = content.replace(/\n/g, '<br>');
|
|
198
|
+
const imgTagRegex = /<img[^>]*data-src="([^"]*)"[^>]*>/g;
|
|
199
|
+
content = content.replace(imgTagRegex, (match, p1) => {
|
|
200
|
+
const newSrc = this.formatUrl(p1);
|
|
201
|
+
return match.replace('data-src', 'src').replace(p1, newSrc);
|
|
202
|
+
});
|
|
203
|
+
return content;
|
|
204
|
+
}
|
|
161
205
|
static formatUrl(url) {
|
|
162
206
|
return 0 == url.indexOf('//') ? `https:${url}` : url;
|
|
163
207
|
}
|
|
@@ -94,7 +94,7 @@ class BiliTask {
|
|
|
94
94
|
if (!author?.pub_ts)
|
|
95
95
|
continue;
|
|
96
96
|
if (Number(now - author.pub_ts) > interval) {
|
|
97
|
-
logger.info(
|
|
97
|
+
logger.info(`超过间隔,跳过 [ ${author?.name} : ${author?.mid} ] ${author?.pub_time} 的动态`);
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
100
|
if (dynamicItem.type === "DYNAMIC_TYPE_FORWARD" && !biliConfigData.pushTransmit)
|
|
@@ -53,7 +53,7 @@ class WeiboTask {
|
|
|
53
53
|
if (!raw_post?.mblog?.created_at)
|
|
54
54
|
continue;
|
|
55
55
|
if (Number(now - (WeiboQuery.getDynamicCreatetDate(raw_post) / 1000)) > interval) {
|
|
56
|
-
logger.info(
|
|
56
|
+
logger.info(`超过间隔,跳过 [ ${user?.screen_name} : ${user?.id} ] ${raw_post?.mblog?.created_at} 的动态`);
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
if (dynamicItem.type === "DYNAMIC_TYPE_FORWARD" && !weiboConfigData.pushTransmit)
|
|
@@ -44,4 +44,23 @@ export declare class BiliApi {
|
|
|
44
44
|
'Sec-Fetch-User': string;
|
|
45
45
|
TE: string;
|
|
46
46
|
};
|
|
47
|
+
static BILIBILI_ARTICLE_HEADERS: {
|
|
48
|
+
Accept: string;
|
|
49
|
+
'Accept-Language': string;
|
|
50
|
+
'Accept-Encoding': string;
|
|
51
|
+
'Content-type': string;
|
|
52
|
+
Cookie: string;
|
|
53
|
+
pragma: string;
|
|
54
|
+
"Cache-control": string;
|
|
55
|
+
DNT: string;
|
|
56
|
+
'Sec-GPC': string;
|
|
57
|
+
'sec-ch-ua-mobile': string;
|
|
58
|
+
'Sec-Fetch-Dest': string;
|
|
59
|
+
'Sec-Fetch-Mode': string;
|
|
60
|
+
'Sec-Fetch-Site': string;
|
|
61
|
+
'Sec-Fetch-User': string;
|
|
62
|
+
TE: string;
|
|
63
|
+
"Upgrade-Insecure-Requests": string;
|
|
64
|
+
'User-Agent': string;
|
|
65
|
+
};
|
|
47
66
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export declare class BiliQuery {
|
|
2
|
-
static formatDynamicData(data: any): {
|
|
2
|
+
static formatDynamicData(data: any): Promise<{
|
|
3
3
|
uid: any;
|
|
4
4
|
data: {
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
};
|
|
7
|
-
}
|
|
7
|
+
}>;
|
|
8
8
|
static parseRichTextNodes: (nodes: any[] | string | any) => any;
|
|
9
|
+
static getFullArticleContent(postUrl: string): Promise<any>;
|
|
10
|
+
static praseFullArticleContent(content: string): string;
|
|
9
11
|
static formatUrl(url: string): string;
|
|
10
12
|
static formatTextDynamicData(upName: string, data: any, isForward: boolean, setData: any): Promise<any>;
|
|
11
13
|
static dynamicContentLimit(content: string, setData: any): string;
|
|
@@ -22,7 +22,7 @@ class YukiPuppeteerRender extends Puppeteer {
|
|
|
22
22
|
if (Options?.header) {
|
|
23
23
|
await page.setExtraHTTPHeaders(Options.header);
|
|
24
24
|
}
|
|
25
|
-
await page.goto(`file://${htmlPath}`, { timeout: Options?.timeout ?? 120000, waitUntil:
|
|
25
|
+
await page.goto(`file://${htmlPath}`, { timeout: Options?.timeout ?? 120000, waitUntil: ["load", "networkidle2"] });
|
|
26
26
|
const body = await page.$(Options?.tab ?? 'body');
|
|
27
27
|
if (!body)
|
|
28
28
|
return false;
|
package/package.json
CHANGED