@karinjs/plugin-puppeteer 1.0.19 → 1.0.21
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.
|
@@ -6,7 +6,7 @@ import { basePath } from 'node-karin/root';
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@karinjs/plugin-puppeteer",
|
|
9
|
-
version: "1.0.
|
|
9
|
+
version: "1.0.21",
|
|
10
10
|
description: "karin\u7684 puppeteer\u622A\u56FE\u3001\u6E32\u67D3\u63D2\u4EF6",
|
|
11
11
|
keywords: [
|
|
12
12
|
"karin",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export * from '@karinjs/puppeteer';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getConfig, HMR_KEY, pluginVersion, pluginName } from './chunk-
|
|
1
|
+
import { getConfig, HMR_KEY, pluginVersion, pluginName } from './chunk-TPFKFKF4.js';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { launch } from '@karinjs/puppeteer';
|
|
4
|
+
export * from '@karinjs/puppeteer';
|
|
4
5
|
import { karin, registerRender, renderTpl, logger } from 'node-karin';
|
|
5
6
|
|
|
6
7
|
var formatBytes = (bytes) => {
|
|
@@ -12,18 +13,30 @@ var formatBytes = (bytes) => {
|
|
|
12
13
|
};
|
|
13
14
|
var getScreenshotByteSize = (payload, encoding) => {
|
|
14
15
|
try {
|
|
15
|
-
if (
|
|
16
|
+
if (payload == null) return void 0;
|
|
16
17
|
const enc = (encoding || "").toLowerCase();
|
|
18
|
+
if (Array.isArray(payload)) {
|
|
19
|
+
let total = 0;
|
|
20
|
+
for (const item of payload) {
|
|
21
|
+
const size = getScreenshotByteSize(item, enc);
|
|
22
|
+
if (typeof size === "number") total += size;
|
|
23
|
+
}
|
|
24
|
+
return total;
|
|
25
|
+
}
|
|
17
26
|
if (typeof payload === "string") {
|
|
18
27
|
return enc === "base64" ? Buffer.from(payload, "base64").length : Buffer.byteLength(payload);
|
|
19
28
|
}
|
|
20
29
|
if (Buffer.isBuffer(payload)) return payload.length;
|
|
30
|
+
if (payload instanceof Uint8Array) return payload.byteLength;
|
|
31
|
+
if (payload instanceof ArrayBuffer) return payload.byteLength;
|
|
21
32
|
const anyPayload = payload;
|
|
22
33
|
if (typeof anyPayload.data === "string") {
|
|
23
34
|
return enc === "base64" ? Buffer.from(anyPayload.data, "base64").length : Buffer.byteLength(anyPayload.data);
|
|
24
35
|
}
|
|
25
36
|
if (Buffer.isBuffer(anyPayload.buffer)) return anyPayload.buffer.length;
|
|
37
|
+
if (anyPayload.buffer instanceof ArrayBuffer) return anyPayload.buffer.byteLength;
|
|
26
38
|
if (typeof anyPayload.byteLength === "number") return anyPayload.byteLength;
|
|
39
|
+
if (typeof anyPayload.length === "number") return anyPayload.length;
|
|
27
40
|
return void 0;
|
|
28
41
|
} catch {
|
|
29
42
|
return void 0;
|
|
@@ -37,16 +50,21 @@ var main = async () => {
|
|
|
37
50
|
registerRender(name, async (options) => {
|
|
38
51
|
options.encoding = "base64";
|
|
39
52
|
const data = renderTpl(options);
|
|
53
|
+
data.encoding = options.encoding;
|
|
40
54
|
const time = Date.now();
|
|
41
55
|
const result = await browser.screenshot(data);
|
|
56
|
+
const fileName = typeof data?.file === "string" ? path.basename(data.file) : "unknown";
|
|
57
|
+
if (!result.status) {
|
|
58
|
+
logger.info(
|
|
59
|
+
`[${name}][${fileName}] \u622A\u56FE\u5931\u8D25 \u8017\u65F6: ${logger.green(Date.now() - time + "")} ms`
|
|
60
|
+
);
|
|
61
|
+
throw new Error(result.data.message || "\u622A\u56FE\u5931\u8D25", { cause: result.data });
|
|
62
|
+
}
|
|
42
63
|
const sizeBytes = getScreenshotByteSize(result.data, options.encoding);
|
|
43
64
|
const sizeStr = sizeBytes != null ? `\u5927\u5C0F: ${logger.green(formatBytes(sizeBytes))} ` : "";
|
|
44
65
|
logger.info(
|
|
45
|
-
`[${name}][${
|
|
66
|
+
`[${name}][${fileName}] \u622A\u56FE\u5B8C\u6210 ${sizeStr}\u8017\u65F6: ${logger.green(Date.now() - time + "")} ms`
|
|
46
67
|
);
|
|
47
|
-
if (!result.status) {
|
|
48
|
-
throw new Error(result.data.message || "\u622A\u56FE\u5931\u8D25", { cause: result.data });
|
|
49
|
-
}
|
|
50
68
|
return result.data;
|
|
51
69
|
});
|
|
52
70
|
logger.info(`${logger.violet(`[\u63D2\u4EF6:${pluginVersion}]`)} ${logger.green(pluginName)} \u521D\u59CB\u5316\u5B8C\u6210~`);
|
package/dist/web.config.js
CHANGED