@zhin.js/plugin-qrcode 1.1.15 → 1.1.17

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/README.md CHANGED
@@ -33,3 +33,9 @@ This plugin currently has no configuration fields. Its [`schema.json`](./schema.
33
33
  The Endpoint determines any command prefix. An explicit `commandNamespace` adds a plugin
34
34
  namespace; neither is hardcoded in the command. Generation declares text length (1–2048)
35
35
  and image size in `defineCommand`; invalid values are rejected before creating the image.
36
+
37
+ ## Language / 语言
38
+
39
+ 命令说明和执行反馈跟随当前操作语言(简体中文或英文);用户输入与第三方内容保持原样,不进行自动翻译。语言与时区、权限和实际执行行为独立。参见[官方插件语言说明](../../README.md#语言与内容)。
40
+
41
+ Command feedback follows the operation language. User input and third-party content remain unchanged. See the [localization guide](../../../docs/en/configuration/localization.md).
@@ -3,8 +3,8 @@ import { defineCommand } from 'zhin.js/command';
3
3
  import { raw } from '@zhin.js/core/runtime';
4
4
  import { buildQrImageUrl } from "../../lib/qrcode-lib.js";
5
5
  export default defineCommand({
6
- description: '根据文本或链接生成二维码图片',
7
- params: { text: { type: 'text', min: 1, max: 2048, description: '二维码内容(可含空格)' } },
8
- options: { size: { type: 'integer', alias: 's', default: 300, min: 64, max: 1024, description: '图片宽高(像素)' } },
6
+ description: '根据文本或链接生成二维码图片', descriptionI18n: { en: "Generate a QR code image from text or a link" },
7
+ params: { text: { type: 'text', min: 1, max: 2048, description: '二维码内容(可含空格)', descriptionI18n: { en: "QR code content (spaces allowed)" } } },
8
+ options: { size: { type: 'integer', alias: 's', default: 300, min: 64, max: 1024, description: '图片宽高(像素)', descriptionI18n: { en: "Image width and height in pixels" } } },
9
9
  execute: ({ params, options }) => raw({ type: 'image', data: { url: buildQrImageUrl(params.text, options.size) } }),
10
10
  });
@@ -3,8 +3,8 @@ import { raw } from '@zhin.js/core/runtime';
3
3
  import { buildQrImageUrl } from '../../src/qrcode-lib.js';
4
4
 
5
5
  export default defineCommand({
6
- description: '根据文本或链接生成二维码图片',
7
- params: { text: { type: 'text', min: 1, max: 2048, description: '二维码内容(可含空格)' } },
8
- options: { size: { type: 'integer', alias: 's', default: 300, min: 64, max: 1024, description: '图片宽高(像素)' } },
6
+ description: '根据文本或链接生成二维码图片', descriptionI18n: { en: "Generate a QR code image from text or a link" },
7
+ params: { text: { type: 'text', min: 1, max: 2048, description: '二维码内容(可含空格)', descriptionI18n: { en: "QR code content (spaces allowed)" } } },
8
+ options: { size: { type: 'integer', alias: 's', default: 300, min: 64, max: 1024, description: '图片宽高(像素)', descriptionI18n: { en: "Image width and height in pixels" } } },
9
9
  execute: ({ params, options }) => raw({ type: 'image', data: { url: buildQrImageUrl(params.text, options.size) } }),
10
10
  });
@@ -1,27 +1,28 @@
1
1
  // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
2
  import { defineCommand } from 'zhin.js/command';
3
+ import { messages as t } from "../../../lib/i18n.js";
3
4
  const QR_API_BASE = 'https://api.qrserver.com/v1';
4
5
  export default defineCommand({
5
- description: '识别图片中的二维码内容',
6
+ description: '识别图片中的二维码内容', descriptionI18n: { en: "Read QR code content from an image" },
6
7
  params: { url: { type: 'string' } },
7
- async execute({ params }) {
8
+ async execute({ params, locale }) {
8
9
  const imageUrl = String(params.url);
9
10
  const apiUrl = `${QR_API_BASE}/read-qr-code/?fileurl=${encodeURIComponent(imageUrl)}`;
10
11
  try {
11
12
  const response = await fetch(apiUrl);
12
13
  if (!response.ok) {
13
- return '二维码识别服务请求失败';
14
+ return t(locale, 'requestFailed');
14
15
  }
15
16
  const data = (await response.json());
16
17
  const symbol = data?.[0]?.symbol?.[0];
17
18
  if (!symbol || symbol.error || !symbol.data) {
18
- return `未能识别二维码内容${symbol?.error ? `:${symbol.error}` : ''}`;
19
+ return t(locale, 'notFound', { detail: symbol?.error ? `: ${symbol.error}` : '' });
19
20
  }
20
- return `识别结果:${symbol.data}`;
21
+ return t(locale, 'result', { text: symbol.data });
21
22
  }
22
23
  catch (e) {
23
24
  console.warn(`[qrcode] scan failed: ${e instanceof Error ? e.message : String(e)}`);
24
- return '二维码识别失败,请检查图片链接是否有效';
25
+ return t(locale, 'failed');
25
26
  }
26
27
  },
27
28
  });
@@ -1,29 +1,30 @@
1
1
  import { defineCommand } from 'zhin.js/command';
2
+ import { messages as t } from '../../../src/i18n.js';
2
3
 
3
4
  const QR_API_BASE = 'https://api.qrserver.com/v1';
4
5
 
5
6
  export default defineCommand({
6
- description: '识别图片中的二维码内容',
7
+ description: '识别图片中的二维码内容', descriptionI18n: { en: "Read QR code content from an image" },
7
8
  params: { url: { type: 'string' } },
8
- async execute({ params }) {
9
+ async execute({ params, locale }) {
9
10
  const imageUrl = String(params.url);
10
11
  const apiUrl = `${QR_API_BASE}/read-qr-code/?fileurl=${encodeURIComponent(imageUrl)}`;
11
12
  try {
12
13
  const response = await fetch(apiUrl);
13
14
  if (!response.ok) {
14
- return '二维码识别服务请求失败';
15
+ return t(locale, 'requestFailed');
15
16
  }
16
17
  const data = (await response.json()) as Array<{
17
18
  symbol: Array<{ data: string | null; error: string | null }>;
18
19
  }>;
19
20
  const symbol = data?.[0]?.symbol?.[0];
20
21
  if (!symbol || symbol.error || !symbol.data) {
21
- return `未能识别二维码内容${symbol?.error ? `:${symbol.error}` : ''}`;
22
+ return t(locale, 'notFound', { detail: symbol?.error ? `: ${symbol.error}` : '' });
22
23
  }
23
- return `识别结果:${symbol.data}`;
24
+ return t(locale, 'result', { text: symbol.data });
24
25
  } catch (e) {
25
26
  console.warn(`[qrcode] scan failed: ${e instanceof Error ? e.message : String(e)}`);
26
- return '二维码识别失败,请检查图片链接是否有效';
27
+ return t(locale, 'failed');
27
28
  }
28
29
  },
29
30
  });
package/lib/i18n.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const messages: (locale: import("@zhin.js/plugin-runtime").Locale | undefined, key: "requestFailed" | "notFound" | "result" | "failed", values?: import("@zhin.js/plugin-runtime").MessageValues) => string;
2
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,6LAiBnB,CAAC"}
package/lib/i18n.js ADDED
@@ -0,0 +1,20 @@
1
+ import { createMessages } from 'zhin.js/i18n';
2
+ export const messages = createMessages({
3
+ "requestFailed": {
4
+ "zh-CN": "二维码识别服务请求失败",
5
+ "en": "The QR code service request failed."
6
+ },
7
+ "notFound": {
8
+ "zh-CN": "未能识别二维码内容{detail}",
9
+ "en": "Could not read a QR code{detail}"
10
+ },
11
+ "result": {
12
+ "zh-CN": "识别结果:{text}",
13
+ "en": "QR code content: {text}"
14
+ },
15
+ "failed": {
16
+ "zh-CN": "二维码识别失败,请检查图片链接是否有效",
17
+ "en": "Could not read the QR code. Check the image URL."
18
+ }
19
+ });
20
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC;IACrC,eAAe,EAAE;QACf,OAAO,EAAE,aAAa;QACtB,IAAI,EAAE,qCAAqC;KAC5C;IACD,UAAU,EAAE;QACV,OAAO,EAAE,mBAAmB;QAC5B,IAAI,EAAE,kCAAkC;KACzC;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,aAAa;QACtB,IAAI,EAAE,yBAAyB;KAChC;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,qBAAqB;QAC9B,IAAI,EAAE,kDAAkD;KACzD;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/plugin-qrcode",
3
- "version": "1.1.15",
3
+ "version": "1.1.17",
4
4
  "description": "QR code generator & reader plugin for Zhin.js (Plugin Runtime)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -37,20 +37,20 @@
37
37
  },
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@zhin.js/core": "1.1.50",
41
- "@zhin.js/tool": "1.1.9",
42
- "@zhin.js/skill": "1.1.9"
40
+ "@zhin.js/core": "1.1.52",
41
+ "@zhin.js/tool": "1.1.11",
42
+ "@zhin.js/skill": "1.1.10"
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": "1.1.15"
48
+ "zhin.js": "1.1.17"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "zod": "^4.0.0",
52
- "@zhin.js/command": "^1.1.10",
53
- "zhin.js": "^1.1.15"
52
+ "@zhin.js/command": "^1.1.11",
53
+ "zhin.js": "^1.1.17"
54
54
  },
55
55
  "peerDependenciesMeta": {
56
56
  "@zhin.js/command": {
package/src/i18n.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { createMessages } from 'zhin.js/i18n';
2
+
3
+ export const messages = createMessages({
4
+ "requestFailed": {
5
+ "zh-CN": "二维码识别服务请求失败",
6
+ "en": "The QR code service request failed."
7
+ },
8
+ "notFound": {
9
+ "zh-CN": "未能识别二维码内容{detail}",
10
+ "en": "Could not read a QR code{detail}"
11
+ },
12
+ "result": {
13
+ "zh-CN": "识别结果:{text}",
14
+ "en": "QR code content: {text}"
15
+ },
16
+ "failed": {
17
+ "zh-CN": "二维码识别失败,请检查图片链接是否有效",
18
+ "en": "Could not read the QR code. Check the image URL."
19
+ }
20
+ });