dsh-mobile-plugin 0.2.2 → 0.4.0
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/config/agent-presets/standard/agent.cordis.yml +7 -5
- package/dsh-mobile-credentials/lib/credentials.js +14 -1
- package/host.js +86 -3
- package/lib/host-compat.cjs +132 -0
- package/lib/impl.js +2 -2
- package/lib/mobile/credential-upgrade.js +24 -0
- package/lib/panel/index.html +11 -11
- package/lib/shared/device-headers.js +64 -0
- package/package.json +8 -5
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 手机每次请求顺带上来的身份:设备名、平台、系统版本、App 版本。
|
|
5
|
+
*
|
|
6
|
+
* ## 为什么要有这几个头
|
|
7
|
+
*
|
|
8
|
+
* 这几格以前**只在配对那一刻写一次**(见 `dsh-mobile-credentials/lib/credentials.js` 的
|
|
9
|
+
* `deviceMeta`),之后谁都不碰。后果是三件事一起出现(2026-10-26 用户报的就是它们):
|
|
10
|
+
*
|
|
11
|
+
* 1. **App 升级之后面板还报配对时的旧版本** —— 那一格永远不变;
|
|
12
|
+
* 2. **旧会话升级进来的记录没有名字** —— 面板只能画「未知设备」;
|
|
13
|
+
* 3. 面板把「加密」读成「已是最新」,其实那只说明这枚凭据带设备密钥。
|
|
14
|
+
*
|
|
15
|
+
* 身份属于「每一次请求都顺手知道」的信息,不该是一张一次性的照片。现在手机在统一的鉴权头
|
|
16
|
+
* 里带上这四样,宿主在鉴权通过那一刻(`lib/impl.js` 的 `onAuthorized`)把它们写回凭据记录。
|
|
17
|
+
*
|
|
18
|
+
* ## 口径
|
|
19
|
+
*
|
|
20
|
+
* - **缺一个就少写一个**:老版本 App 根本不带这些头,那时必须保持记录里原来的值,
|
|
21
|
+
* 绝不能把已经有的名字冲成空串(那会把一个好好的设备变成「未知设备」)。
|
|
22
|
+
* - 头的值是手机自报的,长度交给凭据库的 `truncate` 截断,这里不重复做校验。
|
|
23
|
+
* - 名字是**用户自己起的**,不参与任何判断,只用于显示。
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** 手机自报身份用的四个头(App 侧在 `app/src/services/viewmodels/authHeaders.ts` 里写)。 */
|
|
27
|
+
const DEVICE_NAME_HEADER = 'x-dsh-device-name';
|
|
28
|
+
const PLATFORM_HEADER = 'x-dsh-platform';
|
|
29
|
+
const OS_VERSION_HEADER = 'x-dsh-os-version';
|
|
30
|
+
const APP_VERSION_HEADER = 'x-dsh-app-version';
|
|
31
|
+
|
|
32
|
+
/** 一个头拿成字符串(重复头会是数组,只认第一个)。 */
|
|
33
|
+
function headerText(headers, name) {
|
|
34
|
+
const value = headers && headers[name];
|
|
35
|
+
if (typeof value === 'string') return value.trim();
|
|
36
|
+
if (Array.isArray(value) && typeof value[0] === 'string') return value[0].trim();
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 这次请求带上来的身份。**没带的格子不出现在返回对象里**(不是空串)——
|
|
42
|
+
* 凭据库那边按「有哪几格就写哪几格」合并,空串会变成「把名字清掉」。
|
|
43
|
+
*/
|
|
44
|
+
function deviceMetaFromHeaders(req) {
|
|
45
|
+
const headers = req?.headers || {};
|
|
46
|
+
const meta = {};
|
|
47
|
+
const name = headerText(headers, DEVICE_NAME_HEADER);
|
|
48
|
+
if (name) meta.name = name;
|
|
49
|
+
const platform = headerText(headers, PLATFORM_HEADER);
|
|
50
|
+
if (platform) meta.platform = platform;
|
|
51
|
+
const osVersion = headerText(headers, OS_VERSION_HEADER);
|
|
52
|
+
if (osVersion) meta.osVersion = osVersion;
|
|
53
|
+
const appVersion = headerText(headers, APP_VERSION_HEADER);
|
|
54
|
+
if (appVersion) meta.appVersion = appVersion;
|
|
55
|
+
return meta;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
APP_VERSION_HEADER,
|
|
60
|
+
DEVICE_NAME_HEADER,
|
|
61
|
+
OS_VERSION_HEADER,
|
|
62
|
+
PLATFORM_HEADER,
|
|
63
|
+
deviceMetaFromHeaders,
|
|
64
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mobile-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (0.2.
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"engines": {
|
|
7
|
+
"dsh": ">=0.2.0 <0.3.0"
|
|
8
|
+
},
|
|
6
9
|
"type": "module",
|
|
7
10
|
"main": "lib/index.js",
|
|
8
11
|
"bin": {
|
|
@@ -46,8 +49,6 @@
|
|
|
46
49
|
"release:check": "node scripts/preflight-release.mjs"
|
|
47
50
|
},
|
|
48
51
|
"dependencies": {
|
|
49
|
-
"@deepseek-ai/dsh-tool-ask-user": "0.2.1-rc.2",
|
|
50
|
-
"@deepseek-ai/dsh-tool-present": "0.2.1-rc.2",
|
|
51
52
|
"qrcode": "1.5.4",
|
|
52
53
|
"ws": "8.18.0"
|
|
53
54
|
},
|
|
@@ -73,7 +74,9 @@
|
|
|
73
74
|
}
|
|
74
75
|
},
|
|
75
76
|
"devDependencies": {
|
|
76
|
-
"@deepseek-ai/dsh-host-directory-picker-browse": "0.
|
|
77
|
+
"@deepseek-ai/dsh-host-directory-picker-browse": "^0.2.1-rc.3",
|
|
78
|
+
"@deepseek-ai/dsh-tool-ask-user": "^0.2.1-rc.3",
|
|
79
|
+
"@deepseek-ai/dsh-tool-present": "^0.2.1-rc.3",
|
|
77
80
|
"yaml": "2.9.1"
|
|
78
81
|
}
|
|
79
82
|
}
|