@nsnanocat/preference-panes 0.7.1 → 0.8.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/README.md +31 -68
- package/dist/api.js +1622 -0
- package/dist/module/app.mjs +52 -32
- package/dist/module/index.html +1 -1
- package/dist/module/navigation.mjs +101 -1
- package/dist/preference-panes.mjs +38 -30
- package/package.json +1 -1
- package/src/Store.mjs +40 -53
- package/src/browser/ModuleFrame.mjs +83 -0
- package/src/browser/Navigation.d.mts +42 -0
- package/src/browser/Navigation.mjs +2 -0
- package/src/browser/app.mjs +13 -1
- package/src/browser/client.d.mts +2 -2
- package/src/browser/client.mjs +21 -21
- package/src/browser/panel.css +9 -0
- package/src/browser/panel.mjs +16 -0
- package/src/build.mjs +3 -13
- package/src/index.d.ts +6 -6
- package/src/lib/page-inputs.mjs +1 -1
- package/src/lib/settings-path.mjs +0 -18
- package/src/proxy/handler.mjs +9 -22
- package/dist/preference-panes.config.js +0 -842
- package/dist/preference-panes.proxy.js +0 -1754
- package/src/proxy/config.mjs +0 -14
package/src/proxy/handler.mjs
CHANGED
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
import { URL } from "@nsnanocat/url";
|
|
2
2
|
import assets from "#assets";
|
|
3
|
-
import { BoxJS } from "../BoxJS.mjs";
|
|
4
3
|
import { pageInputs } from "../lib/page-inputs.mjs";
|
|
5
4
|
import { response } from "../lib/response.mjs";
|
|
6
5
|
import { Store } from "../Store.mjs";
|
|
7
6
|
import { complete } from "./response.mjs";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
* @param {string} [css] 自定义 CSS 正文 / Custom CSS text.
|
|
14
|
-
* @returns {Promise<void>} 已提交宿主响应 / Delivered host response.
|
|
9
|
+
* 通用代理入口:提供无鉴权 form 存储 API 及模块页面,不含业务配置。
|
|
10
|
+
* Generic proxy entry serving unauthenticated form storage and module pages without business configuration.
|
|
11
|
+
* @returns {Promise<void>} 已交给代理宿主的响应 / Response delivered to the proxy host.
|
|
15
12
|
*/
|
|
16
|
-
|
|
13
|
+
async function run() {
|
|
17
14
|
const request = globalThis.$request;
|
|
18
15
|
let result;
|
|
19
16
|
try {
|
|
20
|
-
if (typeof css !== "string") throw new TypeError("CSS must be a string");
|
|
21
|
-
const catalog = new BoxJS(boxjs);
|
|
22
|
-
const module = catalog.module.module;
|
|
23
17
|
const url = new URL(request.url);
|
|
24
18
|
switch (true) {
|
|
25
19
|
case url.pathname.startsWith("/api/"):
|
|
26
|
-
result = await new Store(
|
|
20
|
+
result = await new Store().handle(request, url);
|
|
27
21
|
break;
|
|
28
|
-
case url.pathname
|
|
29
|
-
break;
|
|
30
|
-
case url.pathname === `/settings/${module}` || url.pathname === `/settings/${module}/`: {
|
|
31
|
-
// Header 由代理传入文档,浏览器再下载 JSON/CSS;代理不获取外部资源。
|
|
32
|
-
// Carry headers into the document; only the browser downloads external JSON/CSS.
|
|
22
|
+
case /^\/settings\/[a-zA-Z0-9_-]+\/?$/.test(url.pathname): {
|
|
33
23
|
const inputs = encodeURIComponent(JSON.stringify(pageInputs(url, request.headers)));
|
|
34
|
-
|
|
35
|
-
result = response(request, 200, html, "text/html");
|
|
24
|
+
result = response(request, 200, assets.page.body.replace("</head>", `<meta name="preference-panes-inputs" content="${inputs}"></head>`), "text/html");
|
|
36
25
|
break;
|
|
37
26
|
}
|
|
38
|
-
case url.pathname === `/settings/assets/${module}.css`:
|
|
39
|
-
result = response(request, 200, css, "text/css");
|
|
40
|
-
break;
|
|
41
27
|
default: {
|
|
42
28
|
const asset = assets[url.pathname];
|
|
43
29
|
if (asset) result = response(request, 200, asset.body, asset.type);
|
|
@@ -46,7 +32,8 @@ export async function run(boxjs, css = "") {
|
|
|
46
32
|
if (result && !url.pathname.startsWith("/api/") && !["GET", "HEAD"].includes(request.method)) result = response(request, 405, { error: "Method not allowed" });
|
|
47
33
|
} catch (error) {
|
|
48
34
|
console.error(`PreferencePanes: ${error.message}`);
|
|
49
|
-
result = response(request, 500, { error:
|
|
35
|
+
result = response(request, 500, { error: error.message });
|
|
50
36
|
}
|
|
51
37
|
complete(result);
|
|
52
38
|
}
|
|
39
|
+
run();
|