@zhin.js/plugin-qrcode 3.0.5 → 3.0.7

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.
@@ -0,0 +1,15 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { defineCommand } from '@zhin.js/command';
3
+ import { raw } from '@zhin.js/core/runtime';
4
+ import { buildQrImageUrl } from "../lib/qrcode-lib.js";
5
+ export default defineCommand({
6
+ description: '根据文本或链接生成二维码图片',
7
+ execute: ({ params, args }) => {
8
+ // [text:string] 单动态段只消费一个词;含空格的文本需拼上剩余 args
9
+ const text = [String(params.text ?? ''), ...args].join(' ').trim();
10
+ return raw({
11
+ type: 'image',
12
+ data: { url: buildQrImageUrl(text) },
13
+ });
14
+ },
15
+ });
@@ -0,0 +1,26 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { defineCommand } from '@zhin.js/command';
3
+ const QR_API_BASE = 'https://api.qrserver.com/v1';
4
+ export default defineCommand({
5
+ description: '识别图片中的二维码内容',
6
+ async execute({ params }) {
7
+ const imageUrl = String(params.url);
8
+ const apiUrl = `${QR_API_BASE}/read-qr-code/?fileurl=${encodeURIComponent(imageUrl)}`;
9
+ try {
10
+ const response = await fetch(apiUrl);
11
+ if (!response.ok) {
12
+ return '二维码识别服务请求失败';
13
+ }
14
+ const data = (await response.json());
15
+ const symbol = data?.[0]?.symbol?.[0];
16
+ if (!symbol || symbol.error || !symbol.data) {
17
+ return `未能识别二维码内容${symbol?.error ? `:${symbol.error}` : ''}`;
18
+ }
19
+ return `识别结果:${symbol.data}`;
20
+ }
21
+ catch (e) {
22
+ console.warn(`[qrcode] scan failed: ${e instanceof Error ? e.message : String(e)}`);
23
+ return '二维码识别失败,请检查图片链接是否有效';
24
+ }
25
+ },
26
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/plugin-qrcode",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "QR code generator & reader plugin for Zhin.js (Plugin Runtime)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -14,7 +14,7 @@
14
14
  "./package.json": "./package.json"
15
15
  },
16
16
  "files": [
17
- "plugin.ts",
17
+ "plugin.js",
18
18
  "schema.json",
19
19
  "commands",
20
20
  "src",
@@ -37,19 +37,19 @@
37
37
  },
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@zhin.js/command": "1.0.3",
41
- "@zhin.js/plugin-runtime": "1.1.1",
42
- "@zhin.js/core": "1.4.1"
40
+ "@zhin.js/command": "1.0.4",
41
+ "@zhin.js/core": "1.4.2",
42
+ "@zhin.js/plugin-runtime": "1.1.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^6.0.3",
46
46
  "vitest": "^4.1.10",
47
47
  "zod": "^4.4.3",
48
- "@zhin.js/agent": "1.0.6"
48
+ "@zhin.js/agent": "1.0.8"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "zod": "^4.0.0",
52
- "@zhin.js/agent": "1.0.6"
52
+ "@zhin.js/agent": "1.0.8"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@zhin.js/agent": {
@@ -74,7 +74,7 @@
74
74
  "zhin": {
75
75
  "protocol": 1,
76
76
  "type": "plugin",
77
- "entry": "./plugin.ts",
77
+ "entry": "./plugin.js",
78
78
  "engine": "^1.0.0",
79
79
  "runtime": "trusted",
80
80
  "features": [
package/plugin.js ADDED
@@ -0,0 +1,8 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { definePlugin } from '@zhin.js/plugin-runtime';
3
+ export default definePlugin({
4
+ name: 'qrcode',
5
+ metadata: {
6
+ displayName: 'QR Code',
7
+ },
8
+ });
package/plugin.ts DELETED
@@ -1,8 +0,0 @@
1
- import { definePlugin } from '@zhin.js/plugin-runtime';
2
-
3
- export default definePlugin({
4
- name: 'qrcode',
5
- metadata: {
6
- displayName: 'QR Code',
7
- },
8
- });