alemonjs 1.0.25 → 1.0.27

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.
@@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
2
2
  import http from 'http';
3
3
  import https from 'https';
4
4
  import { join } from 'path';
5
+ import { createCanvas, loadImage } from 'canvas';
5
6
  /**
6
7
  * 异步请求图片
7
8
  * @param url
@@ -36,3 +37,26 @@ export function getPathBuffer(path) {
36
37
  const BufferImage = Buffer.from(image);
37
38
  return BufferImage;
38
39
  }
40
+ /**
41
+ * 压缩buffer图片
42
+ * @param img
43
+ * @param quality
44
+ * @returns
45
+ */
46
+ export async function compressImage(img, quality) {
47
+ const image = await loadImage(img);
48
+ const canvas = createCanvas(image.width, image.height);
49
+ const ctx = canvas.getContext('2d');
50
+ ctx.drawImage(image, 0, 0);
51
+ ctx.canvas.toDataURL('image/jpeg', quality);
52
+ return new Promise((resolve, reject) => {
53
+ canvas.toBuffer((err, buf) => {
54
+ if (err) {
55
+ reject(err);
56
+ }
57
+ else {
58
+ resolve(buf);
59
+ }
60
+ }, 'image/jpeg');
61
+ });
62
+ }
@@ -16,18 +16,6 @@ let browser;
16
16
  * 实例控制
17
17
  */
18
18
  let isBrowser = false;
19
- /**
20
- * 对每个页面进行缓存
21
- */
22
- const pageCache = {};
23
- /**
24
- * 清除缓存
25
- */
26
- function delCache() {
27
- for (const item in pageCache) {
28
- delete pageCache[item];
29
- }
30
- }
31
19
  /**
32
20
  * 实例配置
33
21
  */
