@shiqianjiang/ceru-plugin-core 0.3.11 → 0.3.13

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/dist/network.d.ts CHANGED
@@ -1,2 +1,12 @@
1
1
  export declare function isPrivateAddress(address: string): boolean;
2
+ export interface NetworkProxyAgents {
3
+ httpAgent: any;
4
+ httpsAgent: any;
5
+ }
6
+ export type NetworkProxyResolver = (url: string) => NetworkProxyAgents | null;
7
+ /**
8
+ * 宿主注入的代理解析器:按目标 URL 返回代理 agents(null = 直连)。
9
+ * 注入后重定向链的每一跳都会重新询问;DNS pin 仅在直连时保留。
10
+ */
11
+ export declare function setNetworkProxyResolver(resolver: NetworkProxyResolver | null): void;
2
12
  export declare function requestNetwork(input: any, privateAllowed: () => boolean, signal?: AbortSignal, redirects?: number): Promise<any>;
package/dist/network.js CHANGED
@@ -24,6 +24,14 @@ export function isPrivateAddress(address) {
24
24
  (a === 192 && b === 168) ||
25
25
  (a === 100 && b >= 64 && b <= 127));
26
26
  }
27
+ let networkProxyResolver = null;
28
+ /**
29
+ * 宿主注入的代理解析器:按目标 URL 返回代理 agents(null = 直连)。
30
+ * 注入后重定向链的每一跳都会重新询问;DNS pin 仅在直连时保留。
31
+ */
32
+ export function setNetworkProxyResolver(resolver) {
33
+ networkProxyResolver = typeof resolver === 'function' ? resolver : null;
34
+ }
27
35
  export async function requestNetwork(input, privateAllowed, signal, redirects = 0) {
28
36
  const url = new URL(input.url);
29
37
  if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
@@ -38,8 +46,9 @@ export async function requestNetwork(input, privateAllowed, signal, redirects =
38
46
  throw new Error('请先授予局域网访问权限');
39
47
  const chosen = addresses[0];
40
48
  const pin = ((_hostname, options, callback) => options?.all ? callback(null, [chosen]) : callback(null, chosen.address, chosen.family));
41
- const httpAgent = new HttpAgent({ lookup: pin });
42
- const httpsAgent = new HttpsAgent({ lookup: pin });
49
+ const proxyAgents = networkProxyResolver?.(url.href) ?? null;
50
+ const httpAgent = proxyAgents?.httpAgent ?? new HttpAgent({ lookup: pin });
51
+ const httpsAgent = proxyAgents?.httpsAgent ?? new HttpsAgent({ lookup: pin });
43
52
  const headers = {};
44
53
  for (const [name, value] of Object.entries(input.headers ?? {})) {
45
54
  if (/^(host|connection|content-length|transfer-encoding|proxy-.*|upgrade)$/i.test(name))
@@ -104,7 +113,9 @@ export async function requestNetwork(input, privateAllowed, signal, redirects =
104
113
  throw error;
105
114
  }
106
115
  finally {
107
- httpAgent.destroy();
108
- httpsAgent.destroy();
116
+ if (!proxyAgents) {
117
+ httpAgent.destroy();
118
+ httpsAgent.destroy();
119
+ }
109
120
  }
110
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiqianjiang/ceru-plugin-core",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "Ceru Music v2 plugin Core runtime and Host adapter boundary",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -57,8 +57,8 @@
57
57
  "socket.io-client": "^4.8.3",
58
58
  "ws": "^8.21.3",
59
59
  "axios": "^1.13.2",
60
- "@shiqianjiang/ceru-plugin-issuer": "0.3.11",
61
- "@shiqianjiang/ceru-plugin-sdk": "0.3.11"
60
+ "@shiqianjiang/ceru-plugin-issuer": "0.3.13",
61
+ "@shiqianjiang/ceru-plugin-sdk": "0.3.13"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public",