@zhin.js/plugin-60s 3.0.4 → 3.0.6
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/commands/60s.js +7 -0
- package/commands/bing.js +7 -0
- package/commands/douyin/[limit:number=10].js +7 -0
- package/commands/duanzi.js +7 -0
- package/commands/exchange.js +10 -0
- package/commands/fanyi/[text:string].js +7 -0
- package/commands/fuel/[province:string].js +7 -0
- package/commands/gold.js +7 -0
- package/commands/history.js +7 -0
- package/commands/hitokoto/[type:string].js +7 -0
- package/commands/ip/[ip:string].js +7 -0
- package/commands/kfc.js +7 -0
- package/commands/moyu.js +7 -0
- package/commands/toutiao/[limit:number=10].js +7 -0
- package/commands/weather/[city:string].js +7 -0
- package/commands/weibo/[limit:number=10].js +7 -0
- package/commands/zhihu/[limit:number=10].js +7 -0
- package/lib/api.js +17 -3
- package/lib/api.js.map +1 -1
- package/lib/runtime-deps.js +22 -0
- package/lib/runtime-deps.js.map +1 -0
- package/package.json +8 -8
- package/plugin.js +13 -0
- package/src/api.ts +19 -3
- package/src/runtime-deps.ts +26 -0
- package/plugin.ts +0 -18
package/commands/60s.js
ADDED
package/commands/bing.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/douyin-hot.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '抖音热搜',
|
|
6
|
+
execute: ({ params }) => handler({ limit: Number(params.limit) }),
|
|
7
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../lib/handlers/exchange-rate.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '货币汇率',
|
|
6
|
+
execute: ({ args }) => handler({
|
|
7
|
+
from: args[0] != null ? String(args[0]) : undefined,
|
|
8
|
+
to: args[1] != null ? String(args[1]) : undefined,
|
|
9
|
+
}),
|
|
10
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/translate.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '文本翻译',
|
|
6
|
+
execute: ({ params, args }) => handler({ text: String(params.text), to: args[0] != null ? String(args[0]) : undefined }),
|
|
7
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/fuel-price.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '今日油价',
|
|
6
|
+
execute: ({ params }) => handler({ province: params.province != null ? String(params.province) : undefined }),
|
|
7
|
+
});
|
package/commands/gold.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/hitokoto.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '随机一言',
|
|
6
|
+
execute: ({ params }) => handler({ type: params.type != null ? String(params.type) : undefined }),
|
|
7
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/ip-query.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: 'IP 查询',
|
|
6
|
+
execute: ({ params }) => handler({ ip: params.ip != null ? String(params.ip) : undefined }),
|
|
7
|
+
});
|
package/commands/kfc.js
ADDED
package/commands/moyu.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/toutiao-hot.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '头条热搜',
|
|
6
|
+
execute: ({ params }) => handler({ limit: Number(params.limit) }),
|
|
7
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/weather.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '查询城市天气',
|
|
6
|
+
execute: ({ params }) => handler({ city: String(params.city) }),
|
|
7
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/weibo-hot.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '微博热搜',
|
|
6
|
+
execute: ({ params }) => handler({ limit: Number(params.limit) }),
|
|
7
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineCommand } from '@zhin.js/command';
|
|
3
|
+
import handler from "../../lib/handlers/zhihu-hot.js";
|
|
4
|
+
export default defineCommand({
|
|
5
|
+
description: '知乎热榜',
|
|
6
|
+
execute: ({ params }) => handler({ limit: Number(params.limit) }),
|
|
7
|
+
});
|
package/lib/api.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 60s API 共享模块 — 供 *.tool.md handler 使用
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import { resolveApiBase } from './runtime-deps.js';
|
|
5
5
|
export async function fetchApi(endpoint, params) {
|
|
6
|
-
const url = new URL(`${
|
|
6
|
+
const url = new URL(`${resolveApiBase()}/v2${endpoint}`);
|
|
7
7
|
if (params) {
|
|
8
8
|
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
let res;
|
|
11
|
+
try {
|
|
12
|
+
res = await fetch(url.toString(), { signal: AbortSignal.timeout(30_000) });
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
const err = e;
|
|
16
|
+
throw new Error(err.name === 'TimeoutError' ? '请求超时(30s)' : `请求失败: ${err.message}`, { cause: e });
|
|
17
|
+
}
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
throw new Error(`API 请求失败: ${res.status} ${res.statusText}`);
|
|
20
|
+
}
|
|
21
|
+
const contentType = res.headers.get('content-type') ?? '';
|
|
22
|
+
if (!contentType.includes('application/json')) {
|
|
23
|
+
throw new Error(`API 返回非 JSON 响应 (content-type: ${contentType || 'unknown'})`);
|
|
24
|
+
}
|
|
11
25
|
const data = (await res.json());
|
|
12
26
|
if (data.error)
|
|
13
27
|
throw new Error(data.error);
|
package/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOnD,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,QAAgB,EAChB,MAA+B;IAE/B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,cAAc,EAAE,MAAM,QAAQ,EAAE,CAAC,CAAC;IACzD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAA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,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;QACvD,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,GAAG,MAAM,EAAE,CAAC;IACvC,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 60s apiBase 运行时注入 — plugin setup 注册 getter,fetchApi 每次调用时求值。
|
|
3
|
+
* 参考 lottery 的 registerLotteryAgentDeps:registration 模式,卸载时反注册,无 process.env 残留。
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_API_BASE = 'https://60s.viki.moe';
|
|
6
|
+
const registrations = [];
|
|
7
|
+
/** Generation-owned apiBase binding used by Plugin Runtime setup(). Returns unregister. */
|
|
8
|
+
export function registerSixtySApiBase(getter) {
|
|
9
|
+
const registration = Object.freeze({ value: getter });
|
|
10
|
+
registrations.push(registration);
|
|
11
|
+
return () => {
|
|
12
|
+
const index = registrations.lastIndexOf(registration);
|
|
13
|
+
if (index >= 0)
|
|
14
|
+
registrations.splice(index, 1);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Resolve the apiBase at call time so config patches take effect without reload. */
|
|
18
|
+
export function resolveApiBase() {
|
|
19
|
+
const getter = registrations[registrations.length - 1]?.value;
|
|
20
|
+
return getter?.() || DEFAULT_API_BASE;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=runtime-deps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-deps.js","sourceRoot":"","sources":["../src/runtime-deps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAIvD,MAAM,aAAa,GAAmD,EAAE,CAAC;AAEzE,2FAA2F;AAC3F,MAAM,UAAU,qBAAqB,CAAC,MAA2B;IAC/D,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACtD,IAAI,KAAK,IAAI,CAAC;YAAE,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC;IAC9D,OAAO,MAAM,EAAE,EAAE,IAAI,gBAAgB,CAAC;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-60s",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "60s API aggregation plugin for Zhin.js — news, weather, hot searches, utilities (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.
|
|
17
|
+
"plugin.js",
|
|
18
18
|
"schema.json",
|
|
19
19
|
"commands",
|
|
20
20
|
"src",
|
|
@@ -45,19 +45,19 @@
|
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@zhin.js/command": "1.0.
|
|
49
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
50
|
-
"@zhin.js/tool": "1.0.
|
|
48
|
+
"@zhin.js/command": "1.0.4",
|
|
49
|
+
"@zhin.js/plugin-runtime": "1.1.1",
|
|
50
|
+
"@zhin.js/tool": "1.0.4"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"typescript": "^6.0.3",
|
|
54
54
|
"vitest": "^4.1.10",
|
|
55
55
|
"zod": "^4.4.3",
|
|
56
|
-
"@zhin.js/agent": "1.0.
|
|
56
|
+
"@zhin.js/agent": "1.0.7"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"zod": "^4.0.0",
|
|
60
|
-
"@zhin.js/agent": "1.0.
|
|
60
|
+
"@zhin.js/agent": "1.0.7"
|
|
61
61
|
},
|
|
62
62
|
"peerDependenciesMeta": {
|
|
63
63
|
"@zhin.js/agent": {
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"zhin": {
|
|
83
83
|
"protocol": 1,
|
|
84
84
|
"type": "plugin",
|
|
85
|
-
"entry": "./plugin.
|
|
85
|
+
"entry": "./plugin.js",
|
|
86
86
|
"engine": "^1.0.0",
|
|
87
87
|
"runtime": "trusted",
|
|
88
88
|
"features": [
|
package/plugin.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { definePlugin } from '@zhin.js/plugin-runtime';
|
|
3
|
+
import { DEFAULT_API_BASE, registerSixtySApiBase } from "./lib/runtime-deps.js";
|
|
4
|
+
export default definePlugin({
|
|
5
|
+
name: 'sixty-s',
|
|
6
|
+
metadata: {
|
|
7
|
+
displayName: '60s API',
|
|
8
|
+
},
|
|
9
|
+
setup(context) {
|
|
10
|
+
// 运行时读取配置:config patch 即时生效;卸载时 lifecycle 反注册,无 process.env 残留
|
|
11
|
+
context.lifecycle.add(registerSixtySApiBase(() => context.config.get().apiBase?.trim() || DEFAULT_API_BASE));
|
|
12
|
+
},
|
|
13
|
+
});
|
package/src/api.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 60s API 共享模块 — 供 *.tool.md handler 使用
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { resolveApiBase } from './runtime-deps.js';
|
|
6
6
|
|
|
7
7
|
export type ListItem = string | Record<string, unknown>;
|
|
8
8
|
|
|
@@ -13,11 +13,27 @@ export async function fetchApi<T = ApiPayload>(
|
|
|
13
13
|
endpoint: string,
|
|
14
14
|
params?: Record<string, string>,
|
|
15
15
|
): Promise<T> {
|
|
16
|
-
const url = new URL(`${
|
|
16
|
+
const url = new URL(`${resolveApiBase()}/v2${endpoint}`);
|
|
17
17
|
if (params) {
|
|
18
18
|
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
let res: Response;
|
|
21
|
+
try {
|
|
22
|
+
res = await fetch(url.toString(), { signal: AbortSignal.timeout(30_000) });
|
|
23
|
+
} catch (e) {
|
|
24
|
+
const err = e as Error;
|
|
25
|
+
throw new Error(
|
|
26
|
+
err.name === 'TimeoutError' ? '请求超时(30s)' : `请求失败: ${err.message}`,
|
|
27
|
+
{ cause: e },
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
throw new Error(`API 请求失败: ${res.status} ${res.statusText}`);
|
|
32
|
+
}
|
|
33
|
+
const contentType = res.headers.get('content-type') ?? '';
|
|
34
|
+
if (!contentType.includes('application/json')) {
|
|
35
|
+
throw new Error(`API 返回非 JSON 响应 (content-type: ${contentType || 'unknown'})`);
|
|
36
|
+
}
|
|
21
37
|
const data = (await res.json()) as {
|
|
22
38
|
error?: string;
|
|
23
39
|
code?: number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 60s apiBase 运行时注入 — plugin setup 注册 getter,fetchApi 每次调用时求值。
|
|
3
|
+
* 参考 lottery 的 registerLotteryAgentDeps:registration 模式,卸载时反注册,无 process.env 残留。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const DEFAULT_API_BASE = 'https://60s.viki.moe';
|
|
7
|
+
|
|
8
|
+
export type SixtySApiBaseGetter = () => string;
|
|
9
|
+
|
|
10
|
+
const registrations: Array<{ readonly value: SixtySApiBaseGetter }> = [];
|
|
11
|
+
|
|
12
|
+
/** Generation-owned apiBase binding used by Plugin Runtime setup(). Returns unregister. */
|
|
13
|
+
export function registerSixtySApiBase(getter: SixtySApiBaseGetter): () => void {
|
|
14
|
+
const registration = Object.freeze({ value: getter });
|
|
15
|
+
registrations.push(registration);
|
|
16
|
+
return () => {
|
|
17
|
+
const index = registrations.lastIndexOf(registration);
|
|
18
|
+
if (index >= 0) registrations.splice(index, 1);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Resolve the apiBase at call time so config patches take effect without reload. */
|
|
23
|
+
export function resolveApiBase(): string {
|
|
24
|
+
const getter = registrations[registrations.length - 1]?.value;
|
|
25
|
+
return getter?.() || DEFAULT_API_BASE;
|
|
26
|
+
}
|
package/plugin.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { definePlugin } from '@zhin.js/plugin-runtime';
|
|
2
|
-
|
|
3
|
-
export interface SixtySConfig {
|
|
4
|
-
readonly apiBase?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const DEFAULT_API_BASE = 'https://60s.viki.moe';
|
|
8
|
-
|
|
9
|
-
export default definePlugin<SixtySConfig>({
|
|
10
|
-
name: 'sixty-s',
|
|
11
|
-
metadata: {
|
|
12
|
-
displayName: '60s API',
|
|
13
|
-
},
|
|
14
|
-
setup(context) {
|
|
15
|
-
const apiBase = context.config.get().apiBase?.trim() || DEFAULT_API_BASE;
|
|
16
|
-
process.env.ZHIN_60S_API = apiBase;
|
|
17
|
-
},
|
|
18
|
-
});
|