dsh-matrix-todo 1.1.0 → 1.1.1
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/LICENSE +1 -1
- package/README.md +102 -165
- package/client.js +2 -2
- package/cordis.patch.yml +4 -4
- package/icon.svg +7 -7
- package/index.js +123 -123
- package/lib/store.js +511 -511
- package/locale/en.json +5 -5
- package/locale/zh.json +5 -5
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
- GitHub account rename: the repository moved from
|
|
6
|
+
`Zhang-Eli/dsh-matrix-todo` to `wzvx/dsh-matrix-todo`. Package metadata
|
|
7
|
+
(author/repository/homepage/bugs), README links, LICENSE and the settings
|
|
8
|
+
panel footer ("Developed by wzvx", repo/issues links) now point at the new
|
|
9
|
+
handle. No functional changes.
|
|
10
|
+
|
|
3
11
|
## 1.1.0
|
|
4
12
|
|
|
5
13
|
- First-run guide: when the panel opens on an empty store, the client sends
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,208 +1,145 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img alt="node" src="https://img.shields.io/badge/node-%3E%3D22-3178c6" />
|
|
3
|
+
<img alt="npm" src="https://img.shields.io/npm/v/dsh-matrix-todo?label=dsh-matrix-todo" />
|
|
4
|
+
<img alt="license" src="https://img.shields.io/badge/license-MIT-2ea44f" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
1
7
|
# 四象限待办 · dsh-matrix-todo
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
- 侧边栏新增入口「四象限待办」,排在自带「待办」之后
|
|
6
|
-
- 首次打开且清单为空时,自动写入一组本地化引导条目(覆盖四个象限、逾期变色与日期面板);删掉后不会再出现
|
|
7
|
-
- 矩阵视图:立即做 / 计划做 / 委托做 / 别做,四个象限自动撑满面板、各自计数
|
|
8
|
-
- 拖动四象限中心的圆点即可调整行/列比例,双击圆点恢复均分
|
|
9
|
-
- 每个象限都能直接点击空白处或底部「+ 添加」就地新增,可为该条设置截止日期
|
|
10
|
-
- 到期日临期/逾期会在行内变色标识,逾期标题转为警示色
|
|
11
|
-
- 拖动任意待办可在象限内上下排序,或直接拖到另一个象限
|
|
12
|
-
- 双击待办文字即可就地重写标题,回车保存、Esc 取消
|
|
13
|
-
- 完成一项时在**插件面板正中**(不含左侧边栏)弹出随机鼓励浮窗(中英各 8 条,避免连续重复)
|
|
14
|
-
- 顶部一键切换「四象限 ↔ 已完成」,已完成项可恢复或删除,清空需二次确认
|
|
15
|
-
- 齿轮设置:紧急列在左 / 在右、边框风格(卡片 / 田字格 / 十字线)、象限底色(纯色 / 淡彩)、圆角幅度、待办字号、文字显示、日期显示、侧栏名称、恢复默认
|
|
16
|
-
- 设置面板底部有一条链接行:左侧「反馈问题」,右侧是带头像的「*Developed by* Zhang-Eli」(都在系统浏览器中打开)
|
|
17
|
-
- 极简风:界面颜色只用 `--dsw-alias-*` 主题 token(淡彩底色由 token 混出),跟随明暗外观与配色风格
|
|
18
|
-
- 界面文案中英双语,跟随 Harness 语言设置
|
|
19
|
-
|
|
20
|
-
## 安装
|
|
9
|
+
## 1. 它是什么
|
|
21
10
|
|
|
22
|
-
|
|
11
|
+
DeepSeek Harness 的侧栏四象限待办插件。主界面就是艾森豪威尔矩阵(重要 × 紧急),右上角一键切换「已完成」视图;所有数据只存在你本机的一个 JSON 文件里。
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
- **不是一条长列表**:待办天然落在「立即做 / 计划做 / 委托做 / 别做」四个象限,拖到别的象限就自动改「重要 / 紧急」标记
|
|
14
|
+
- **到期会提醒**:当天到期加粗警示,逾期整行转红;日期(`11-15`)或倒计时(`7d`、`-3d`)两种显示可切换
|
|
15
|
+
- **首开有引导**:第一次打开且清单为空时,自动写入 7 条本地化引导待办,覆盖四个象限的用法;删掉后不再出现
|
|
16
|
+
- **布局随你调**:紧急列左右、边框风格、象限底色、圆角、字号、行列比例(拖中心圆点,双击复位)
|
|
17
|
+
- **跟随主题**:界面颜色全部取自 Harness 主题 token,明暗外观自动适配
|
|
18
|
+
- **中英双语**:文案跟随 Harness 语言设置
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
## 2. 效果预览
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
plugin_manager install_bundle target: dsh-matrix-todo
|
|
32
|
-
```
|
|
22
|
+
四象限面板(淡彩底色版):
|
|
33
23
|
|
|
34
|
-
|
|
24
|
+

|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
plugin_manager install_bundle target: <本目录绝对路径>
|
|
38
|
-
```
|
|
26
|
+
同一面板(纯净底色版):
|
|
39
27
|
|
|
40
|
-
|
|
28
|
+

