yz-yuki-plugin 1.0.1-rc.1 → 1.0.2-rc.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 CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.2
2
+ * 新增支持获取完整文章动态内容
3
+ * 修复宫格样式
4
+
1
5
  # 1.0.1
2
6
  * 修复了一些bug
3
7
  * 优化了一些功能
@@ -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
- formatData.data.pics = pics;
75
- formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
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(`超过间隔时间,跳过该up [ ${author?.name} : ${author?.mid} ] ${author?.pub_time} 的动态`);
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(`超过间隔时间,跳过该博主 [ ${user?.screen_name} : ${user?.id} ] ${raw_post?.mblog?.created_at} 的动态`);
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: 'networkidle2' });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "1.0.1-rc.1",
3
+ "version": "1.0.2-rc.0",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",
@@ -21,19 +21,19 @@
21
21
  "format": "prettier --write ."
22
22
  },
23
23
  "dependencies": {
24
- "axios": "^1.7.2",
24
+ "axios": "^1.7.3",
25
25
  "chokidar": "^3.6.0",
26
26
  "jsdom": "^24.1.0",
27
27
  "json5": "^2.2.3",
28
28
  "md5": "^2.3.0",
29
29
  "moment": "^2.30.1",
30
30
  "node-fetch": "^3.3.2",
31
- "puppeteer": "^22.14.0",
32
- "qrcode": "^1.5.3",
31
+ "puppeteer": "^22.15.0",
32
+ "qrcode": "^1.5.4",
33
33
  "react": "^18.3.1",
34
34
  "react-dom": "^18.3.1",
35
- "react-puppeteer": "1.0.0-rc.7",
36
- "redis": "^4.6.13",
35
+ "react-puppeteer": "1.0.1",
36
+ "redis": "^4.7.0",
37
37
  "yaml": "^2.5.0",
38
38
  "yarn": "^1.19.1"
39
39
  },
@@ -45,6 +45,7 @@
45
45
  "@rollup/plugin-replace": "^5.0.7",
46
46
  "@rollup/plugin-terser": "^0.4.4",
47
47
  "@rollup/plugin-typescript": "^11.1.3",
48
+ "@types/rollup-plugin-auto-external": "^2.0.5",
48
49
  "@types/jsdom": "^21.1.7",
49
50
  "@types/lodash": "^4.17.7",
50
51
  "@types/md5": "^2.3.5",
@@ -53,9 +54,8 @@
53
54
  "@types/qrcode": "^1.5.5",
54
55
  "@types/react": "^18.3.3",
55
56
  "@types/react-dom": "^18.3.0",
56
- "@types/rollup-plugin-auto-external": "^2.0.5",
57
57
  "@types/yaml": "1.9.7",
58
- "axios": "^1.7.2",
58
+ "axios": "^1.7.3",
59
59
  "chokidar": "^3.6.0",
60
60
  "jsdom": "^24.1.0",
61
61
  "json5": "^2.2.3",
@@ -63,13 +63,13 @@
63
63
  "node-fetch": "^3.3.2",
64
64
  "nodemon": "^3.0.1",
65
65
  "prettier": "^3.2.5",
66
- "puppeteer": "^22.14.0",
67
- "qrcode": "^1.5.3",
66
+ "puppeteer": "^22.15.0",
67
+ "qrcode": "^1.5.4",
68
68
  "react": "^18.3.1",
69
69
  "react-dom": "^18.3.1",
70
- "react-puppeteer": "1.0.0-rc.7",
71
- "redis": "^4.6.13",
72
- "rollup": "^4.16.4",
70
+ "react-puppeteer": "1.0.1",
71
+ "redis": "^4.7.0",
72
+ "rollup": "^4.20.0",
73
73
  "rollup-plugin-auto-external": "^2.0.0",
74
74
  "rollup-plugin-copy": "^3.5.0",
75
75
  "rollup-plugin-dts": "^6.1.1",
@@ -5,6 +5,10 @@
5
5
  font-style: normal;
6
6
  }
7
7
 
8
+ .content-text-title {
9
+ margin-top: 10px;
10
+ }
11
+
8
12
  .content {
9
13
  font-size: 20px;
10
14
  color: #333;