yz-yuki-plugin 1.0.3 → 1.0.4
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 +7 -0
- package/README.md +23 -5
- package/lib/apps/bilibili.js +13 -5
- package/lib/apps/index.d.ts +4 -0
- package/lib/components/index.d.ts +5 -0
- package/lib/{types/index.d.ts → index.d.ts} +1 -1
- package/lib/index.js +28 -12
- package/lib/main.d.ts +1 -0
- package/lib/models/bilibili/bilibili.models.js +3 -0
- package/lib/models/bilibili/bilibili.query.js +27 -1
- package/lib/{types/models → models}/bilibili/bilibili.task.d.ts +2 -2
- package/lib/{types/models → models}/weibo/weibo.task.d.ts +2 -2
- package/lib/utils/config.js +30 -13
- package/lib/{types/utils → utils}/image.d.ts +1 -1
- package/lib/utils/puppeteer.render.js +7 -6
- package/package.json +26 -17
- package/resources/css/loginQrcode/Page.css +1 -0
- package/lib/types/apps/index.d.ts +0 -4
- package/lib/types/components/index.d.ts +0 -5
- /package/lib/{types/apps → apps}/bilibili.d.ts +0 -0
- /package/lib/{types/apps → apps}/help.d.ts +0 -0
- /package/lib/{types/apps → apps}/version.d.ts +0 -0
- /package/lib/{types/apps → apps}/weibo.d.ts +0 -0
- /package/lib/{types/components → components}/dynamic/Account.d.ts +0 -0
- /package/lib/{types/components → components}/dynamic/Content.d.ts +0 -0
- /package/lib/{types/components → components}/dynamic/Footer.d.ts +0 -0
- /package/lib/{types/components → components}/dynamic/ForwardContent.d.ts +0 -0
- /package/lib/{types/components → components}/dynamic/LogoText.d.ts +0 -0
- /package/lib/{types/components → components}/dynamic/MainPage.d.ts +0 -0
- /package/lib/{types/components → components}/help/Help.d.ts +0 -0
- /package/lib/{types/components → components}/loginQrcode/Page.d.ts +0 -0
- /package/lib/{types/components → components}/version/Version.d.ts +0 -0
- /package/lib/{types/models → models}/bilibili/bilibili.api.d.ts +0 -0
- /package/lib/{types/models → models}/bilibili/bilibili.buid.fp.d.ts +0 -0
- /package/lib/{types/models → models}/bilibili/bilibili.get.web.data.d.ts +0 -0
- /package/lib/{types/models → models}/bilibili/bilibili.models.d.ts +0 -0
- /package/lib/{types/models → models}/bilibili/bilibili.query.d.ts +0 -0
- /package/lib/{types/models → models}/bilibili/bilibili.wbi.d.ts +0 -0
- /package/lib/{types/models → models}/help/help.d.ts +0 -0
- /package/lib/{types/models → models}/version/version.d.ts +0 -0
- /package/lib/{types/models → models}/weibo/weibo.api.d.ts +0 -0
- /package/lib/{types/models → models}/weibo/weibo.get.web.data.d.ts +0 -0
- /package/lib/{types/models → models}/weibo/weibo.query.d.ts +0 -0
- /package/lib/{types/utils → utils}/config.d.ts +0 -0
- /package/lib/{types/utils → utils}/paths.d.ts +0 -0
- /package/lib/{types/utils → utils}/puppeteer.render.d.ts +0 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -15,11 +15,22 @@
|
|
|
15
15
|
|
|
16
16
|
##### ```Yunzai-Next:```
|
|
17
17
|
|
|
18
|
-
1. yunzai-next npm包
|
|
18
|
+
1. 方式1: yunzai-next npm包 安装插件:
|
|
19
19
|
>```
|
|
20
20
|
> yarn add yz-yuki-plugin -W
|
|
21
21
|
>```
|
|
22
|
-
接着修改 `yunzaijs/yunzai.config.js
|
|
22
|
+
接着修改 `yunzaijs/yunzai.config.js`,按版本选择修改方式:
|
|
23
|
+
|
|
24
|
+
Yunzai-Next v4.1.28+及以上版本:
|
|
25
|
+
```js
|
|
26
|
+
import { defineConfig } from 'yunzai'
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
applications: ['yz-system', 'yz-yuki-plugin'], //该行添加 'yz-yuki-plugin'
|
|
29
|
+
middlewares: ['yz-mw-runtime', 'yunzai-mys/mw']
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
旧版本:
|
|
23
34
|
```js
|
|
24
35
|
import yuki from 'yz-yuki-plugin' //新增该行
|
|
25
36
|
export default defineConfig({
|
|
@@ -28,7 +39,7 @@ export default defineConfig({
|
|
|
28
39
|
})
|
|
29
40
|
```
|
|
30
41
|
|
|
31
|
-
2.
|
|
42
|
+
2. 方式2(V3的方式):
|
|
32
43
|
>gitee仓库:
|
|
33
44
|
>```
|
|
34
45
|
>git clone --branch main https://gitee.com/snowtafir/yuki-plugin.git ./plugins/yuki-plugin
|
|
@@ -52,6 +63,8 @@ export default defineConfig({
|
|
|
52
63
|
|
|
53
64
|
#### 2. 安装依赖
|
|
54
65
|
* Yunzai-Next:
|
|
66
|
+
|
|
67
|
+
方式2(V3的方式)安装则需要执行:
|
|
55
68
|
```
|
|
56
69
|
yarn install
|
|
57
70
|
```
|
|
@@ -110,14 +123,19 @@ https://m.weibo.cn/u/7643376782 # 7643376782 为崩坏星穹铁道博主uid
|
|
|
110
123
|
- [x] 微博动态
|
|
111
124
|
|
|
112
125
|
|
|
113
|
-
##
|
|
126
|
+
## 🚀指令列表
|
|
114
127
|
|
|
115
128
|
<details><summary>点击展开</summary>
|
|
116
129
|
|
|
130
|
+
> [!IMPORTANT]
|
|
131
|
+
> 统一的配置文件路径:
|
|
132
|
+
|
|
133
|
+
`Yunzai/data/yuki-plugin/config/`,启动一次后,即可查看配置文件。
|
|
134
|
+
|
|
117
135
|
> [!TIP]
|
|
118
136
|
> 指令前缀:`#优纪`、`#yuki`、`/优纪`、`/yuki`,
|
|
119
137
|
|
|
120
|
-
|
|
138
|
+
示例:`#优纪订阅B站推送uid`、`#yuki订阅B站推送uid`、`/优纪订阅B站推送uid`、`/yuki订阅B站推送uid`。
|
|
121
139
|
|
|
122
140
|
| 用途 | 描述 | 指令 |
|
|
123
141
|
| --------- | ----------- | ------------ |
|
package/lib/apps/bilibili.js
CHANGED
|
@@ -32,7 +32,7 @@ message.use(async (e) => {
|
|
|
32
32
|
e.reply("未取得bot主人身份,无权限添加B站动态订阅");
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
const uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(订阅|添加|add|ADD)(b站|B站|bili|bilibili|哔哩|哔哩哔哩)推送\s*(视频\s*|图文\s*|文章\s*|转发\s*|直播\s*)*/g, "").trim();
|
|
35
|
+
const uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(订阅|添加|add|ADD)(b站|B站|bili|bilibili|哔哩|哔哩哔哩)推送\s*(视频\s*|图文\s*|文章\s*|转发\s*|直播\s*)*/g, "").trim().replace(/^(uid|UID)?(:|:)?/g, '');
|
|
36
36
|
if (!uid) {
|
|
37
37
|
e.reply(`请在指令末尾指定订阅的B站up主的UID!`);
|
|
38
38
|
return true;
|
|
@@ -67,7 +67,15 @@ message.use(async (e) => {
|
|
|
67
67
|
e.reply(`订阅校验失败~\nup主uid:${uid} 无效,请核对uid后再试~`);
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
|
-
let name
|
|
70
|
+
let name;
|
|
71
|
+
if (Array.isArray(items)) {
|
|
72
|
+
if (items.length > 0) {
|
|
73
|
+
name = items[0].modules?.module_author?.name || uid;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
name = uid;
|
|
78
|
+
}
|
|
71
79
|
subData[chatType][chatId].push({
|
|
72
80
|
bot_id: e.self_id,
|
|
73
81
|
uid,
|
|
@@ -84,7 +92,7 @@ message.use(async (e) => {
|
|
|
84
92
|
e.reply("未取得bot主人身份,无权限删除B站动态订阅");
|
|
85
93
|
}
|
|
86
94
|
else {
|
|
87
|
-
const uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(取消|删除|del|DEL)(b站|B站|bili|bilibili|哔哩|哔哩哔哩)推送\s*(视频\s*|图文\s*|文章\s*|转发\s*|直播\s*)*/g, "").trim();
|
|
95
|
+
const uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(取消|删除|del|DEL)(b站|B站|bili|bilibili|哔哩|哔哩哔哩)推送\s*(视频\s*|图文\s*|文章\s*|转发\s*|直播\s*)*/g, "").trim().replace(/^(uid|UID)?(:|:)?/g, '');
|
|
88
96
|
if (!uid) {
|
|
89
97
|
e.reply(`请在指令末尾指定订阅的B站up主的UID!`);
|
|
90
98
|
return;
|
|
@@ -289,7 +297,7 @@ message.use(async (e) => {
|
|
|
289
297
|
DYNAMIC_TYPE_LIVE_RCMD: "直播",
|
|
290
298
|
};
|
|
291
299
|
if (subData.group && Object.keys(subData.group).length > 0) {
|
|
292
|
-
messages.push("------群组B
|
|
300
|
+
messages.push("------群组B站订阅------\n");
|
|
293
301
|
Object.keys(subData.group).forEach((groupId) => {
|
|
294
302
|
messages.push(`群组ID:${groupId}:`);
|
|
295
303
|
subData.group[groupId].forEach((item) => {
|
|
@@ -306,7 +314,7 @@ message.use(async (e) => {
|
|
|
306
314
|
});
|
|
307
315
|
}
|
|
308
316
|
if (subData.private && Object.keys(subData.private).length > 0) {
|
|
309
|
-
messages.push("------私聊B站订阅------");
|
|
317
|
+
messages.push("\n------私聊B站订阅------");
|
|
310
318
|
Object.keys(subData.private).forEach((userId) => {
|
|
311
319
|
messages.push(`用户ID:${userId}:`);
|
|
312
320
|
subData.private[userId].forEach((item) => {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const MainPage: typeof import("@/components/dynamic/MainPage").default;
|
|
2
|
+
declare const Help: typeof import("@/components/help/Help").default;
|
|
3
|
+
declare const LoginQrcodePage: typeof import("@/components/loginQrcode/Page").default;
|
|
4
|
+
declare const Version: typeof import("@/components/version/Version").default;
|
|
5
|
+
export { Help, LoginQrcodePage, MainPage, Version };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: () => {
|
|
2
2
|
create(): void;
|
|
3
|
-
mounted<T extends keyof import("yunzai").EventEmun = "message.group">(
|
|
3
|
+
mounted<T extends keyof import("yunzai").EventEmun = "message.group">(e: Parameters<import("yunzai").EventEmun[T]>[0]): Promise<any[]>;
|
|
4
4
|
};
|
|
5
5
|
export default _default;
|
package/lib/index.js
CHANGED
|
@@ -1,27 +1,43 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import {
|
|
2
|
+
import { applicationOptions, useEvent } from 'yunzai';
|
|
3
3
|
import Config from './utils/config.js';
|
|
4
4
|
import * as index$1 from './apps/index.js';
|
|
5
5
|
|
|
6
|
-
const Data = useAppStorage();
|
|
7
6
|
var index = () => {
|
|
7
|
+
const rules = [];
|
|
8
8
|
return applicationOptions({
|
|
9
9
|
create() {
|
|
10
|
-
let count = 0;
|
|
11
10
|
for (const key in index$1) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const app = new index$1[key]();
|
|
12
|
+
for (const rule of app.rule) {
|
|
13
|
+
rules.push({
|
|
14
|
+
reg: rule.reg,
|
|
15
|
+
key: key
|
|
16
|
+
});
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
19
|
logger.info(chalk.rgb(0, 190, 255)(`-----------------------------------------`));
|
|
16
|
-
logger.info(chalk.rgb(255, 225, 255)(
|
|
17
|
-
logger.info(chalk.rgb(255, 245, 255)(
|
|
18
|
-
logger.info(chalk.rgb(255, 225, 255)(
|
|
19
|
-
logger.info(chalk.rgb(255, 245, 255)(
|
|
20
|
+
logger.info(chalk.rgb(255, 225, 255)(`优纪插件 ${Config.getLatestVersion()} 初始化~`));
|
|
21
|
+
logger.info(chalk.rgb(255, 245, 255)(`作者:snowtafir`));
|
|
22
|
+
logger.info(chalk.rgb(255, 225, 255)(`仓库地址:`));
|
|
23
|
+
logger.info(chalk.rgb(255, 245, 255)(`https://github.com/snowtafir/yuki-plugin`));
|
|
20
24
|
logger.info(chalk.rgb(0, 190, 255)(`-----------------------------------------`));
|
|
21
|
-
logger.info(chalk.rgb(0, 190, 255)(`★
|
|
25
|
+
logger.info(chalk.rgb(0, 190, 255)(`★ 优纪插件加载完成了喵~`));
|
|
22
26
|
},
|
|
23
|
-
mounted() {
|
|
24
|
-
|
|
27
|
+
async mounted(e) {
|
|
28
|
+
const data = [];
|
|
29
|
+
const cache = {};
|
|
30
|
+
await useEvent(e => {
|
|
31
|
+
for (const item of rules) {
|
|
32
|
+
if (new RegExp(item.reg).test(e.msg) &&
|
|
33
|
+
index$1[item.key] &&
|
|
34
|
+
!cache[item.key]) {
|
|
35
|
+
cache[item.key] = true;
|
|
36
|
+
data.push(new index$1[item.key]());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, [e, 'message']);
|
|
40
|
+
return data;
|
|
25
41
|
}
|
|
26
42
|
});
|
|
27
43
|
};
|
package/lib/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -28,6 +28,7 @@ async function applyLoginQRCode(e) {
|
|
|
28
28
|
};
|
|
29
29
|
const ScreenshotOptionsData = {
|
|
30
30
|
saveHtmlfile: false,
|
|
31
|
+
modelName: "bili-login"
|
|
31
32
|
};
|
|
32
33
|
const qrCodeImage = await Image.renderPage("bili-login", "LoginQrcodePage", LoginPropsData, ScreenshotOptionsData);
|
|
33
34
|
let qrcodeImg;
|
|
@@ -39,6 +40,8 @@ async function applyLoginQRCode(e) {
|
|
|
39
40
|
msg.push(Segment.image(qrcodeImg[0]));
|
|
40
41
|
e.reply('请在3分钟内扫码以完成B站登陆绑定');
|
|
41
42
|
e.reply(msg);
|
|
43
|
+
logger.info(`优纪插件: 如果发送二维码图片消息失败可复制如下URL, 使用在线或本地二维码生成工具生成二维码并扫码`);
|
|
44
|
+
logger.info(`优纪插件: 哔哩登陆二维码URL: ${qrcodeUrl}`);
|
|
42
45
|
return qrcodeKey;
|
|
43
46
|
}
|
|
44
47
|
else {
|
|
@@ -55,6 +55,12 @@ class BiliQuery {
|
|
|
55
55
|
pics = pics.map((item) => { return { url: item?.url, width: item?.width, height: item?.height }; });
|
|
56
56
|
formatData.data.content = this.parseRichTextNodes(desc?.summary?.rich_text_nodes || desc?.summary?.text) || "";
|
|
57
57
|
}
|
|
58
|
+
else if (majorType === "MAJOR_TYPE_DRAW") {
|
|
59
|
+
desc = data?.modules?.module_dynamic?.desc;
|
|
60
|
+
pics = data?.modules?.module_dynamic?.major?.draw?.items;
|
|
61
|
+
pics = pics.map((item) => { return { url: item?.url, width: item?.width, height: item?.height }; });
|
|
62
|
+
formatData.data.content = this.parseRichTextNodes(desc?.rich_text_nodes || desc?.text) || "";
|
|
63
|
+
}
|
|
58
64
|
else {
|
|
59
65
|
desc = data?.modules?.module_dynamic?.desc;
|
|
60
66
|
pics = data?.modules?.module_dynamic?.major?.draw?.items;
|
|
@@ -89,6 +95,13 @@ class BiliQuery {
|
|
|
89
95
|
formatData.data.pics = pics;
|
|
90
96
|
}
|
|
91
97
|
}
|
|
98
|
+
else if (majorType === "MAJOR_TYPE_ARTICLE") {
|
|
99
|
+
desc = data?.modules?.module_dynamic?.major?.article || {};
|
|
100
|
+
pics = desc?.covers;
|
|
101
|
+
pics = pics.map((item) => { return { url: item }; }) || [];
|
|
102
|
+
formatData.data.title = desc?.title;
|
|
103
|
+
formatData.data.content = this.parseRichTextNodes(desc?.desc);
|
|
104
|
+
}
|
|
92
105
|
else {
|
|
93
106
|
desc = data?.modules?.module_dynamic?.major?.article || {};
|
|
94
107
|
if (desc.covers && desc.covers.length) {
|
|
@@ -139,6 +152,7 @@ class BiliQuery {
|
|
|
139
152
|
;
|
|
140
153
|
static parseRichTextNodes = (nodes) => {
|
|
141
154
|
if (typeof nodes === 'string') {
|
|
155
|
+
nodes = nodes.replace(/\t/g, ' ');
|
|
142
156
|
return nodes.replace(/\n/g, '<br>');
|
|
143
157
|
}
|
|
144
158
|
else if (Array.isArray(nodes)) {
|
|
@@ -194,7 +208,7 @@ class BiliQuery {
|
|
|
194
208
|
}
|
|
195
209
|
}
|
|
196
210
|
static praseFullArticleContent(content) {
|
|
197
|
-
content = content.replace(/\n/g, '<br>');
|
|
211
|
+
content = String(content).replace(/\n/g, '<br>');
|
|
198
212
|
const imgTagRegex = /<img[^>]*data-src="([^"]*)"[^>]*>/g;
|
|
199
213
|
content = content.replace(imgTagRegex, (match, p1) => {
|
|
200
214
|
const newSrc = this.formatUrl(p1);
|
|
@@ -263,6 +277,12 @@ class BiliQuery {
|
|
|
263
277
|
});
|
|
264
278
|
content = desc?.summary?.text || "";
|
|
265
279
|
}
|
|
280
|
+
else if (majorType === "MAJOR_TYPE_DRAW") {
|
|
281
|
+
desc = data?.modules?.module_dynamic?.desc;
|
|
282
|
+
pics = data?.modules?.module_dynamic?.major?.draw?.items;
|
|
283
|
+
pics = pics.map((item) => { return item?.src; });
|
|
284
|
+
content = desc?.text || "";
|
|
285
|
+
}
|
|
266
286
|
else {
|
|
267
287
|
desc = data?.modules?.module_dynamic?.desc;
|
|
268
288
|
pics = data?.modules?.module_dynamic?.major?.draw?.items;
|
|
@@ -298,6 +318,12 @@ class BiliQuery {
|
|
|
298
318
|
dynamicTitle = desc?.title;
|
|
299
319
|
content = desc?.summary?.text || "";
|
|
300
320
|
}
|
|
321
|
+
else if (majorType === "MAJOR_TYPE_ARTICLE") {
|
|
322
|
+
desc = data?.modules?.module_dynamic?.major?.article || {};
|
|
323
|
+
pics = desc?.covers || [];
|
|
324
|
+
dynamicTitle = desc?.title;
|
|
325
|
+
content = desc?.desc;
|
|
326
|
+
}
|
|
301
327
|
else {
|
|
302
328
|
desc = data?.modules?.module_dynamic?.major?.article || {};
|
|
303
329
|
if (desc.covers && desc.covers.length) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventType } from 'yunzai';
|
|
2
|
-
import { MainProps } from "
|
|
3
|
-
import { ScreenshotOptions } from '
|
|
2
|
+
import { MainProps } from "@/components/dynamic/MainPage";
|
|
3
|
+
import { ScreenshotOptions } from '@/utils/puppeteer.render';
|
|
4
4
|
export declare class BiliTask {
|
|
5
5
|
taskName: string;
|
|
6
6
|
groupKey: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventType } from 'yunzai';
|
|
2
|
-
import { MainProps } from "
|
|
3
|
-
import { ScreenshotOptions } from '
|
|
2
|
+
import { MainProps } from "@/components/dynamic/MainPage";
|
|
3
|
+
import { ScreenshotOptions } from '@/utils/puppeteer.render';
|
|
4
4
|
export declare class WeiboTask {
|
|
5
5
|
taskName: string;
|
|
6
6
|
groupKey: string;
|
package/lib/utils/config.js
CHANGED
|
@@ -22,23 +22,35 @@ class Config {
|
|
|
22
22
|
this.initConfigFiles();
|
|
23
23
|
}
|
|
24
24
|
initConfigFiles() {
|
|
25
|
-
let bilibiliSetFile = path.join(_paths.pluginPath, 'config/bilibili/config.yaml');
|
|
26
|
-
let bilibiliPushFile = path.join(_paths.pluginPath, 'config/bilibili/push.yaml');
|
|
27
|
-
let weiboSetFile = path.join(_paths.pluginPath, 'config/weibo/config.yaml');
|
|
28
|
-
let weiboPushFile = path.join(_paths.pluginPath, 'config/weibo/push.yaml');
|
|
29
25
|
const configFiles = [
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
{
|
|
27
|
+
configFile: path.join(_paths.botYukiData, 'config/bilibili/config.yaml'),
|
|
28
|
+
defaultFile: path.join(_paths.pluginPath, 'defaultConfig/bilibili/config.yaml'),
|
|
29
|
+
dir: 'config/bilibili'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
configFile: path.join(_paths.botYukiData, 'config/bilibili/push.yaml'),
|
|
33
|
+
defaultFile: path.join(_paths.pluginPath, 'defaultConfig/bilibili/push.yaml'),
|
|
34
|
+
dir: 'config/bilibili'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
configFile: path.join(_paths.botYukiData, 'config/weibo/config.yaml'),
|
|
38
|
+
defaultFile: path.join(_paths.pluginPath, 'defaultConfig/weibo/config.yaml'),
|
|
39
|
+
dir: 'config/weibo'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
configFile: path.join(_paths.botYukiData, 'config/weibo/push.yaml'),
|
|
43
|
+
defaultFile: path.join(_paths.pluginPath, 'defaultConfig/weibo/push.yaml'),
|
|
44
|
+
dir: 'config/weibo'
|
|
45
|
+
}
|
|
34
46
|
];
|
|
35
|
-
for (const {
|
|
36
|
-
if (!fs.existsSync(
|
|
37
|
-
const configDir = path.join(_paths.
|
|
47
|
+
for (const { configFile, defaultFile, dir } of configFiles) {
|
|
48
|
+
if (!fs.existsSync(configFile)) {
|
|
49
|
+
const configDir = path.join(_paths.botYukiData, dir);
|
|
38
50
|
if (!fs.existsSync(configDir)) {
|
|
39
51
|
fs.mkdirSync(configDir, { recursive: true });
|
|
40
52
|
}
|
|
41
|
-
fs.copyFileSync(defaultFile,
|
|
53
|
+
fs.copyFileSync(defaultFile, configFile);
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
56
|
}
|
|
@@ -52,7 +64,12 @@ class Config {
|
|
|
52
64
|
return this[key];
|
|
53
65
|
}
|
|
54
66
|
getConfigFilePath(typeDir, appDir, functionName) {
|
|
55
|
-
|
|
67
|
+
if (typeDir === "defaultConfig") {
|
|
68
|
+
return path.join(_paths.pluginPath, `${typeDir}`, `${appDir}`, `${functionName}.yaml`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return path.join(_paths.botYukiData, `${typeDir}`, `${appDir}`, `${functionName}.yaml`);
|
|
72
|
+
}
|
|
56
73
|
}
|
|
57
74
|
watch(configFilePath, typeDir, appDir, functionName) {
|
|
58
75
|
const key = `${typeDir}_${appDir}_${functionName}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Picture, ComponentCreateOpsionType } from 'react-puppeteer';
|
|
2
|
-
import { ScreenshotOptions } from '
|
|
2
|
+
import { ScreenshotOptions } from '@/utils/puppeteer.render';
|
|
3
3
|
export declare class Image extends Picture {
|
|
4
4
|
constructor();
|
|
5
5
|
renderPage<T = any>(uid: number | string, page: string, props?: T, ScreenshotOptions?: ScreenshotOptions, ComponentCreateOpsion?: ComponentCreateOpsionType): Promise<false | {
|
|
@@ -23,10 +23,10 @@ class YukiPuppeteerRender extends Puppeteer {
|
|
|
23
23
|
await page.setExtraHTTPHeaders(Options.header);
|
|
24
24
|
}
|
|
25
25
|
await page.goto(`file://${htmlPath}`, { timeout: Options?.timeout ?? 120000, waitUntil: ["load", "networkidle0"] });
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
26
|
+
const element = await page.$(Options?.tab ?? 'body');
|
|
27
|
+
if (!element)
|
|
28
28
|
return false;
|
|
29
|
-
const boundingBox = await
|
|
29
|
+
const boundingBox = await element.boundingBox();
|
|
30
30
|
const num = Options?.isSplit ? Math.ceil(boundingBox.height / pageHeight) : 1;
|
|
31
31
|
pageHeight = Math.round(boundingBox.height / num);
|
|
32
32
|
await page.setViewport({
|
|
@@ -71,15 +71,16 @@ class YukiPuppeteerRender extends Puppeteer {
|
|
|
71
71
|
height: Math.min(pageHeight, boundingBox.height - pageHeight * (i - 1)),
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
|
-
buff = await
|
|
74
|
+
buff = await element.screenshot(screenshotOptions).catch(err => {
|
|
75
75
|
logger.error('[puppeteer]', 'screenshot', err);
|
|
76
76
|
return false;
|
|
77
77
|
});
|
|
78
78
|
numSun++;
|
|
79
79
|
if (buff !== false) {
|
|
80
|
-
|
|
80
|
+
let imgBuff = !Buffer.isBuffer(buff) ? Buffer.from(buff) : buff;
|
|
81
|
+
const kb = (imgBuff?.length / 1024).toFixed(2) + "kb";
|
|
81
82
|
logger.mark(`[图片生成][${name}][${numSun}次] ${kb} ${logger.green(`${Date.now() - start}ms`)}`);
|
|
82
|
-
ret.push(
|
|
83
|
+
ret.push(imgBuff);
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
86
|
logger.error(`[puppeteer]`, '截图失败');
|
package/package.json
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yz-yuki-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
|
|
5
5
|
"author": "snowtafir",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"
|
|
8
|
+
"private": false,
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/snowtafir/yuki-plugin.git"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"app": "
|
|
15
|
-
"dev": "
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"css": "tailwindcss -i ./src/input.css -o ./public/output.css",
|
|
19
|
-
"css
|
|
20
|
-
"css:watch": "tailwindcss -i ./src/input.css -o ./public/output.css --watch",
|
|
14
|
+
"app": "npx tsx src/main.ts",
|
|
15
|
+
"img-dev": "npx tsx watch --clear-screen=false routes.server.ts",
|
|
16
|
+
"build": "npm run css-m && rollup --config rollup.config.js",
|
|
17
|
+
"css-app": "tailwindcss -i ./src/input.css -o ./public/output.css",
|
|
18
|
+
"css-dev": "tailwindcss -i ./src/input.css -o ./public/output.css --watch",
|
|
19
|
+
"css-m": "tailwindcss -i ./src/input.css -o ./public/output.css -m",
|
|
21
20
|
"format": "prettier --write ."
|
|
22
21
|
},
|
|
23
22
|
"dependencies": {
|
|
24
23
|
"axios": "^1.7.3",
|
|
24
|
+
"chalk": "^5.3.0",
|
|
25
25
|
"chokidar": "^3.6.0",
|
|
26
|
+
"debug": "^4.3.6",
|
|
26
27
|
"jsdom": "^24.1.1",
|
|
27
28
|
"json5": "^2.2.3",
|
|
28
29
|
"md5": "^2.3.0",
|
|
@@ -32,12 +33,19 @@
|
|
|
32
33
|
"qrcode": "^1.5.4",
|
|
33
34
|
"react": "^18.3.1",
|
|
34
35
|
"react-dom": "^18.3.1",
|
|
35
|
-
"react-puppeteer": "1.0.
|
|
36
|
+
"react-puppeteer": "1.0.3",
|
|
36
37
|
"redis": "^4.7.0",
|
|
37
38
|
"yaml": "^2.5.0",
|
|
38
39
|
"yarn": "^1.19.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
42
|
+
"@babel/core": "^7.25.2",
|
|
43
|
+
"@babel/preset-env": "^7.25.4",
|
|
44
|
+
"@babel/preset-react": "^7.24.7",
|
|
45
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
46
|
+
"@types/chalk": "2.2.0",
|
|
47
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
48
|
+
"@types/lodash": "^4.17.7",
|
|
41
49
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
42
50
|
"@rollup/plugin-image": "^3.0.3",
|
|
43
51
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -47,7 +55,6 @@
|
|
|
47
55
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
48
56
|
"@types/rollup-plugin-auto-external": "^2.0.5",
|
|
49
57
|
"@types/jsdom": "^21.1.7",
|
|
50
|
-
"@types/lodash": "^4.17.7",
|
|
51
58
|
"@types/md5": "^2.3.5",
|
|
52
59
|
"@types/node": "^22.2.0",
|
|
53
60
|
"@types/node-fetch": "^2.6.11",
|
|
@@ -56,6 +63,7 @@
|
|
|
56
63
|
"@types/react-dom": "^18.3.0",
|
|
57
64
|
"@types/yaml": "1.9.7",
|
|
58
65
|
"axios": "^1.7.3",
|
|
66
|
+
"babel-plugin-module-resolver": "^5.0.2",
|
|
59
67
|
"chokidar": "^3.6.0",
|
|
60
68
|
"jsdom": "^24.1.1",
|
|
61
69
|
"json5": "^2.2.3",
|
|
@@ -67,7 +75,7 @@
|
|
|
67
75
|
"qrcode": "^1.5.4",
|
|
68
76
|
"react": "^18.3.1",
|
|
69
77
|
"react-dom": "^18.3.1",
|
|
70
|
-
"react-puppeteer": "1.0.
|
|
78
|
+
"react-puppeteer": "1.0.3",
|
|
71
79
|
"redis": "^4.7.0",
|
|
72
80
|
"rollup": "^4.20.0",
|
|
73
81
|
"rollup-plugin-auto-external": "^2.0.0",
|
|
@@ -76,9 +84,10 @@
|
|
|
76
84
|
"rollup-plugin-ignore": "^1.0.10",
|
|
77
85
|
"tailwindcss": "^3.4.9",
|
|
78
86
|
"ts-node": "^10.9.2",
|
|
87
|
+
"tsx": "^4.18.0",
|
|
79
88
|
"typescript": "^5.5.4",
|
|
80
|
-
"yunzai": "^1.0.
|
|
81
|
-
"yunzai-mys": "^1.0.
|
|
89
|
+
"yunzai": "^1.0.6",
|
|
90
|
+
"yunzai-mys": "^1.0.5"
|
|
82
91
|
},
|
|
83
92
|
"files": [
|
|
84
93
|
"public",
|
|
@@ -91,18 +100,18 @@
|
|
|
91
100
|
"LICENSE",
|
|
92
101
|
".puppeteerrc.cjs"
|
|
93
102
|
],
|
|
94
|
-
"types": "lib
|
|
103
|
+
"types": "lib",
|
|
95
104
|
"exports": {
|
|
96
105
|
".": {
|
|
97
106
|
"import": "./lib/index.js",
|
|
98
|
-
"types": "./lib/
|
|
107
|
+
"types": "./lib/index.d.ts"
|
|
99
108
|
}
|
|
100
109
|
},
|
|
101
110
|
"keywords": [
|
|
102
111
|
"yunzai"
|
|
103
112
|
],
|
|
104
113
|
"publishConfig": {
|
|
105
|
-
"registry": "https://registry.npmjs.org
|
|
114
|
+
"registry": "https://registry.npmjs.org"
|
|
106
115
|
},
|
|
107
116
|
"engines": {
|
|
108
117
|
"node": ">=16.14.0"
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
declare const MainPage: typeof import("./dynamic/MainPage").default;
|
|
2
|
-
declare const Help: typeof import("./help/Help").default;
|
|
3
|
-
declare const LoginQrcodePage: typeof import("./loginQrcode/Page").default;
|
|
4
|
-
declare const Version: typeof import("./version/Version").default;
|
|
5
|
-
export { Help, LoginQrcodePage, MainPage, Version };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|