@@ -72,7 +60,6 @@ export async function pupStartCheck() {
72
60
  */
73
61
  pic = 0;
74
62
  console.info('[puppeteer] close');
75
- delCache();
76
63
  isBrowser = false;
77
64
  browser.close().catch(err => console.error(err));
78
65
  console.info('[puppeteer] reopen');
@@ -125,7 +112,7 @@ export async function screenshotByFile(htmlPath, Options) {
125
112
  /**
126
113
  * 关闭
127
114
  */
128
- page.close().catch((err) => console.error(err));
115
+ await page.close().catch((err) => console.error(err));
129
116
  /**
130
117
  * 空的
131
118
  */
@@ -149,25 +136,22 @@ export async function screenshotByUrl(val) {
149
136
  return false;
150
137
  }
151
138
  const { url, time, rand, params, tab, cache } = val;
152
- if (!pageCache[url]) {
153
- pageCache[url] = await browser.newPage();
154
- }
139
+ const page = await browser.newPage();
155
140
  const isurl = params == undefined ? url : `${url}?${queryString.stringify(params ?? {})}`;
156
141
  /**
157
142
  * 启用页面缓存
158
143
  */
159
- await pageCache[url].setCacheEnabled(cache == undefined ? true : cache);
144
+ await page.setCacheEnabled(cache == undefined ? true : cache);
160
145
  /**
161
146
  * 启动网页
162
147
  */
163
- await pageCache[url].goto(isurl);
148
+ await page.goto(isurl);
164
149
  console.info(`open ${isurl}`);
165
150
  /**
166
151
  * 找到元素
167
152
  */
168
- const body = await pageCache[url].$(tab ?? 'body');
153
+ const body = await page.$(tab ?? 'body');
169
154
  if (!body) {
170
- delete pageCache[url];
171
155
  console.error(`tab err`);
172
156
  return false;
173
157
  }
@@ -192,9 +176,10 @@ export async function screenshotByUrl(val) {
192
176
  * 打印错误
193
177
  */
194
178
  if (!buff) {
195
- delete pageCache[url];
196
179
  console.error(`buff err:${url}`);
197
180
  }
181
+ // 确保页面已经不再使用后再删除
182
+ await page.close();
198
183
  return buff;
199
184
  }
200
185
  /**
@@ -205,14 +190,12 @@ export async function startChrom() {
205
190
  try {
206
191
  browser = await puppeteer.launch(LaunchCfg);
207
192
  isBrowser = true;
208
- delCache();
209
193
  console.info('[puppeteer] open success');
210
194
  return true;
211
195
  }
212
196
  catch (err) {
213
197
  console.error(err);
214
198
  isBrowser = false;
215
- delCache();
216
199
  console.error('[puppeteer] open fail');
217
200
  return false;
218
201
  }
@@ -114,7 +114,6 @@ export function createHtml(AppName, tplFile) {
114
114
  console.info('[HTML][CREATE]', AdressHtml);
115
115
  }
116
116
  return {
117
- control,
118
117
  // 模板地址
119
118
  AdressHtml,
120
119
  // 模板字符
@@ -73,7 +73,8 @@ export async function defineAlemonConfig(Options) {
73
73
  * 登录机器人
74
74
  * *********
75
75
  */
76
- if (Options?.login) {
76
+ if (Options?.login &&
77
+ (Options?.plugin?.init !== false || Options?.app?.init !== false)) {
77
78
  if (Options.login?.discord) {
78
79
  // 自定义覆盖
79
80
  setBotConfigByKey('discord', Options.login.discord);
@@ -192,7 +193,7 @@ export async function defineAlemonConfig(Options) {
192
193
  * 扫描插件
193
194
  * ************
194
195
  */
195
- if (Options?.plugin?.init) {
196
+ if (Options?.login && Options?.plugin?.init !== false) {
196
197
  // 加载插件
197
198
  await loadInit();
198
199
  }
@@ -3,7 +3,7 @@ import { ClientAPIByQQ as Client, getWebConfig } from '../../sdk/index.js';
3
3
  import { segmentQQ } from '../segment.js';
4
4
  import { getBotMsgByNtqq } from '../bot.js';
5
5
  import IMGS from 'image-size';
6
- import { setLocalImg } from '../../../koa/index.js';
6
+ import { setLocalImg } from '../../sdk/web/index.js';
7
7
  export const C2C_MESSAGE_CREATE = async (event) => {
8
8
  /**
9
9
  * 获取ip
@@ -3,7 +3,7 @@ import { ClientAPIByQQ as Client, getWebConfig } from '../../sdk/index.js';
3
3
  import { segmentQQ } from '../segment.js';
4
4
  import { getBotMsgByNtqq } from '../bot.js';
5
5
  import { getBotConfigByKey } from '../../../config/index.js';
6
- import { setLocalImg } from '../../../koa/index.js';
6
+ import { setLocalImg } from '../../sdk/web/index.js';
7
7
  import IMGS from 'image-size';
8
8
  /**
9
9
  * 公私域合并
package/lib/ntqq/index.js CHANGED
@@ -2,7 +2,7 @@ import { checkRobotByQQ } from './login.js';
2
2
  import { getBotConfigByKey } from '../config/index.js';
3
3
  import { conversation } from './alemon/conversation.js';
4
4
  import { setBotConfig, createClient, ClientAPIByQQ, getWebConfig } from './sdk/index.js';
5
- import { createWeb, autoClearImages } from '../koa/index.js';
5
+ import { createWeb, autoClearImages } from './sdk/web/index.js';
6
6
  import { getIP } from '../core/index.js';
7
7
  export async function createAlemonByNtqq() {
8
8
  /**
@@ -3,7 +3,7 @@ import Router from 'koa-router';
3
3
  import bodyParser from 'koa-bodyparser';
4
4
  import { mkdirSync } from 'fs';
5
5
  import { getLocalImg } from './img.js';
6
- import { setWebConfig } from '../ntqq/sdk/config.js';
6
+ import { setWebConfig } from '../config.js';
7
7
  /**
8
8
  * 创建客户端
9
9
  * @param param0
@@ -1,7 +1,7 @@
1
1
  import { createReadStream, writeFileSync, readdirSync, unlinkSync } from 'fs';
2
2
  import { join } from 'path';
3
3
  import { fileTypeFromBuffer } from 'file-type';
4
- import { getWebConfig } from '../ntqq/sdk/config.js';
4
+ import { getWebConfig } from '../config.js';
5
5
  /**
6
6
  * 处理图片请求
7
7
  * @param ctx
@@ -1,3 +1,3 @@
1
1
  export * from './client.js';
2
2
  export * from './img.js';
3
- export * from '../ntqq/sdk/types.js';
3
+ export * from '../types.js';
package/package.json CHANGED
@@ -1,72 +1,73 @@
1
- {
2
- "name": "alemonjs",
3
- "version": "1.0.25",
4
- "description": "docs https://alemonjs.com/",
5
- "author": "ningmengchongshui",
6
- "license": "GPL-2.0",
7
- "type": "module",
8
- "scripts": {
9
- "tsc": "npx tsc",
10
- "format": "prettier --write .",
11
- "lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
12
- },
13
- "dependencies": {
14
- "@discordjs/builders": "^1.6.3",
15
- "@discordjs/core": "^0.6.0",
16
- "@discordjs/rest": "^1.7.1",
17
- "axios": "^1.4.0",
18
- "discord.js": "^14.11.0",
19
- "image-size": "^1.0.2",
20
- "kook-ws": "^1.0.4",
21
- "lodash": "^4.17.21",
22
- "mys-villa": "^1.1.8",
23
- "public-ip": "^6.0.1",
24
- "puppeteer": "^20.7.1",
25
- "qq-channel": "^1.0.0",
26
- "qq-guild-bot": "^2.9.5",
27
- "qrcode": "^1.5.3"
28
- },
29
- "devDependencies": {
30
- "@types/lodash": "^4.14.186",
31
- "@types/node": "^20.2.4",
32
- "@types/progress": "^2.0.5",
33
- "@types/qrcode": "^1.5.0",
34
- "@types/ws": "^8.5.5",
35
- "@typescript-eslint/eslint-plugin": "^5.60.0",
36
- "@typescript-eslint/parser": "^5.60.0",
37
- "eslint": "^8.43.0",
38
- "eslint-config-prettier": "^8.8.0",
39
- "eslint-plugin-prettier": "^4.2.1",
40
- "prettier": "^2.8.8",
41
- "ts-node": "^10.9.1",
42
- "typescript": ">=5.0.4 <5.1.0"
43
- },
44
- "types": "types",
45
- "main": "lib/index.js",
46
- "files": [
47
- "bin",
48
- "lib",
49
- "types",
50
- "run.js",
51
- "run.d.ts"
52
- ],
53
- "exports": {
54
- ".": {
55
- "import": "./lib/index.js",
56
- "types": "./types/index.d.ts"
57
- },
58
- "./run": {
59
- "import": "./run.js",
60
- "types": "./run.d.ts"
61
- }
62
- },
63
- "bin": {
64
- "alemonjs": "bin/main.js"
65
- },
66
- "publishConfig": {
67
- "registry": "https://registry.npmjs.org"
68
- },
69
- "engines": {
70
- "node": ">=16.14.0"
71
- }
1
+ {
2
+ "name": "alemonjs",
3
+ "version": "1.0.27",
4
+ "description": "docs https://alemonjs.com/",
5
+ "author": "ningmengchongshui",
6
+ "license": "GPL-2.0",
7
+ "type": "module",
8
+ "scripts": {
9
+ "tsc": "npx tsc",
10
+ "format": "prettier --write .",
11
+ "lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
12
+ },
13
+ "dependencies": {
14
+ "@discordjs/builders": "^1.6.3",
15
+ "@discordjs/core": "^0.6.0",
16
+ "@discordjs/rest": "^1.7.1",
17
+ "axios": "^1.4.0",
18
+ "canvas": "^2.11.2",
19
+ "discord.js": "^14.11.0",
20
+ "image-size": "^1.0.2",
21
+ "kook-ws": "^1.0.4",
22
+ "lodash": "^4.17.21",
23
+ "mys-villa": "^1.1.8",
24
+ "public-ip": "^6.0.1",
25
+ "puppeteer": "^20.7.1",
26
+ "qq-channel": "^1.0.0",
27
+ "qq-guild-bot": "^2.9.5",
28
+ "qrcode": "^1.5.3"
29
+ },
30
+ "devDependencies": {
31
+ "@types/lodash": "^4.14.186",
32
+ "@types/node": "^20.2.4",
33
+ "@types/progress": "^2.0.5",
34
+ "@types/qrcode": "^1.5.0",
35
+ "@types/ws": "^8.5.5",
36
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
37
+ "@typescript-eslint/parser": "^5.60.0",
38
+ "eslint": "^8.43.0",
39
+ "eslint-config-prettier": "^8.8.0",
40
+ "eslint-plugin-prettier": "^4.2.1",
41
+ "prettier": "^2.8.8",
42
+ "ts-node": "^10.9.1",
43
+ "typescript": ">=5.0.4 <5.1.0"
44
+ },
45
+ "types": "types",
46
+ "main": "lib/index.js",
47
+ "files": [
48
+ "bin",
49
+ "lib",
50
+ "types",
51
+ "run.js",
52
+ "run.d.ts"
53
+ ],
54
+ "exports": {
55
+ ".": {
56
+ "import": "./lib/index.js",
57
+ "types": "./types/index.d.ts"
58
+ },
59
+ "./run": {
60
+ "import": "./run.js",
61
+ "types": "./run.d.ts"
62
+ }
63
+ },
64
+ "bin": {
65
+ "alemonjs": "bin/main.js"
66
+ },
67
+ "publishConfig": {
68
+ "registry": "https://registry.npmjs.org"
69
+ },
70
+ "engines": {
71
+ "node": ">=16.14.0"
72
+ }
72
73
  }
@@ -11,3 +11,10 @@ export declare function getUrlbuffer(url: string): Promise<Buffer>;
11
11
  * @returns
12
12
  */
13
13
  export declare function getPathBuffer(path: string): Buffer;
14
+ /**
15
+ * 压缩buffer图片
16
+ * @param img
17
+ * @param quality
18
+ * @returns
19
+ */
20
+ export declare function compressImage(img: Buffer, quality: number): Promise<Buffer>;
@@ -5,7 +5,6 @@
5
5
  * @returns
6
6
  */
7
7
  export declare function createHtml(AppName: string, tplFile: string): {
8
- control: boolean;
9
8
  AdressHtml: string;
10
9
  template: any;
11
10
  };
@@ -18,7 +18,7 @@ export interface AlemonOptions {
18
18
  /**
19
19
  * 是否创建
20
20
  */
21
- init?: boolean;
21
+ init?: false;
22
22
  /**
23
23
  * 应用名称
24
24
  */
@@ -35,7 +35,7 @@ export interface AlemonOptions {
35
35
  * 是否生成
36
36
  * defaukt true
37
37
  */
38
- create?: undefined | false;
38
+ create?: false;
39
39
  /**
40
40
  * 生成地址
41
41
  * defaukt /publick/defset
@@ -56,7 +56,7 @@ export interface AlemonOptions {
56
56
  /**
57
57
  * 是否加载插件
58
58
  */
59
- init?: boolean;
59
+ init?: false;
60
60
  /**
61
61
  * 插件目录
62
62
  */
@@ -1,4 +1,4 @@
1
- import { type WebConfig } from '../ntqq/sdk/types.js';
1
+ import { type WebConfig } from '../types.js';
2
2
  /**
3
3
  * 创建客户端
4
4
  * @param param0
@@ -1,3 +1,3 @@
1
1
  export * from './client.js';
2
2
  export * from './img.js';
3
- export * from '../ntqq/sdk/types.js';
3
+ export * from '../types.js';
File without changes