|
|
41
29
|
|
|
42
|
-
|
|
30
|
+
| 区域 | 你能做什么 |
|
|
31
|
+
|---|---|
|
|
32
|
+
| 标题行(左上) | 「待办 · 重要 × 紧急」定位说明 |
|
|
33
|
+
| 顶部切换(右上) | 「四象限 ↔ 已完成」两个视图互切,已完成可恢复或删除 |
|
|
34
|
+
| 象限头部 | 象限名、重要/紧急标记、本象限计数 |
|
|
35
|
+
| 待办行 | 勾选完成;双击标题就地编辑;日期固定在最右侧 |
|
|
36
|
+
| 象限空白处 /「+ 添加」 | 就地新增一条属于该象限的待办 |
|
|
37
|
+
| 矩阵中心圆点 | 拖动调整行列比例,双击恢复均分 |
|
|
43
38
|
|
|
44
|
-
|
|
39
|
+
## 3. 快速开始
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
- 新增项直接使用该象限的重要/紧急标记,不需要先选分类。
|
|
48
|
-
- 新增区右侧的日历按钮打开日期面板:
|
|
49
|
-
- **单击**某天只预览/改选,面板保持打开,可以反复点选;
|
|
50
|
-
- **双击**某天即确定截止日期,面板关闭并**自动把这条待办加入该象限**;
|
|
51
|
-
- 面板里还能切换月份、选「今天」、或「清除」已选日期。
|
|
52
|
-
- 也可以只单击选好日期后按回车提交,效果相同(带上该日期)。
|
|
41
|
+
### 3.1 前置条件
|
|
53
42
|
|
|
54
|
-
|
|
43
|
+
| 项目 | 要求 |
|
|
44
|
+
|---|---|
|
|
45
|
+
| DeepSeek Harness | 桌面版已安装可用 |
|
|
46
|
+
| 运行环境 | Host 自带 Node.js ≥ 22,无需单独安装 |
|
|
47
|
+
| 权限 | 可读写 Harness profile 数据目录 |
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
- 日期固定在每行最右侧,两种显示方式可在设置里切换:**日期**(如 `11-11`)或**倒计时**(如 `7d`、`0d`、`-3d`)。
|
|
58
|
-
- 点日期本身会打开同一个自绘日历:单击预览、双击确认保存;「清除」可去掉日期。还没设日期的行,悬浮工具条里会出现日历按钮作为入口。
|
|
49
|
+
### 3.2 安装
|
|
59
50
|
|
|
60
|
-
|
|
51
|
+
从 npm 安装(推荐):
|
|
61
52
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
```bash
|
|
54
|
+
dsh plugin --profile desktop add dsh-matrix-todo
|
|
55
|
+
```
|
|
65
56
|
|
|
66
|
-
|
|
57
|
+
或在 Harness 的插件市场里搜索 `dsh-matrix-todo` 点击安装。
|
|
67
58
|
|
|
68
|
-
|
|
59
|
+
从源码目录安装(想直接改代码的人):
|
|
69
60
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
| 逾期完成(完成时截止日期已过) | 勉励,「完成了就好,下次早点开始」「逾期也完成了,值得肯定」等 | 品牌色箭头 |
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/wzvx/dsh-matrix-todo.git
|
|
63
|
+
```
|
|
74
64
|
|
|
75
|
-
|
|
65
|
+
然后在 Harness 插件管理工具里:
|
|
76
66
|
|
|
77
|
-
|
|
67
|
+
```text
|
|
68
|
+
plugin_manager install_bundle target: <本仓库绝对路径>
|
|
69
|
+
```
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
- 回车或点击别处保存,Esc 取消;标题去空白后为空(或没有改动)则视为放弃修改。
|
|
71
|
+
安装后**重启 DeepSeek Harness** 生效。
|
|
81
72
|
|
|
82
|
-
|
|
73
|
+
### 3.3 首次配置
|
|
83
74
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
1. 打开侧栏「四象限待办」入口。
|
|
76
|
+
2. 空清单首开自动出现 7 条引导待办,教你拖拽排序、双击编辑、日期面板。
|
|
77
|
+
3. 试一遍:把一条待办拖进别的象限;双击标题改名;点日历按钮设截止日期(单击预览、双击确认)。
|
|
78
|
+
4. 右上角齿轮可调边框、底色、字号、紧急方向;改完即时生效并自动保存。
|
|
87
79
|
|
|
88
|
-
|
|
80
|
+
### 3.4 在新环境还原
|
|
89
81
|
|
|
90
|
-
|
|
82
|
+
全部数据就一个文件:
|
|
91
83
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
| 边框风格 | 卡片 / 田字格 / 十字线 | 卡片=四个圆角框;田字格=外框 + 中间十字线;十字线=只有中间十字、无外框;默认十字线 |
|
|
96
|
-
| 象限底色 | 纯色 / 淡彩 | 淡彩用低饱和主题色给四个象限分别铺一层很淡的底色;默认纯色 |
|
|
97
|
-
| 圆角幅度 | 0–24px(步长 2) | 卡片风格作用于每个象限框,田字格/十字线风格作用于外框;默认 10px |
|
|
98
|
-
| 字号 | 11–17px(步长 1) | 待办标题与象限内输入框的字号;默认 14px |
|
|
99
|
-
| 文字显示 | 完整换行 / 单行截断 | 完整换行时内容全部展示;单行截断时超长内容以省略号收尾;默认完整换行 |
|
|
100
|
-
| 侧边栏名称 | 0–24 字 | 自定义左侧入口显示的文字,留空则用默认的「四象限待办」 |
|
|
101
|
-
| 日期显示 | 日期 / 倒计时 | 日期显示 `11-11`;倒计时显示距今天数 `7d`、`0d`、逾期 `-3d`;默认倒计时 |
|
|
102
|
-
| 恢复默认 | 按钮 | 立即回到 紧急在右 / 十字线 / 纯色 / 10px / 14px / 完整换行 / 倒计时 / 均分 |
|
|
84
|
+
```text
|
|
85
|
+
%DSH_PROFILE_DIR%\data\dsh-matrix-todo\todos.json
|
|
86
|
+
```
|
|
103
87
|
|
|
104
|
-
|
|
88
|
+
把它拷到新环境同一位置,装好插件即全部回来(待办 + 界面设置)。想放别处,在插件配置里覆盖:
|
|
105
89
|
|
|
106
|
-
|
|
90
|
+
```yaml
|
|
91
|
+
- id: matrix-todo
|
|
92
|
+
config:
|
|
93
|
+
dataPath: 'D:\notes\todos.json'
|
|
94
|
+
```
|
|
107
95
|
|
|
108
|
-
|
|
96
|
+
### 3.5 验证
|
|
109
97
|
|
|
110
|
-
|
|
98
|
+
- 重启后侧栏出现「四象限待办」;
|
|
99
|
+
- 打开面板能看到四个象限,首开空清单自动出现 7 条引导;
|
|
100
|
+
- 数据文件在上面的路径存在。
|
|
111
101
|
|
|
112
|
-
|
|
102
|
+
## 4. 设计取舍
|
|
113
103
|
|
|
114
|
-
|
|
104
|
+
- **不提供 agent 工具**:Harness 已自带待办工具 `personal_todo`,面板刻意不再暴露第二套待办语义,避免两个真源。
|
|
105
|
+
- **引导只写一次**:删掉引导即视为「已学会」,之后不会再自动回来;想再看见见常见问题。
|
|
106
|
+
- **单文件 + 原子写盘**:数据以「临时文件 + 替换」方式落盘,中途断电不损坏原文件;文件真损坏时先备份为 `todos.corrupt-<时间戳>.json`,再以空清单启动。
|
|
107
|
+
- **装完要重启**:面板在 Harness 启动时挂载,没有热更新。
|
|
108
|
+
- **颜色只用主题 token**:面板不自带配色,深色浅色模式都自动融入。
|
|
109
|
+
- **新条目排最前**:没手动排序前按创建时间倒序派生;一旦拖过,你的顺序就是最终顺序。
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
| --- | --- | --- | --- |
|
|
118
|
-
| 最左 | 反馈问题 | `https://github.com/Zhang-Eli/dsh-matrix-todo/issues` | 提 issue、报告 bug |
|
|
119
|
-
| 最右 | *Developed by* + 头像 + Zhang-Eli | `https://github.com/Zhang-Eli` | 顺序为斜体的「Developed by」、16px 圆形 GitHub 头像、用户名;只有用户名是可点击链接,跳转 GitHub |
|
|
111
|
+
## 5. 卸载与回滚
|
|
120
112
|
|
|
121
|
-
|
|
113
|
+
```bash
|
|
114
|
+
dsh plugin --profile desktop remove dsh-matrix-todo
|
|
115
|
+
```
|
|
122
116
|
|
|
123
|
-
|
|
117
|
+
或在插件市场移除,然后重启 Harness。
|
|
124
118
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
"todos": [
|
|
129
|
-
{
|
|
130
|
-
"id": "e_m3k2_ab12",
|
|
131
|
-
"title": "交周报",
|
|
132
|
-
"important": true,
|
|
133
|
-
"urgent": false,
|
|
134
|
-
"done": false,
|
|
135
|
-
"dueDate": "2026-11-15",
|
|
136
|
-
"createdAt": "2026-11-09T10:00:00.000Z",
|
|
137
|
-
"updatedAt": "2026-11-09T10:00:00.000Z",
|
|
138
|
-
"completedAt": null
|
|
139
|
-
}
|
|
140
|
-
],
|
|
141
|
-
"settings": {
|
|
142
|
-
"urgentSide": "right",
|
|
143
|
-
"frame": "cross",
|
|
144
|
-
"radius": 10,
|
|
145
|
-
"tint": "plain",
|
|
146
|
-
"fontSize": 14,
|
|
147
|
-
"dueFormat": "countdown",
|
|
148
|
-
"titleStyle": "wrap",
|
|
149
|
-
"colRatio": 0.5,
|
|
150
|
-
"rowRatio": 0.5,
|
|
151
|
-
"navLabel": ""
|
|
152
|
-
},
|
|
153
|
-
"reordered": false,
|
|
154
|
-
"seeded": true
|
|
155
|
-
}
|
|
156
|
-
```
|
|
119
|
+
- 卸载**不会**删除你的待办数据,`todos.json` 仍在数据目录;
|
|
120
|
+
- 想彻底清掉数据:删除 `%DSH_PROFILE_DIR%\data\dsh-matrix-todo\` 目录;
|
|
121
|
+
- 回滚:把备份(`todos.corrupt-<时间戳>.json` 或你自己的拷贝)恢复为 `todos.json` 再启动。
|
|
157
122
|
|
|
158
|
-
|
|
123
|
+
## 6. 常见问题
|
|
159
124
|
|
|
160
|
-
|
|
125
|
+
**装完侧栏没有「四象限待办」?**
|
|
126
|
+
重启 DeepSeek Harness,面板在启动时加载。
|
|
161
127
|
|
|
162
|
-
|
|
128
|
+
**怎么让 7 条引导待办再出现?**
|
|
129
|
+
清空全部待办,把 `todos.json` 里的 `seeded` 改成 `false`,重启 Harness 再打开面板。
|
|
163
130
|
|
|
164
|
-
|
|
131
|
+
**待办怎么变红了?**
|
|
132
|
+
截止日期已过。今天到期会加粗警示,逾期日期和标题都转红;设置里可在「日期 / 倒计时」两种显示间切换。
|
|
165
133
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
134
|
+
**手改 todos.json 好像没生效?**
|
|
135
|
+
非法值会被忽略并回落默认。请退出 Harness 后再编辑,或改完重启让它重新读取。
|
|
136
|
+
|
|
137
|
+
**换机器 / 换盘怎么迁移?**
|
|
138
|
+
拷 `todos.json` 到新环境同一位置即可;也可以用 `dataPath` 指定自定义路径(见 3.4)。
|
|
139
|
+
|
|
140
|
+
**有没有批量操作?**
|
|
141
|
+
没有多选;一次拖拽移动一条。唯一的批量入口是「清空已完成」,需要二次确认。
|
|
142
|
+
|
|
143
|
+
## 7. License
|
|
171
144
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
Host 半在 `/matrix-todo/api` 注册 prefix 路由,只接受 POST,并做同源/回环校验:
|
|
175
|
-
|
|
176
|
-
| 方法 | body | 说明 |
|
|
177
|
-
| --- | --- | --- |
|
|
178
|
-
| `list` | `{}` | 取全部待办与设置 |
|
|
179
|
-
| `seed` | `{ items: [{ title, important, urgent, dueDate? }] }` | 首次使用引导:仅在 `seeded` 为 `false` 时写入,幂等 |
|
|
180
|
-
| `create` | `{ title, important, urgent, dueDate? }` | 新建 |
|
|
181
|
-
| `update` | `{ id, title?, important?, urgent?, dueDate? }` | 改字段(含象限标记、截止日期;`dueDate: null` 清除) |
|
|
182
|
-
| `toggle` | `{ id }` | 完成 / 恢复 |
|
|
183
|
-
| `reorder` | `{ id, important?, urgent?, beforeId }` | 拖动结果:移到目标象限并插到 `beforeId` 之前(`null` = 末尾) |
|
|
184
|
-
| `remove` | `{ id }` | 删除 |
|
|
185
|
-
| `clearCompleted` | `{}` | 清空已完成 |
|
|
186
|
-
| `saveSettings` | `{ urgentSide?, frame?, radius?, tint?, fontSize?, dueFormat?, titleStyle?, colRatio?, rowRatio?, navLabel? }` | 合并保存界面设置 |
|
|
187
|
-
|
|
188
|
-
成功返回 `{ ok: true, result: { todos, settings, seeded } }`;失败返回 `{ ok: false, error: { code, message } }`,状态码 `invalid-input` 400 / `not-found` 404 / `io-error` 500。标题去空白后 1–200 字符,清单上限 500 条,圆角 0–24 整数,字号 11–17 整数,`dueDate` 必须是真实存在的 `YYYY-MM-DD` 日期。
|
|
189
|
-
|
|
190
|
-
## 文件结构
|
|
191
|
-
|
|
192
|
-
| 文件 | 作用 |
|
|
193
|
-
| --- | --- |
|
|
194
|
-
| `package.json` | 包清单:`dsh.bundle.patch` + `dsh.client`(web、immediately、locale/sidebar 依赖) |
|
|
195
|
-
| `cordis.patch.yml` | 插入插件行 `matrix-todo` |
|
|
196
|
-
| `index.js` | Host 半:注册 HTTP 路由,管理 store 生命周期 |
|
|
197
|
-
| `lib/store.js` | 文件型 store:待办与设置、校验、原子写、备份损坏文件 |
|
|
198
|
-
| `client.js` | Client 半:侧栏入口、矩阵与已完成两个视图、设置面板、全部样式 |
|
|
199
|
-
| `locale/en.json`、`locale/zh.json` | 插件管理器的标题/描述 |
|
|
200
|
-
| `icon.svg` | 插件图标(2×2 矩阵) |
|
|
201
|
-
|
|
202
|
-
## 已知边界
|
|
203
|
-
|
|
204
|
-
- 不提供 agent 工具;待办数据只由面板读写(Harness 已自带 `personal_todo` 工具,避免重复暴露两套语义)。
|
|
205
|
-
- 没有多选与批量操作;一次拖拽只移动一条,删除也只针对单条。
|
|
206
|
-
- 淡彩底色用 CSS `color-mix()` 从主题 token 混出;很旧的 Chromium 不支持时自动回落到单色背景。
|
|
207
|
-
- 侧栏图标与面板的视觉细节无法在无浏览器控制的环境里截图验证;本次通过实时插槽注册、接口契约、存储测试与语法/资源检查验证。
|
|
208
|
-
- 改 `client.js` 由 HMR 自动拾取;改 `index.js` / `lib/store.js`(Host 半)需要重启该插件行或重启 Harness。
|
|
145
|
+
MIT © wzvx,详见 `LICENSE`。
|
package/client.js
CHANGED
|
@@ -47,9 +47,9 @@ window.__ModuleLoader__.load({
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
/** Author links shown at the foot of the settings panel (external, new tab). */
|
|
50
|
-
const AUTHOR_NAME = '
|
|
50
|
+
const AUTHOR_NAME = 'wzvx';
|
|
51
51
|
const AUTHOR_URL = 'https://github.com/' + AUTHOR_NAME;
|
|
52
|
-
const REPO_URL = 'https://github.com/
|
|
52
|
+
const REPO_URL = 'https://github.com/wzvx/dsh-matrix-todo';
|
|
53
53
|
const ISSUES_URL = REPO_URL + '/issues';
|
|
54
54
|
|
|
55
55
|
/** Keep a split ratio inside the range the Host accepts. */
|
package/cordis.patch.yml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# Eisenhower-matrix to-do list: one sidebar entry, one main panel, and a
|
|
2
|
-
# file-backed store served through /matrix-todo/api.
|
|
3
|
-
- insert:
|
|
4
|
-
- id: matrix-todo
|
|
1
|
+
# Eisenhower-matrix to-do list: one sidebar entry, one main panel, and a
|
|
2
|
+
# file-backed store served through /matrix-todo/api.
|
|
3
|
+
- insert:
|
|
4
|
+
- id: matrix-todo
|
|
5
5
|
name: dsh-matrix-todo
|
package/icon.svg
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Eisenhower to-do">
|
|
2
|
-
<rect x="4" y="4" width="56" height="56" rx="14" fill="#17181c"/>
|
|
3
|
-
<rect x="11" y="11" width="19" height="19" rx="5" fill="#e88989"/>
|
|
4
|
-
<rect x="34" y="11" width="19" height="19" rx="5" fill="#93a3e6"/>
|
|
5
|
-
<rect x="11" y="34" width="19" height="19" rx="5" fill="#d3a866"/>
|
|
6
|
-
<rect x="34" y="34" width="19" height="19" rx="5" fill="#4b4e56"/>
|
|
7
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Eisenhower to-do">
|
|
2
|
+
<rect x="4" y="4" width="56" height="56" rx="14" fill="#17181c"/>
|
|
3
|
+
<rect x="11" y="11" width="19" height="19" rx="5" fill="#e88989"/>
|
|
4
|
+
<rect x="34" y="11" width="19" height="19" rx="5" fill="#93a3e6"/>
|
|
5
|
+
<rect x="11" y="34" width="19" height="19" rx="5" fill="#d3a866"/>
|
|
6
|
+
<rect x="34" y="34" width="19" height="19" rx="5" fill="#4b4e56"/>
|
|
7
|
+
</svg>
|
package/index.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
/** Host half of the matrix-todo bundle: one JSON route over the file-backed store. */
|
|
2
|
-
|
|
3
|
-
import { createStore, resolveDataFile } from './lib/store.js'
|
|
4
|
-
|
|
5
|
-
export const name = 'dsh-matrix-todo'
|
|
6
|
-
export const inject = ['webServer']
|
|
7
|
-
|
|
8
|
-
const PREFIX = '/matrix-todo/api/'
|
|
9
|
-
const STATUS = { 'invalid-input': 400, 'not-found': 404, 'io-error': 500 }
|
|
10
|
-
|
|
11
|
-
function sendJson(res, status, body, extraHeaders) {
|
|
12
|
-
const text = JSON.stringify(body)
|
|
13
|
-
res.writeHead(status, {
|
|
14
|
-
'content-type': 'application/json; charset=utf-8',
|
|
15
|
-
'cache-control': 'no-store',
|
|
16
|
-
...extraHeaders,
|
|
17
|
-
})
|
|
18
|
-
res.end(text)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Body is JSON; an empty body and malformed JSON both count as {}. */
|
|
22
|
-
async function readJson(req) {
|
|
23
|
-
const chunks = []
|
|
24
|
-
for await (const chunk of req) chunks.push(chunk)
|
|
25
|
-
if (chunks.length === 0) return {}
|
|
26
|
-
try {
|
|
27
|
-
const parsed = JSON.parse(Buffer.concat(chunks).toString('utf8'))
|
|
28
|
-
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
|
|
29
|
-
return parsed
|
|
30
|
-
} catch {
|
|
31
|
-
return {}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function isLoopbackPeer(address) {
|
|
36
|
-
if (address === undefined) return false
|
|
37
|
-
const plain = address.startsWith('::ffff:') ? address.slice('::ffff:'.length) : address
|
|
38
|
-
return plain === '::1' || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(plain)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Same-origin / loopback fence. The connection service is authoritative when present;
|
|
43
|
-
* otherwise fall back to the same checks the harness engine uses for local routes.
|
|
44
|
-
* Returns undefined when allowed, or the HTTP status of the refusal.
|
|
45
|
-
*/
|
|
46
|
-
function refusalOf(ctx, req) {
|
|
47
|
-
const connection = ctx.get('connection')
|
|
48
|
-
if (typeof connection?.requestRejection === 'function') return connection.requestRejection(req)
|
|
49
|
-
if (!isLoopbackPeer(req.socket?.remoteAddress)) return 403
|
|
50
|
-
const host = req.headers.host
|
|
51
|
-
if (host !== undefined) {
|
|
52
|
-
if (!URL.canParse(`http://${host}`)) return 403
|
|
53
|
-
const name = new URL(`http://${host}`).hostname
|
|
54
|
-
if (name !== 'localhost' && name !== '[::1]' && !/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(name)) return 403
|
|
55
|
-
}
|
|
56
|
-
const site = req.headers['sec-fetch-site']
|
|
57
|
-
if (site !== undefined && site !== 'same-origin' && site !== 'none') return 403
|
|
58
|
-
const origin = req.headers.origin
|
|
59
|
-
if (origin === undefined) return undefined
|
|
60
|
-
if (!URL.canParse(origin)) return 403
|
|
61
|
-
return new URL(origin).host === host ? undefined : 403
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const ACTIONS = {
|
|
65
|
-
list: (store) => store.list(),
|
|
66
|
-
seed: (store, body) => store.seed(body),
|
|
67
|
-
create: (store, body) => store.create(body),
|
|
68
|
-
update: (store, body) => store.update(body),
|
|
69
|
-
toggle: (store, body) => store.toggle(body),
|
|
70
|
-
remove: (store, body) => store.remove(body),
|
|
71
|
-
clearCompleted: (store, body) => store.clearCompleted(body),
|
|
72
|
-
reorder: (store, body) => store.reorder(body),
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Every response carries the full list plus the layout preferences. */
|
|
76
|
-
function resultOf(store) {
|
|
77
|
-
return { todos: store.list(), settings: store.settings(), seeded: store.seeded() }
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function apply(ctx, config = {}) {
|
|
81
|
-
// config.dataPath: optional override for the data file
|
|
82
|
-
// (default: %DSH_PROFILE_DIR%/data/dsh-matrix-todo/todos.json).
|
|
83
|
-
const store = createStore({ file: resolveDataFile(config.dataPath) })
|
|
84
|
-
const ready = store.load()
|
|
85
|
-
void ready.catch(() => {}) // keep load failures out of the unhandled-rejection path; callers still await it
|
|
86
|
-
|
|
87
|
-
ctx.effect(() => ctx.webServer.register({
|
|
88
|
-
kind: 'prefix',
|
|
89
|
-
path: '/matrix-todo/api',
|
|
90
|
-
handler: async (req, res) => {
|
|
91
|
-
try {
|
|
92
|
-
if (refusalOf(ctx, req) !== undefined) {
|
|
93
|
-
sendJson(res, 403, { ok: false, error: { code: 'forbidden', message: '请求来源不受信任' } })
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
if (req.method !== 'POST') {
|
|
97
|
-
sendJson(res, 405, { ok: false, error: { code: 'method', message: '只支持 POST' } }, { allow: 'POST' })
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
const pathname = new URL(req.url ?? '/', 'http://dsh.internal').pathname
|
|
101
|
-
const action = pathname.startsWith(PREFIX) ? pathname.slice(PREFIX.length) : ''
|
|
102
|
-
const known = action === 'saveSettings' || Object.hasOwn(ACTIONS, action)
|
|
103
|
-
if (action === '' || action.includes('/') || !known) {
|
|
104
|
-
sendJson(res, 404, { ok: false, error: { code: 'not-found', message: '未知接口' } })
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
await ready
|
|
108
|
-
const body = await readJson(req)
|
|
109
|
-
if (action === 'saveSettings') await store.saveSettings(body)
|
|
110
|
-
else await ACTIONS[action](store, body)
|
|
111
|
-
sendJson(res, 200, { ok: true, result: resultOf(store) })
|
|
112
|
-
} catch (err) {
|
|
113
|
-
const code = typeof err?.code === 'string' && err.code !== '' ? err.code : 'internal'
|
|
114
|
-
sendJson(res, STATUS[code] ?? 500, {
|
|
115
|
-
ok: false,
|
|
116
|
-
error: { code, message: err?.message ?? '待办操作失败' },
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
}), 'matrix-todo: http')
|
|
121
|
-
|
|
122
|
-
ctx.effect(() => () => { void store.close() }, 'matrix-todo: store')
|
|
123
|
-
}
|
|
1
|
+
/** Host half of the matrix-todo bundle: one JSON route over the file-backed store. */
|
|
2
|
+
|
|
3
|
+
import { createStore, resolveDataFile } from './lib/store.js'
|
|
4
|
+
|
|
5
|
+
export const name = 'dsh-matrix-todo'
|
|
6
|
+
export const inject = ['webServer']
|
|
7
|
+
|
|
8
|
+
const PREFIX = '/matrix-todo/api/'
|
|
9
|
+
const STATUS = { 'invalid-input': 400, 'not-found': 404, 'io-error': 500 }
|
|
10
|
+
|
|
11
|
+
function sendJson(res, status, body, extraHeaders) {
|
|
12
|
+
const text = JSON.stringify(body)
|
|
13
|
+
res.writeHead(status, {
|
|
14
|
+
'content-type': 'application/json; charset=utf-8',
|
|
15
|
+
'cache-control': 'no-store',
|
|
16
|
+
...extraHeaders,
|
|
17
|
+
})
|
|
18
|
+
res.end(text)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Body is JSON; an empty body and malformed JSON both count as {}. */
|
|
22
|
+
async function readJson(req) {
|
|
23
|
+
const chunks = []
|
|
24
|
+
for await (const chunk of req) chunks.push(chunk)
|
|
25
|
+
if (chunks.length === 0) return {}
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString('utf8'))
|
|
28
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
|
|
29
|
+
return parsed
|
|
30
|
+
} catch {
|
|
31
|
+
return {}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isLoopbackPeer(address) {
|
|
36
|
+
if (address === undefined) return false
|
|
37
|
+
const plain = address.startsWith('::ffff:') ? address.slice('::ffff:'.length) : address
|
|
38
|
+
return plain === '::1' || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(plain)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Same-origin / loopback fence. The connection service is authoritative when present;
|
|
43
|
+
* otherwise fall back to the same checks the harness engine uses for local routes.
|
|
44
|
+
* Returns undefined when allowed, or the HTTP status of the refusal.
|
|
45
|
+
*/
|
|
46
|
+
function refusalOf(ctx, req) {
|
|
47
|
+
const connection = ctx.get('connection')
|
|
48
|
+
if (typeof connection?.requestRejection === 'function') return connection.requestRejection(req)
|
|
49
|
+
if (!isLoopbackPeer(req.socket?.remoteAddress)) return 403
|
|
50
|
+
const host = req.headers.host
|
|
51
|
+
if (host !== undefined) {
|
|
52
|
+
if (!URL.canParse(`http://${host}`)) return 403
|
|
53
|
+
const name = new URL(`http://${host}`).hostname
|
|
54
|
+
if (name !== 'localhost' && name !== '[::1]' && !/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(name)) return 403
|
|
55
|
+
}
|
|
56
|
+
const site = req.headers['sec-fetch-site']
|
|
57
|
+
if (site !== undefined && site !== 'same-origin' && site !== 'none') return 403
|
|
58
|
+
const origin = req.headers.origin
|
|
59
|
+
if (origin === undefined) return undefined
|
|
60
|
+
if (!URL.canParse(origin)) return 403
|
|
61
|
+
return new URL(origin).host === host ? undefined : 403
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ACTIONS = {
|
|
65
|
+
list: (store) => store.list(),
|
|
66
|
+
seed: (store, body) => store.seed(body),
|
|
67
|
+
create: (store, body) => store.create(body),
|
|
68
|
+
update: (store, body) => store.update(body),
|
|
69
|
+
toggle: (store, body) => store.toggle(body),
|
|
70
|
+
remove: (store, body) => store.remove(body),
|
|
71
|
+
clearCompleted: (store, body) => store.clearCompleted(body),
|
|
72
|
+
reorder: (store, body) => store.reorder(body),
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Every response carries the full list plus the layout preferences. */
|
|
76
|
+
function resultOf(store) {
|
|
77
|
+
return { todos: store.list(), settings: store.settings(), seeded: store.seeded() }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function apply(ctx, config = {}) {
|
|
81
|
+
// config.dataPath: optional override for the data file
|
|
82
|
+
// (default: %DSH_PROFILE_DIR%/data/dsh-matrix-todo/todos.json).
|
|
83
|
+
const store = createStore({ file: resolveDataFile(config.dataPath) })
|
|
84
|
+
const ready = store.load()
|
|
85
|
+
void ready.catch(() => {}) // keep load failures out of the unhandled-rejection path; callers still await it
|
|
86
|
+
|
|
87
|
+
ctx.effect(() => ctx.webServer.register({
|
|
88
|
+
kind: 'prefix',
|
|
89
|
+
path: '/matrix-todo/api',
|
|
90
|
+
handler: async (req, res) => {
|
|
91
|
+
try {
|
|
92
|
+
if (refusalOf(ctx, req) !== undefined) {
|
|
93
|
+
sendJson(res, 403, { ok: false, error: { code: 'forbidden', message: '请求来源不受信任' } })
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
if (req.method !== 'POST') {
|
|
97
|
+
sendJson(res, 405, { ok: false, error: { code: 'method', message: '只支持 POST' } }, { allow: 'POST' })
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
const pathname = new URL(req.url ?? '/', 'http://dsh.internal').pathname
|
|
101
|
+
const action = pathname.startsWith(PREFIX) ? pathname.slice(PREFIX.length) : ''
|
|
102
|
+
const known = action === 'saveSettings' || Object.hasOwn(ACTIONS, action)
|
|
103
|
+
if (action === '' || action.includes('/') || !known) {
|
|
104
|
+
sendJson(res, 404, { ok: false, error: { code: 'not-found', message: '未知接口' } })
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
await ready
|
|
108
|
+
const body = await readJson(req)
|
|
109
|
+
if (action === 'saveSettings') await store.saveSettings(body)
|
|
110
|
+
else await ACTIONS[action](store, body)
|
|
111
|
+
sendJson(res, 200, { ok: true, result: resultOf(store) })
|
|
112
|
+
} catch (err) {
|
|
113
|
+
const code = typeof err?.code === 'string' && err.code !== '' ? err.code : 'internal'
|
|
114
|
+
sendJson(res, STATUS[code] ?? 500, {
|
|
115
|
+
ok: false,
|
|
116
|
+
error: { code, message: err?.message ?? '待办操作失败' },
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
}), 'matrix-todo: http')
|
|
121
|
+
|
|
122
|
+
ctx.effect(() => () => { void store.close() }, 'matrix-todo: store')
|
|
123
|
+
}
|