dsh-half-page 0.3.50 → 0.3.53
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/index.js +56 -2
- package/package.json +7 -2
package/index.js
CHANGED
|
@@ -8,11 +8,48 @@ import { fileURLToPath } from 'node:url'
|
|
|
8
8
|
import { readTimeline, newestSessionId } from './lib/session-probe.js'
|
|
9
9
|
import { loadCreateUserMessage, SOURCE_KIND } from './lib/notice.js'
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 路由准入(工单-HTTP路由准入,2026-11-26)。
|
|
13
|
+
*
|
|
14
|
+
* 宿主契约:register({ auth }) 的 auth 可以是
|
|
15
|
+
* 'anonymous' | 'required' | 'deny',或 (request) => policy;
|
|
16
|
+
* request 里有 { headers, method, url, transport }。
|
|
17
|
+
*
|
|
18
|
+
* 规则:请求带 Origin/Referer 且跟 Host 对不上 → 拒;Origin 是 "null"
|
|
19
|
+
* (沙箱页面 / data: / file:)→ 拒;没带来源(curl、本地脚本、同源导航)
|
|
20
|
+
* 或来源就是本服务的 Host → 放行。面板在同源 iframe 里跑,功能不变。
|
|
21
|
+
*/
|
|
22
|
+
export function sameSiteAuth(request) {
|
|
23
|
+
const headers = request?.headers
|
|
24
|
+
const read = (name) => {
|
|
25
|
+
if (!headers) return undefined
|
|
26
|
+
if (typeof headers.get === 'function') return headers.get(name) ?? undefined
|
|
27
|
+
const value = headers[name] ?? headers[name.toLowerCase()] ?? headers[name.toUpperCase()]
|
|
28
|
+
return Array.isArray(value) ? value[0] : value
|
|
29
|
+
}
|
|
30
|
+
const host = String(read('host') || '')
|
|
31
|
+
const source = String(read('origin') || read('referer') || '')
|
|
32
|
+
if (!source) return 'anonymous'
|
|
33
|
+
if (source === 'null') return 'deny'
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(source)
|
|
36
|
+
if (host && url.host === host) return 'anonymous'
|
|
37
|
+
// 同一个本机服务、但 Host 头缺失(HTTP/1.0、某些本地代理)
|
|
38
|
+
if (!host && (url.hostname === '127.0.0.1' || url.hostname === 'localhost')) return 'anonymous'
|
|
39
|
+
return 'deny'
|
|
40
|
+
} catch {
|
|
41
|
+
return 'deny'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
11
46
|
export const inject = ['webServer', 'tools', 'systemPrompt', 'agents', 'sessions']
|
|
12
47
|
|
|
13
48
|
const HOME = process.env.USERPROFILE || process.env.HOME || homedir()
|
|
14
|
-
|
|
15
|
-
const
|
|
49
|
+
// 跟宿主的 DSH_HOME 走:有人把它设到别的盘时,数据和插件不能分家(心跳就是这么写的)
|
|
50
|
+
const DSH_HOME = process.env.DSH_HOME || join(HOME, '.dsh')
|
|
51
|
+
const CONFIG = join(DSH_HOME, 'reading.config.json')
|
|
52
|
+
const DEFAULT_DIR = join(DSH_HOME, 'reading')
|
|
16
53
|
|
|
17
54
|
const CH_RE = /^[ \t\u3000]*(第[0-90-9一二三四五六七八九十百千两零〇]+[章节回][^\n]{0,30})$/m
|
|
18
55
|
const CH_LINE_RE = /^[ \t\u3000]*(第[0-90-9一二三四五六七八九十百千两零〇]+[章节回][^\n]{0,30})$/gm
|
|
@@ -821,6 +858,7 @@ export function apply(ctx, rawConfig) {
|
|
|
821
858
|
// 面板读取
|
|
822
859
|
ctx.effect(() =>
|
|
823
860
|
ctx.webServer.register({
|
|
861
|
+
auth: sameSiteAuth,
|
|
824
862
|
kind: 'exact',
|
|
825
863
|
path: '/dsh-reading.state',
|
|
826
864
|
async handler(req, res) {
|
|
@@ -878,6 +916,7 @@ export function apply(ctx, rawConfig) {
|
|
|
878
916
|
// 把某本设为「正在读」
|
|
879
917
|
ctx.effect(() =>
|
|
880
918
|
ctx.webServer.register({
|
|
919
|
+
auth: sameSiteAuth,
|
|
881
920
|
kind: 'exact',
|
|
882
921
|
path: '/dsh-reading.setCurrent',
|
|
883
922
|
async handler(req, res) {
|
|
@@ -894,6 +933,7 @@ export function apply(ctx, rawConfig) {
|
|
|
894
933
|
// 面板里直接读一章(不记账)
|
|
895
934
|
ctx.effect(() =>
|
|
896
935
|
ctx.webServer.register({
|
|
936
|
+
auth: sameSiteAuth,
|
|
897
937
|
kind: 'exact',
|
|
898
938
|
path: '/dsh-reading.chapter',
|
|
899
939
|
async handler(req, res) {
|
|
@@ -920,6 +960,7 @@ export function apply(ctx, rawConfig) {
|
|
|
920
960
|
// 面板里点「下一章」:记一次已读并推进
|
|
921
961
|
ctx.effect(() =>
|
|
922
962
|
ctx.webServer.register({
|
|
963
|
+
auth: sameSiteAuth,
|
|
923
964
|
kind: 'exact',
|
|
924
965
|
path: '/dsh-reading.advance',
|
|
925
966
|
async handler(req, res) {
|
|
@@ -947,6 +988,7 @@ export function apply(ctx, rawConfig) {
|
|
|
947
988
|
// 面板里点「退一章」:退回上一章(手滑多点了一下能救回来)
|
|
948
989
|
ctx.effect(() =>
|
|
949
990
|
ctx.webServer.register({
|
|
991
|
+
auth: sameSiteAuth,
|
|
950
992
|
kind: 'exact',
|
|
951
993
|
path: '/dsh-reading.back',
|
|
952
994
|
async handler(req, res) {
|
|
@@ -1025,6 +1067,7 @@ async function signWork(rel, who) {
|
|
|
1025
1067
|
|
|
1026
1068
|
ctx.effect(() =>
|
|
1027
1069
|
ctx.webServer.register({
|
|
1070
|
+
auth: sameSiteAuth,
|
|
1028
1071
|
kind: 'exact',
|
|
1029
1072
|
path: '/dsh-reading.works',
|
|
1030
1073
|
async handler(req, res) {
|
|
@@ -1067,6 +1110,7 @@ async function signWork(rel, who) {
|
|
|
1067
1110
|
// 给面板读一张图(限制在上面那几个根里)
|
|
1068
1111
|
ctx.effect(() =>
|
|
1069
1112
|
ctx.webServer.register({
|
|
1113
|
+
auth: sameSiteAuth,
|
|
1070
1114
|
kind: 'exact',
|
|
1071
1115
|
path: '/dsh-reading.image',
|
|
1072
1116
|
async handler(req, res) {
|
|
@@ -1095,6 +1139,7 @@ async function signWork(rel, who) {
|
|
|
1095
1139
|
// 给一件作品署名
|
|
1096
1140
|
ctx.effect(() =>
|
|
1097
1141
|
ctx.webServer.register({
|
|
1142
|
+
auth: sameSiteAuth,
|
|
1098
1143
|
kind: 'exact',
|
|
1099
1144
|
path: '/dsh-reading.sign',
|
|
1100
1145
|
async handler(req, res) {
|
|
@@ -1120,6 +1165,7 @@ async function signWork(rel, who) {
|
|
|
1120
1165
|
// 取一个文本文件的正文(作品 / 读后感),供面板展示与复制
|
|
1121
1166
|
ctx.effect(() =>
|
|
1122
1167
|
ctx.webServer.register({
|
|
1168
|
+
auth: sameSiteAuth,
|
|
1123
1169
|
kind: 'exact',
|
|
1124
1170
|
path: '/dsh-reading.file',
|
|
1125
1171
|
async handler(req, res) {
|
|
@@ -1145,6 +1191,7 @@ async function signWork(rel, who) {
|
|
|
1145
1191
|
// 设置读写:perDay / notesEvery / quietFrom-quietTo / writing / favorites
|
|
1146
1192
|
ctx.effect(() =>
|
|
1147
1193
|
ctx.webServer.register({
|
|
1194
|
+
auth: sameSiteAuth,
|
|
1148
1195
|
kind: 'exact',
|
|
1149
1196
|
path: '/dsh-reading.config',
|
|
1150
1197
|
async handler(req, res) {
|
|
@@ -1171,6 +1218,7 @@ async function signWork(rel, who) {
|
|
|
1171
1218
|
// 面板里导入一本书(txt/md):body {path}
|
|
1172
1219
|
ctx.effect(() =>
|
|
1173
1220
|
ctx.webServer.register({
|
|
1221
|
+
auth: sameSiteAuth,
|
|
1174
1222
|
kind: 'exact',
|
|
1175
1223
|
path: '/dsh-reading.importText',
|
|
1176
1224
|
async handler(req, res) {
|
|
@@ -1194,6 +1242,7 @@ async function signWork(rel, who) {
|
|
|
1194
1242
|
|
|
1195
1243
|
ctx.effect(() =>
|
|
1196
1244
|
ctx.webServer.register({
|
|
1245
|
+
auth: sameSiteAuth,
|
|
1197
1246
|
path: '/dsh-reading.import',
|
|
1198
1247
|
async handler(req, res) {
|
|
1199
1248
|
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
@@ -1239,6 +1288,7 @@ async function signWork(rel, who) {
|
|
|
1239
1288
|
// 近况:一句状态 + 最近 7 天的读书/动笔时间线(只报事实,不编状态数值)
|
|
1240
1289
|
ctx.effect(() =>
|
|
1241
1290
|
ctx.webServer.register({
|
|
1291
|
+
auth: sameSiteAuth,
|
|
1242
1292
|
kind: 'exact',
|
|
1243
1293
|
path: '/dsh-reading.recent',
|
|
1244
1294
|
async handler(req, res) {
|
|
@@ -1314,6 +1364,7 @@ async function signWork(rel, who) {
|
|
|
1314
1364
|
// 下架一本书:文件移到 books/.trash(可手工找回),state 记录清掉;读后感一律不动
|
|
1315
1365
|
ctx.effect(() =>
|
|
1316
1366
|
ctx.webServer.register({
|
|
1367
|
+
auth: sameSiteAuth,
|
|
1317
1368
|
kind: 'exact',
|
|
1318
1369
|
path: '/dsh-reading.removeBook',
|
|
1319
1370
|
async handler(req, res) {
|
|
@@ -1360,6 +1411,7 @@ async function signWork(rel, who) {
|
|
|
1360
1411
|
// 稿子状态:在写 / 写完了 / 搁下了(存在 reading.config.json 的 workStatus 里)
|
|
1361
1412
|
ctx.effect(() =>
|
|
1362
1413
|
ctx.webServer.register({
|
|
1414
|
+
auth: sameSiteAuth,
|
|
1363
1415
|
kind: 'exact',
|
|
1364
1416
|
path: '/dsh-reading.workstatus',
|
|
1365
1417
|
async handler(req, res) {
|
|
@@ -1388,6 +1440,7 @@ async function signWork(rel, who) {
|
|
|
1388
1440
|
// 读后感的排序方式(0=章节升 1=章节降 2=时间降),存在 reading.config.json 里
|
|
1389
1441
|
ctx.effect(() =>
|
|
1390
1442
|
ctx.webServer.register({
|
|
1443
|
+
auth: sameSiteAuth,
|
|
1391
1444
|
kind: 'exact',
|
|
1392
1445
|
path: '/dsh-reading.notesort',
|
|
1393
1446
|
async handler(req, res) {
|
|
@@ -1407,6 +1460,7 @@ async function signWork(rel, who) {
|
|
|
1407
1460
|
// 书籍状态:在读 / 已读完 / 弃坑(空 status 表示清掉)
|
|
1408
1461
|
ctx.effect(() =>
|
|
1409
1462
|
ctx.webServer.register({
|
|
1463
|
+
auth: sameSiteAuth,
|
|
1410
1464
|
kind: 'exact',
|
|
1411
1465
|
path: '/dsh-reading.bookstatus',
|
|
1412
1466
|
async handler(req, res) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-half-page",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.53",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "鹿野 <luye@dsh.local>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/heiyedehen/dsh-half-page.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/heiyedehen/dsh-half-page",
|
|
7
12
|
"description": "一间会自己读书的书房:一章一章地读,记下读到哪了;读完想说什么就写在那一章边上,想写点自己的东西也放在这儿。",
|
|
8
13
|
"type": "module",
|
|
9
14
|
"exports": {
|
|
@@ -44,6 +49,6 @@
|
|
|
44
49
|
"agent"
|
|
45
50
|
],
|
|
46
51
|
"engines": {
|
|
47
|
-
"dsh": ">=0.2.
|
|
52
|
+
"dsh": ">=0.2.3-alpha.0 <0.4.0-0"
|
|
48
53
|
}
|
|
49
54
|
}
|