@nsnanocat/preference-panes 1.1.1 → 1.1.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @nsnanocat/preference-panes
2
2
 
3
- PreferencePanes 提供一个由 BoxJS JSON 驱动的通用设置前端,以及一个独立的代理持久化 API。业务模块只发布自己的 `/configs/{module}` `/api/{module}`;通用 `/settings/**` 前端只需要安装一次。
3
+ PreferencePanes 提供一个由 BoxJS JSON 驱动的通用设置前端,以及一个独立的代理持久化 API。业务模块直接将自己的 BoxJS JSON Mock 到 `/api/{module}`;通用 `/settings/**` 前端和固定存储 API 分别只需要安装一次。
4
4
 
5
5
  在 Biliverse 中,Enhanced 是唯一安装 `web.js` 的模块。Global、Redirect、ADBlock 不携带 `web.js`,它们的设置页仍由同一份通用前端读取各自 BoxJS 后渲染。
6
6
 
@@ -16,7 +16,7 @@ interface MountedPreferences { destroy(): void }
16
16
  ```js
17
17
  import { mount } from "@nsnanocat/preference-panes/browser";
18
18
 
19
- const boxjs = await fetch("/configs/Module", {
19
+ const boxjs = await fetch("/api/Module", {
20
20
  cache: "no-store",
21
21
  credentials: "omit",
22
22
  }).then(response => response.json());
@@ -39,29 +39,30 @@ preferences.destroy();
39
39
  - `GET /settings/assets/index.mjs`
40
40
  - `GET /settings/assets/navigation.mjs`
41
41
 
42
- 模块页面从 URL 或 `ModuleFrame` 的模块标记取得模块名,直接读取同源 `/configs/{module}`,然后调用 `mount(boxjs)`。页面不接受 JSON/CSS 查询参数、私有请求头或兼容资源别名。
42
+ 模块页面从 URL 或 `ModuleFrame` 的模块标记取得模块名,通过同源 `/api/{module}` 读取原始 BoxJS,然后调用 `mount(boxjs)`。页面不接受 JSON/CSS 查询参数、私有请求头或兼容资源别名,也不直接访问 `/configs/**`。
43
+
44
+ 业务模块模板直接处理:
45
+
46
+ - `HEAD /api/{module}`:返回空正文和 `X-PreferencePanes-Version`。
47
+ - `GET /api/{module}`:返回同版原始 BoxJS JSON。
43
48
 
44
49
  `api.js` 只处理:
45
50
 
46
- - `HEAD /api/{module}`:探测同源 `/configs/{module}`,透传状态与 `X-PreferencePanes-Version`。
47
- - `POST /api/{module}/get`:读取声明字段或 Settings、Caches、module 子树。
48
- - `POST /api/{module}/set`:写入当前 BoxJS 声明的字段。
49
- - `POST /api/{module}/delete`:删除声明字段或模块子树。
51
+ - `POST /api/get`:读取完整 `@root.path`。
52
+ - `POST /api/set`:写入完整 `@root.path`。
53
+ - `POST /api/delete`:删除完整 `@root.path` 或子树。
50
54
 
51
- `GET /api/{module}` 和其它未规定方法返回 `405`。API 每次动作都从 `/configs/{module}` 建立字段目录,只负责字段授权与 util `Storage` 读写,不解释控件、选项或默认值。
55
+ 模块名 `get`、`set` `delete` 为固定存储端点保留。模块 API 与固定存储 API 都不解析 BoxJS;BoxJS 字段、控件、选项、默认值与写入值全部由浏览器校验。
52
56
 
53
57
  ```js
54
- await fetch("/api/Enhanced/set", {
58
+ await fetch("/api/set", {
55
59
  method: "POST",
56
- headers: { "Content-Type": "application/json" },
57
- body: JSON.stringify({
58
- key: "Enhanced.Settings.Home.Top_left",
59
- value: "mine",
60
- }),
60
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
61
+ body: new URLSearchParams([["@BiliBili.Enhanced.Settings.Home.Top_left", JSON.stringify("mine")]]),
61
62
  });
62
63
  ```
63
64
 
64
- 页面初始化时只执行一次 `POST /api/{module}/get` 读取 Settings 子树。写入成功后仅更新当前页面快照;查看 Settings/Caches 时按需读取,清空和重置通过 delete 动作完成。
65
+ 页面初始化时只执行一次 `POST /api/get` 读取 Settings 子树。写入成功后仅更新当前页面快照;查看 Settings/Caches 时按需读取,清空和重置通过 `/api/delete` 完成。
65
66
 
66
67
  ## 宿主集成
67
68