@michengai/dsh-im-connect 1.0.12 → 1.0.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/CHANGELOG.md +8 -0
- package/CHANGELOG.zh-CN.md +8 -0
- package/README.md +28 -3
- package/README.zh-CN.md +28 -3
- package/client.js +378 -11
- package/lib/api-base.d.ts +21 -0
- package/lib/api-base.d.ts.map +1 -0
- package/lib/api-base.js +51 -0
- package/lib/api-base.js.map +1 -0
- package/lib/client.js +463 -15
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -6
- package/lib/index.js.map +1 -1
- package/lib/manager.d.ts +7 -0
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +75 -0
- package/lib/manager.js.map +1 -1
- package/lib/plugin-updater.d.ts +1 -0
- package/lib/plugin-updater.d.ts.map +1 -1
- package/lib/plugin-updater.js +7 -0
- package/lib/plugin-updater.js.map +1 -1
- package/package.json +1 -1
- package/src/api-base.ts +45 -0
- package/src/index.ts +12 -6
- package/src/manager.ts +78 -1
- package/src/plugin-update-ui.js +36 -5
- package/src/plugin-updater.ts +8 -1
package/lib/api-base.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API 基址解析:把插件自己的根绝对路径端点解析到页面实际所在的 base 之下。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要:DSH 可能被挂在带路径前缀的反向代理后面(例如 https://host/app/dsh/,
|
|
5
|
+
* 网关转发前剥掉前缀)。此时浏览器把根绝对路径 "/api/..." 解析到站点根,前缀丢失,
|
|
6
|
+
* 网关返回自己的 HTML 404,面板就报「服务端返回非 JSON 响应(HTTP 404)」。
|
|
7
|
+
*
|
|
8
|
+
* 为什么这么解析:宿主前端同样以页面 base 解析 API 路径(参见 dsh-client-connection 的
|
|
9
|
+
* openConnectionWebSocket 与 dsh-client-file-upload 的 new URL(path, document.baseURI)),
|
|
10
|
+
* 这里沿用同一约定——先去掉前导 "/",再用 new URL 相对解析;若直接 new URL("/api/x", base)
|
|
11
|
+
* 会丢弃 base 的路径段,前缀就没了。
|
|
12
|
+
*/
|
|
13
|
+
/** 页面基准地址;末尾补斜杠,避免 /app/dsh 这类无斜杠页面把前缀解析掉一级。 */
|
|
14
|
+
function pageBaseHref() {
|
|
15
|
+
const doc = globalThis.document;
|
|
16
|
+
if (typeof doc === 'undefined' || doc === null)
|
|
17
|
+
return undefined;
|
|
18
|
+
const raw = doc.baseURI;
|
|
19
|
+
if (typeof raw !== 'string' || raw === '')
|
|
20
|
+
return undefined;
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(raw);
|
|
23
|
+
if (!url.pathname.endsWith('/'))
|
|
24
|
+
url.pathname += '/';
|
|
25
|
+
return url.href;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 解析插件端点 URL。
|
|
33
|
+
*
|
|
34
|
+
* @param path 端点路径,通常是 "/api/dsh-im-connect/xxx" 这类根绝对路径。
|
|
35
|
+
* @returns 基于页面 base 的绝对 URL;相对路径、完整 URL、协议相对 URL、无 document
|
|
36
|
+
* 或 base 非法时原样返回,保证非浏览器环境与测试夹具行为不变。
|
|
37
|
+
*/
|
|
38
|
+
export function resolveApiUrl(path) {
|
|
39
|
+
if (typeof path !== 'string' || path.charAt(0) !== '/' || path.charAt(1) === '/')
|
|
40
|
+
return path;
|
|
41
|
+
const base = pageBaseHref();
|
|
42
|
+
if (base === undefined)
|
|
43
|
+
return path;
|
|
44
|
+
try {
|
|
45
|
+
return new URL(path.slice(1), base).href;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return path;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=api-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-base.js","sourceRoot":"","sources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