dsh-web-mobile-pmsfh 0.0.0-stage → 3.2.5
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/LICENSE +21 -0
- package/README.en.md +146 -0
- package/README.md +145 -2
- package/client/client.js +68 -0
- package/cordis.patch.yml +4 -0
- package/lib/index.js +136 -0
- package/mobile/app.css +766 -0
- package/mobile/app.js +2388 -0
- package/mobile/index.html +18 -0
- package/mobile/vendor/markdown-it-cjk-friendly.min.js +1 -0
- package/mobile/vendor/markdown-it.min.js +2 -0
- package/package.json +40 -4
- package/types.d.ts +301 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 renlang119
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# dsh-web-mobile-pmsfh
|
|
2
|
+
|
|
3
|
+
[简体中文](README.md) | **English**
|
|
4
|
+
|
|
5
|
+
A dedicated mobile page for DeepSeek Harness: open the main site on a mobile device and you land in a separate interface built for narrow screens, with sessions, chat, attachments, and approvals in one place. The desktop client UI and the upstream repository stay untouched.
|
|
6
|
+
|
|
7
|
+
It serves a standalone mobile UI at `/dsh-web-mobile-pmsfh/`, calls DSH's own APIs directly, does not load the official frontend, and does not modify official code.
|
|
8
|
+
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/topics/dsh-plugin)
|
|
11
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Sessions**: grouped by workspace and collapsible; create, rename, and delete workspaces — deleting only removes a workspace from the list, keeping the directory and session records, and its sessions move to "Ungrouped"; long-press a session to archive it, and pick a permission level when creating one (read-only / workspace write / Full access, with a risk confirmation)
|
|
16
|
+
- **Conversations**: streaming output, collapsible reasoning, a notice when context is compacted; markdown and code block rendering, stop while generating, queued messages stay visible, scroll up for earlier messages, stick to the bottom with a one-tap return
|
|
17
|
+
- **Attachments**: pick files on the device and send them with the message through the official conversation attachment channel, 8 MB per file, removable before sending, not written to the workspace
|
|
18
|
+
- **Approvals**: out-of-scope operations raise an approval card with allow once, deny, enter your own, or later
|
|
19
|
+
- **Models**: switch model and reasoning level within a session
|
|
20
|
+
- **Files**: list and download workspace files, read-only
|
|
21
|
+
- **Interface**: Chinese and English follow the browser, light and dark follow the system; "Open desktop version" at the bottom of the list applies to this browsing session only; uses the existing DSH login state with guidance when it expires and a sign-out action
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
Requirements: DSH `0.2.2-rc.1` (see Compatibility), Node 24 or later, and pnpm for the `dsh plugin` command.
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
corepack enable
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
or
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm i -g pnpm
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Once pnpm is available, install the plugin:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
git clone https://github.com/renlang119/dsh-web-mobile-pmsfh.git
|
|
41
|
+
dsh plugin --profile web add ./dsh-web-mobile-pmsfh
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The `dsh plugin` command above installs the plugin for the server started by `dsh web`. The DSH desktop client manages its own plugins; to use it there too, open Settings → Plugins in the client.
|
|
45
|
+
|
|
46
|
+
The install is a link, so keep the cloned directory.
|
|
47
|
+
|
|
48
|
+
Then restart DSH however your deployment runs it:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
sudo systemctl restart dsh-web
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
First visit: opening the main site on a mobile device redirects automatically, or you can open `https://<domain>/dsh-web-mobile-pmsfh/` directly; if it does not redirect, check whether "Open desktop version" was chosen in this browsing session — that preference is session-scoped (sessionStorage) and resets when the page is closed.
|
|
55
|
+
|
|
56
|
+
## Compatibility
|
|
57
|
+
|
|
58
|
+
| DSH | Status |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `0.2.2-rc.1` | Supported, running in production |
|
|
61
|
+
| other `0.2.x` | Untested; endpoint signatures may differ |
|
|
62
|
+
|
|
63
|
+
## Tech Stack
|
|
64
|
+
|
|
65
|
+
Node 24 · DeepSeek Harness `0.2.2-rc.1` · Cordis plugin · vanilla JavaScript (no build) · markdown-it
|
|
66
|
+
|
|
67
|
+
The mobile page is a single-page vanilla JS app; it does not load the official frontend or go through a bundler, and it has no extra runtime dependencies.
|
|
68
|
+
|
|
69
|
+
## Project Structure
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
dsh-web-mobile-pmsfh/
|
|
73
|
+
├─ lib/index.js host half: static routes and connection.admit checks
|
|
74
|
+
├─ client/client.js desktop client: redirect narrow screens to the mobile page
|
|
75
|
+
├─ mobile/ mobile page
|
|
76
|
+
│ ├─ index.html
|
|
77
|
+
│ ├─ app.js / app.css
|
|
78
|
+
│ └─ vendor/ markdown-it and CJK punctuation patch
|
|
79
|
+
├─ cordis.patch.yml plugin mount configuration
|
|
80
|
+
├─ types.d.ts protocol and data shapes
|
|
81
|
+
└─ tsconfig.json type-check only, no emit
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Quality
|
|
85
|
+
|
|
86
|
+
- **Types**: `types.d.ts` defines the protocol and data shapes; sources use `@ts-check`; `tsc --noEmit` is clean
|
|
87
|
+
- **Syntax**: `node --check` covers the host and the mobile page
|
|
88
|
+
- **Assets**: content-hash ETags return 304 on repeat visits and take effect right after an upgrade
|
|
89
|
+
- **No build chain**: the repository is the runtime artifact; no install or build step
|
|
90
|
+
|
|
91
|
+
## Routes
|
|
92
|
+
|
|
93
|
+
| Path | Content |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `/dsh-web-mobile-pmsfh/` | Mobile page |
|
|
96
|
+
| `/dsh-web-mobile-pmsfh/app.js` | Page script |
|
|
97
|
+
| `/dsh-web-mobile-pmsfh/app.css` | Page styles |
|
|
98
|
+
| `/dsh-web-mobile-pmsfh/vendor/markdown-it.min.js` | Markdown rendering |
|
|
99
|
+
| `/dsh-web-mobile-pmsfh/vendor/markdown-it-cjk-friendly.min.js` | `**` handling for CJK punctuation |
|
|
100
|
+
|
|
101
|
+
The bare path redirects with a 302 to the trailing-slash form.
|
|
102
|
+
|
|
103
|
+
## Security
|
|
104
|
+
|
|
105
|
+
- No account system of its own: unauthenticated access to the plugin page is rejected by DSH's login check (401); if that check service is unavailable, the plugin returns 503 and does not let the request through.
|
|
106
|
+
- When exposing the service through a reverse proxy, add authentication at the proxy layer (Basic Auth / OIDC / mTLS) and do not expose the DSH port directly to the internet.
|
|
107
|
+
- Model output is rendered by markdown-it (`html: false`), and links are limited to `http/https/mailto`; HTML responses carry CSP, nosniff, no-referrer, and `X-Frame-Options: DENY`.
|
|
108
|
+
|
|
109
|
+
## Known limitations
|
|
110
|
+
|
|
111
|
+
- Subagent sessions are not listed (matching the desktop client: subagents do not take top-level rows).
|
|
112
|
+
- Attachments use the official conversation attachment channel and are not written to the workspace; workspace files are read-only.
|
|
113
|
+
- The plugin relies on DSH's internal session-check endpoint: if a DSH upgrade changes it, the plugin deactivates rather than allowing access.
|
|
114
|
+
- Single-user use is recommended: DSH itself does not separate accounts, so a shared deployment needs isolation in front.
|
|
115
|
+
|
|
116
|
+
## Update
|
|
117
|
+
|
|
118
|
+
Pull the latest code in the cloned directory and restart:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
git pull
|
|
122
|
+
sudo systemctl restart dsh-web
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Uninstall
|
|
126
|
+
|
|
127
|
+
Remove the plugin from the `web` profile and restart:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
dsh plugin --profile web remove dsh-web-mobile-pmsfh
|
|
131
|
+
sudo systemctl restart dsh-web
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Development
|
|
135
|
+
|
|
136
|
+
For local debugging, use a separate `DSH_HOME` and port so production data is unaffected:
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
DSH_HOME=~/.dsh-test dsh --profile web --no-open --port 3080
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Implementation notes: static assets get content-hash ETags and return 304 on repeat visits; bundled dependencies are cached for 30 days.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
[MIT](LICENSE)
|
package/README.md
CHANGED
|
@@ -1,3 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-web-mobile-pmsfh
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**简体中文** | [English](README.en.md)
|
|
4
|
+
|
|
5
|
+
DeepSeek Harness 的移动端页面插件:移动设备打开主站自动进入,会话、聊天、附件、审批都在这个为窄屏设计的独立界面里,桌面端 UI 与主仓库零改动
|
|
6
|
+
|
|
7
|
+
它在 `/dsh-web-mobile-pmsfh/` 下挂一套独立的移动页,直接调 DSH 自己的接口,不加载官方前端,也不改官方代码
|
|
8
|
+
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/topics/dsh-plugin)
|
|
11
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
12
|
+
|
|
13
|
+
## 功能概览
|
|
14
|
+
|
|
15
|
+
- **会话**:按工作区分组折叠;新建、重命名、删除工作区,删除只从列表移除,目录与会话记录保留,会话转入「未分组」;长按会话归档,新建时选权限档位(只读 / 工作区可写 / Full access,需确认风险)
|
|
16
|
+
- **对话**:流式输出、思考过程折叠、上下文压缩提示;markdown 与代码块渲染,生成中可停止,后续消息排队可见,上翻加载更早消息,贴底跟随与一键回到底部
|
|
17
|
+
- **附件**:移动设备上选文件随消息发送,走官方对话附件通道,单文件上限 8 MB,发送前可移除,不落工作区
|
|
18
|
+
- **审批**:越界操作弹审批卡,支持允许一次、拒绝、自行输入或稍后
|
|
19
|
+
- **模型**:会话内切换模型与推理等级
|
|
20
|
+
- **文件**:工作区文件列表与下载,只读
|
|
21
|
+
- **界面**:中英双语跟随浏览器,深浅色跟随系统;列表底部「进入桌面版」只对本次浏览生效;沿用 DSH 登录状态,过期有引导,可退出登录
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
环境要求:DSH `0.2.2-rc.1`(见「兼容性」);Node ≥ 24;`dsh plugin` 需要 pnpm
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
corepack enable
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
或
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm i -g pnpm
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
装好 pnpm 后,安装插件:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
git clone https://github.com/renlang119/dsh-web-mobile-pmsfh.git
|
|
41
|
+
dsh plugin --profile web add ./dsh-web-mobile-pmsfh
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
上面的 `dsh plugin` 命令是给 `dsh web` 启动的服务端安装插件;DSH 桌面客户端自己管理插件,如果也要在桌面端使用,在客户端的设置 → 插件页里安装
|
|
45
|
+
|
|
46
|
+
安装为 link 方式,克隆目录要保留
|
|
47
|
+
|
|
48
|
+
然后重启 DSH 服务,按你的部署方式来
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
sudo systemctl restart dsh-web
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
首次访问:用移动设备打开主站会自动跳转,也可以直接开 `https://<域名>/dsh-web-mobile-pmsfh/`,如果没跳,检查这次浏览是否点过「进入桌面版」;那是会话级偏好(sessionStorage),关掉页面重开即恢复默认
|
|
55
|
+
|
|
56
|
+
## 兼容性
|
|
57
|
+
|
|
58
|
+
| DSH | 状态 |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `0.2.2-rc.1` | 已适配,线上运行 |
|
|
61
|
+
| 其他 `0.2.x` | 未验证,端点签名可能不同 |
|
|
62
|
+
|
|
63
|
+
## 技术栈
|
|
64
|
+
|
|
65
|
+
Node 24 · DeepSeek Harness `0.2.2-rc.1` · Cordis 插件 · 原生 JavaScript(无构建)· markdown-it
|
|
66
|
+
|
|
67
|
+
移动页是单页原生 JS,不加载官方前端、不走打包器;运行时没有额外依赖,克隆下来即可用
|
|
68
|
+
|
|
69
|
+
## 项目结构
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
dsh-web-mobile-pmsfh/
|
|
73
|
+
├─ lib/index.js host 半:静态路由与 connection.admit 校验
|
|
74
|
+
├─ client/client.js 桌面端:窄屏设备跳转移动页
|
|
75
|
+
├─ mobile/ 移动页
|
|
76
|
+
│ ├─ index.html
|
|
77
|
+
│ ├─ app.js / app.css
|
|
78
|
+
│ └─ vendor/ markdown-it 与中文标点兼容补丁
|
|
79
|
+
├─ cordis.patch.yml 插件挂载配置
|
|
80
|
+
├─ types.d.ts 协议与数据形状
|
|
81
|
+
└─ tsconfig.json 只做类型检查,不产出
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## 质量
|
|
85
|
+
|
|
86
|
+
- **类型检查**:`types.d.ts` 定义协议与数据形状,源码带 `@ts-check`,`tsc --noEmit` 全绿
|
|
87
|
+
- **语法检查**:`node --check` 覆盖 host 与移动页
|
|
88
|
+
- **静态资源**:按内容哈希发 ETag,重复访问返回 304,升级后立即可见
|
|
89
|
+
- **无构建链**:仓库即运行产物,不需要 install 或 build
|
|
90
|
+
|
|
91
|
+
## 路由
|
|
92
|
+
|
|
93
|
+
| 路径 | 内容 |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `/dsh-web-mobile-pmsfh/` | 移动页 |
|
|
96
|
+
| `/dsh-web-mobile-pmsfh/app.js` | 页面脚本 |
|
|
97
|
+
| `/dsh-web-mobile-pmsfh/app.css` | 页面样式 |
|
|
98
|
+
| `/dsh-web-mobile-pmsfh/vendor/markdown-it.min.js` | markdown 渲染 |
|
|
99
|
+
| `/dsh-web-mobile-pmsfh/vendor/markdown-it-cjk-friendly.min.js` | 中文标点下的 `**` 兼容 |
|
|
100
|
+
|
|
101
|
+
裸路径 302 到带斜杠形式
|
|
102
|
+
|
|
103
|
+
## 安全
|
|
104
|
+
|
|
105
|
+
- 不自带账号体系:未登录访问插件页面会被 DSH 的登录校验直接拒绝(401);校验服务不可用时返回 503,不放行
|
|
106
|
+
- 反向代理公开时,请在代理层加认证(Basic Auth / OIDC / mTLS),不要把 DSH 端口直接暴露到公网
|
|
107
|
+
- 模型输出经 markdown-it 渲染(`html: false`),链接白名单仅 `http/https/mailto`;HTML 响应带 CSP、nosniff、no-referrer、`X-Frame-Options: DENY`
|
|
108
|
+
|
|
109
|
+
## 已知限制
|
|
110
|
+
|
|
111
|
+
- 不列子代理会话(与桌面端一致:子代理不占顶层行)
|
|
112
|
+
- 附件走官方对话附件通道,不写入工作区;工作区文件只读
|
|
113
|
+
- 依赖 DSH 内部的会话校验接口:DSH 升级若改动它,插件会不激活而不是放行
|
|
114
|
+
- 建议只单人使用:DSH 本身没有多账号区分,多人共用要自己在外面做隔离
|
|
115
|
+
|
|
116
|
+
## 更新
|
|
117
|
+
|
|
118
|
+
在克隆目录拉取最新代码后重启:
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
git pull
|
|
122
|
+
sudo systemctl restart dsh-web
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 卸载
|
|
126
|
+
|
|
127
|
+
从 `web` profile 移除插件后重启:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
dsh plugin --profile web remove dsh-web-mobile-pmsfh
|
|
131
|
+
sudo systemctl restart dsh-web
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## 开发
|
|
135
|
+
|
|
136
|
+
本地调试建议用独立 `DSH_HOME` 和端口,避免影响生产数据:
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
DSH_HOME=~/.dsh-test dsh --profile web --no-open --port 3080
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
实现要点:静态资源按内容哈希打 ETag,重复访问回 304;内置依赖缓存 30 天
|
|
143
|
+
|
|
144
|
+
## 许可证
|
|
145
|
+
|
|
146
|
+
[MIT](LICENSE)
|
package/client/client.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-web-mobile-pmsfh client bundle (v2.2, hand-written lazy-CJS factory).
|
|
3
|
+
*
|
|
4
|
+
* Role: bounce coarse-pointer narrow-viewport browsers (phones) from the
|
|
5
|
+
* official SPA to the standalone mobile page served by the plugin's host half
|
|
6
|
+
* at /dsh-web-mobile-pmsfh/. The old CSS-overlay drawer/touch-target code is retired.
|
|
7
|
+
*
|
|
8
|
+
* Escape hatch (session-scoped): the mobile page's "desktop version" link sets
|
|
9
|
+
* sessionStorage['dsh-web-mobile-pmsfh:desktop'] = '1' before navigating to '/',
|
|
10
|
+
* and this bundle then stays out of the way for that browsing session only —
|
|
11
|
+
* the next fresh visit defaults back to the mobile page.
|
|
12
|
+
*
|
|
13
|
+
* Legacy note: v2.0/v2.1 used a PERMANENT localStorage flag that stranded
|
|
14
|
+
* users on the desktop UI with no way back. This bundle clears that legacy
|
|
15
|
+
* flag on every load so previously-locked browsers recover mobile default.
|
|
16
|
+
*/
|
|
17
|
+
window.__ModuleLoader__.load({
|
|
18
|
+
id: 'dsh-web-mobile-pmsfh',
|
|
19
|
+
factory: function (require) {
|
|
20
|
+
var module = { exports: {} }
|
|
21
|
+
var exports = module.exports
|
|
22
|
+
|
|
23
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
24
|
+
exports.name = 'dsh-web-mobile-pmsfh'
|
|
25
|
+
exports.inject = []
|
|
26
|
+
exports.apply = function () {
|
|
27
|
+
try {
|
|
28
|
+
if (location.pathname.indexOf('/dsh-web-mobile-pmsfh') === 0) return
|
|
29
|
+
// Remove the legacy permanent escape flag (one-way lock from v2.0/v2.1)
|
|
30
|
+
try { localStorage.removeItem('dsh-web-mobile-pmsfh:desktop') } catch (e) {}
|
|
31
|
+
var escaped = false
|
|
32
|
+
try { escaped = sessionStorage.getItem('dsh-web-mobile-pmsfh:desktop') === '1' } catch (e) {}
|
|
33
|
+
var coarse = window.matchMedia('(pointer: coarse)').matches
|
|
34
|
+
var narrow = window.matchMedia('(max-width: 768px)').matches
|
|
35
|
+
if (!escaped && coarse && narrow) {
|
|
36
|
+
location.replace('/dsh-web-mobile-pmsfh/')
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
// Phone chose desktop for this session: give it a way back.
|
|
40
|
+
if (escaped && coarse && narrow) addMobileFab()
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// Redirect is best-effort; never block the official UI on a failure.
|
|
43
|
+
console.warn('[dsh-web-mobile-pmsfh] redirect check failed', e)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addMobileFab() {
|
|
48
|
+
if (document.getElementById('dsh-web-mobile-pmsfh-fab')) return
|
|
49
|
+
var fab = document.createElement('a')
|
|
50
|
+
fab.id = 'dsh-web-mobile-pmsfh-fab'
|
|
51
|
+
fab.href = '/dsh-web-mobile-pmsfh/'
|
|
52
|
+
fab.textContent = '📱'
|
|
53
|
+
fab.title = '移动版'
|
|
54
|
+
fab.setAttribute('aria-label', '移动版')
|
|
55
|
+
fab.style.cssText = 'position:fixed;right:12px;bottom:calc(12px + env(safe-area-inset-bottom,0px));' +
|
|
56
|
+
'z-index:2200;width:44px;height:44px;border-radius:22px;display:flex;align-items:center;' +
|
|
57
|
+
'justify-content:center;background:#1a1a1a;color:#fff;font-size:20px;text-decoration:none;' +
|
|
58
|
+
'box-shadow:0 2px 10px rgba(0,0,0,.35);opacity:.85;'
|
|
59
|
+
var append = function () {
|
|
60
|
+
if (document.body && !document.getElementById('dsh-web-mobile-pmsfh-fab')) document.body.appendChild(fab)
|
|
61
|
+
}
|
|
62
|
+
if (document.body) append()
|
|
63
|
+
else document.addEventListener('DOMContentLoaded', append)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return module.exports
|
|
67
|
+
},
|
|
68
|
+
})
|
package/cordis.patch.yml
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* dsh-web-mobile-pmsfh host entry (v2.0): serves the standalone mobile page.
|
|
4
|
+
*
|
|
5
|
+
* The plugin's host half registers static routes under /dsh-web-mobile-pmsfh/ that
|
|
6
|
+
* serve a self-contained mini chat app (mobile/index.html + app.js + app.css,
|
|
7
|
+
* read from disk per request so a plugin update + dsh-web restart always
|
|
8
|
+
* serves fresh bytes). The page talks directly to the DSH wire protocol
|
|
9
|
+
* (POST /api/<method>, WS /api/events.mux, POST /api/respond) — it never
|
|
10
|
+
* loads the official SPA bundle.
|
|
11
|
+
*
|
|
12
|
+
* The client half (client/client.js) only redirects coarse-pointer
|
|
13
|
+
* narrow-viewport browsers from the official SPA to the mobile page.
|
|
14
|
+
*
|
|
15
|
+
* Zero main-repo changes. All routes sit behind the login gate (dsh-auth-gate).
|
|
16
|
+
*/
|
|
17
|
+
import { createHash } from 'node:crypto'
|
|
18
|
+
import { readFile } from 'node:fs/promises'
|
|
19
|
+
import { dirname, join } from 'node:path'
|
|
20
|
+
import { fileURLToPath } from 'node:url'
|
|
21
|
+
|
|
22
|
+
/** @typedef {import('../types.d.ts').CordisContext} CordisContext */
|
|
23
|
+
/** @typedef {import('../types.d.ts').IncomingMessage} IncomingMessage */
|
|
24
|
+
/** @typedef {import('../types.d.ts').ServerResponse} ServerResponse */
|
|
25
|
+
|
|
26
|
+
/** Cordis plugin name. */
|
|
27
|
+
export const name = 'dsh-web-mobile-pmsfh'
|
|
28
|
+
|
|
29
|
+
/** Required services: the HTTP carrier + the host connection (for browser auth). */
|
|
30
|
+
export const inject = ['webServer', 'connection']
|
|
31
|
+
|
|
32
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', 'mobile')
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Security headers for the HTML entry. The page renders model output through
|
|
36
|
+
* markdown-it (html:false) into innerHTML, so a CSP is the second line of
|
|
37
|
+
* defence against any sanitiser bypass; frame-ancestors/nosniff/referrer
|
|
38
|
+
* round out the standalone-deployment baseline.
|
|
39
|
+
*/
|
|
40
|
+
const HTML_HEADERS = {
|
|
41
|
+
'content-security-policy': "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' ws: wss:; frame-ancestors 'none'; base-uri 'none'; form-action 'self'",
|
|
42
|
+
'x-content-type-options': 'nosniff',
|
|
43
|
+
'referrer-policy': 'no-referrer',
|
|
44
|
+
'x-frame-options': 'DENY',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Whitelisted asset table — request path → file + content type. */
|
|
48
|
+
const ASSETS = new Map([
|
|
49
|
+
['/dsh-web-mobile-pmsfh/', { file: 'index.html', type: 'text/html; charset=utf-8', cache: 'no-cache', headers: HTML_HEADERS }],
|
|
50
|
+
['/dsh-web-mobile-pmsfh/app.js', { file: 'app.js', type: 'text/javascript; charset=utf-8', cache: 'no-cache' }],
|
|
51
|
+
['/dsh-web-mobile-pmsfh/app.css', { file: 'app.css', type: 'text/css; charset=utf-8', cache: 'no-cache' }],
|
|
52
|
+
// Vendored, version-pinned upstream files: immutable, cache hard.
|
|
53
|
+
['/dsh-web-mobile-pmsfh/vendor/markdown-it.min.js', { file: 'vendor/markdown-it.min.js', type: 'text/javascript; charset=utf-8', cache: 'public, max-age=2592000, immutable' }],
|
|
54
|
+
['/dsh-web-mobile-pmsfh/vendor/markdown-it-cjk-friendly.min.js', { file: 'vendor/markdown-it-cjk-friendly.min.js', type: 'text/javascript; charset=utf-8', cache: 'public, max-age=2592000, immutable' }],
|
|
55
|
+
])
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gate static routes with the host's own browser-session check.
|
|
59
|
+
*
|
|
60
|
+
* DSH's token gate only wraps the `/api` prefix; a third-party exact route is
|
|
61
|
+
* otherwise reachable without the DSH cookie. `client-connection` exposes the
|
|
62
|
+
* same admission check the API uses (trusted authority + browser session), so
|
|
63
|
+
* an unauthenticated request gets the same 401 here. When a login gate such as
|
|
64
|
+
* dsh-auth-gate sits in front, its 302 still wins for navigations.
|
|
65
|
+
* @param {CordisContext} ctx
|
|
66
|
+
* @param {IncomingMessage} req
|
|
67
|
+
* @param {ServerResponse} res
|
|
68
|
+
* @returns {boolean} true when the request may proceed
|
|
69
|
+
*/
|
|
70
|
+
function admit(ctx, req, res) {
|
|
71
|
+
try {
|
|
72
|
+
const svc = typeof ctx.get === 'function' ? ctx.get('connection') : ctx.connection
|
|
73
|
+
if (!svc || typeof svc.admit !== 'function') throw new Error('connection service unavailable')
|
|
74
|
+
const admission = svc.admit(req)
|
|
75
|
+
if (admission && 'rejection' in admission) {
|
|
76
|
+
res.writeHead(/** @type {number} */ (admission.rejection), { 'content-type': 'text/plain; charset=utf-8' })
|
|
77
|
+
res.end(admission.rejection === 401 ? 'unauthorized' : 'forbidden')
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
return true
|
|
81
|
+
} catch {
|
|
82
|
+
res.writeHead(503, { 'content-type': 'text/plain; charset=utf-8' })
|
|
83
|
+
res.end('auth unavailable')
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @param {CordisContext} ctx */
|
|
89
|
+
export function apply(ctx) {
|
|
90
|
+
const webServer = ctx.webServer
|
|
91
|
+
if (!webServer) throw new Error('webServer service unavailable')
|
|
92
|
+
ctx.effect(() => {
|
|
93
|
+
/** @type {(() => void)[]} */
|
|
94
|
+
const disposers = []
|
|
95
|
+
// Bare path (no trailing slash) → redirect to the canonical slash form.
|
|
96
|
+
disposers.push(webServer.register({
|
|
97
|
+
kind: 'exact',
|
|
98
|
+
path: '/dsh-web-mobile-pmsfh',
|
|
99
|
+
/** @param {IncomingMessage} req @param {ServerResponse} res */
|
|
100
|
+
handler: async (req, res) => {
|
|
101
|
+
if (!admit(ctx, req, res)) return
|
|
102
|
+
res.writeHead(302, { location: '/dsh-web-mobile-pmsfh/' })
|
|
103
|
+
res.end()
|
|
104
|
+
},
|
|
105
|
+
}))
|
|
106
|
+
for (const [path, spec] of ASSETS) {
|
|
107
|
+
disposers.push(webServer.register({
|
|
108
|
+
kind: 'exact',
|
|
109
|
+
path,
|
|
110
|
+
/** @param {IncomingMessage} req @param {ServerResponse} res */
|
|
111
|
+
handler: async (req, res) => {
|
|
112
|
+
if (!admit(ctx, req, res)) return
|
|
113
|
+
try {
|
|
114
|
+
const data = await readFile(join(ROOT, spec.file))
|
|
115
|
+
// Content hash as a validator: `no-cache` keeps updates immediate,
|
|
116
|
+
// the ETag turns a repeat visit into a bodiless 304 instead of a
|
|
117
|
+
// full re-download of app.js.
|
|
118
|
+
const etag = '"' + createHash('sha1').update(data).digest('base64url').slice(0, 20) + '"'
|
|
119
|
+
const headers = Object.assign({ 'content-type': spec.type, 'cache-control': spec.cache, etag }, spec.headers || {})
|
|
120
|
+
if (req.headers['if-none-match'] === etag) {
|
|
121
|
+
res.writeHead(304, headers)
|
|
122
|
+
res.end()
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
res.writeHead(200, headers)
|
|
126
|
+
res.end(data)
|
|
127
|
+
} catch {
|
|
128
|
+
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' })
|
|
129
|
+
res.end('not found')
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
}))
|
|
133
|
+
}
|
|
134
|
+
return () => { for (const d of disposers) d() }
|
|
135
|
+
}, 'dsh-web-mobile-pmsfh routes')
|
|
136
|
+
}
|