dsh-folia 4.12.3 → 4.12.4
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/lib/client.js +16 -10
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -18318,13 +18318,13 @@ window.__ModuleLoader__.load({
|
|
|
18318
18318
|
const doc = (resp && resp.data) || null;
|
|
18319
18319
|
if (resp && resp.ok && doc && doc.ok) {
|
|
18320
18320
|
// 读"当前在用哪套皮肤"必须**由浏览器发**,不能走宿主代理:
|
|
18321
|
-
// `/api/skin-center/v2/*` 的读写被 DSH 自己的会话鉴权挡着,宿主 fetch 没有 cookie
|
|
18322
|
-
//
|
|
18323
|
-
//
|
|
18324
|
-
//
|
|
18321
|
+
// `/api/skin-center/v2/*` 的读写被 DSH 自己的会话鉴权挡着,宿主 fetch 没有 cookie ⇒ 401。
|
|
18322
|
+
// 路径用**相对 `/api/...`**:不要拼 `location.origin` —— 我们跑在宿主页面里,origin 不一定
|
|
18323
|
+
// 等于宿主 HTTP API 的源;拼错会得到一个不存在的地址,而它的 404 还会被误读成业务 404。
|
|
18324
|
+
// api-client 对 `/api/**` 原样放行(不补 /folia 前缀)。
|
|
18325
18325
|
if (doc.skinCenter === "present") {
|
|
18326
18326
|
try {
|
|
18327
|
-
const a = await apiJson(
|
|
18327
|
+
const a = await apiJson("/api/skin-center/v2/active", { parse: "always" });
|
|
18328
18328
|
if (a && a.ok) doc.active = (a.data && a.data.active) || "";
|
|
18329
18329
|
} catch { /* 读不到就显示"无使用中" */ }
|
|
18330
18330
|
}
|
|
@@ -18349,8 +18349,6 @@ window.__ModuleLoader__.load({
|
|
|
18349
18349
|
if (kind === "activate") setBusy("activate:" + ((payload && payload.id) || ""));
|
|
18350
18350
|
setNote(null);
|
|
18351
18351
|
try {
|
|
18352
|
-
// 切换皮肤**由浏览器直接写**皮肤中心自己的端点(同源请求自带会话);
|
|
18353
|
-
// 走宿主代理会 401 —— DSH 对 `/api/skin-center/v2/*` 的读写都做会话鉴权,宿主 fetch 没有 cookie。
|
|
18354
18352
|
if (kind === "activate") {
|
|
18355
18353
|
const wantId = (payload && payload.id) || null;
|
|
18356
18354
|
// ⚠️ 这里写入的必须是**皮肤中心自己认识的 id**(= skin.json 里的原始 id),
|
|
@@ -18365,10 +18363,14 @@ window.__ModuleLoader__.load({
|
|
|
18365
18363
|
}
|
|
18366
18364
|
// 切换皮肤**由浏览器直接写**皮肤中心自己的端点(同源、自带会话);
|
|
18367
18365
|
// 走宿主代理会 401 —— DSH 对 `/api/skin-center/v2/*` 的读写都做会话鉴权,宿主 fetch 没有 cookie。
|
|
18368
|
-
// 统一走 api-client(不裸 fetch
|
|
18369
|
-
|
|
18366
|
+
// 统一走 api-client(不裸 fetch),路径用相对 `/api/...`(不拼 location.origin ——
|
|
18367
|
+
// 拼错会得到一个不存在的地址,404 又会被误读成业务 404)。
|
|
18368
|
+
const resp = await apiPostJson("/api/skin-center/v2/active", { active: wantId }, { parse: "always" });
|
|
18370
18369
|
if (!(resp && resp.ok)) {
|
|
18371
|
-
|
|
18370
|
+
// 把响应体里的 error 一起显示:`skin-not-found`(它的 catalog 不收)与"路径不对"
|
|
18371
|
+
// 从状态码上看都是 404,只有 body 能分开(实测踩过:把 URL 拼错当成了业务 404)。
|
|
18372
|
+
const detail = (resp && resp.data && resp.data.error) ? ":" + resp.data.error : "";
|
|
18373
|
+
setNote({ ok: false, text: weT("操作失败:{code}", { code: "skin-center-" + ((resp && resp.status) || 0) + detail }) });
|
|
18372
18374
|
return;
|
|
18373
18375
|
}
|
|
18374
18376
|
// 两条收敛路径:① 广播皮肤中心自己监听的 `dsh-skin-applied`(立即就地切换);
|
|
@@ -23848,6 +23850,10 @@ window.__ModuleLoader__.load({
|
|
|
23848
23850
|
// 应用侧封面恒 404,而同路径 curl 200)。
|
|
23849
23851
|
if (/^[a-z][a-z0-9+.-]*:/i.test(p) || p.startsWith('data:') || p.startsWith('blob:')) return p;
|
|
23850
23852
|
if (p.startsWith(BASE)) return p;
|
|
23853
|
+
// **宿主自己的 HTTP API** 挂在 `/api/**`(我们的是 `/folia/**`):这类绝对路径必须原样放行。
|
|
23854
|
+
// 补成 `/folia/api/...` 会得到一个不存在的路径 —— 那个 404 还会被调用方误读成"业务侧返回 404"
|
|
23855
|
+
// (实测:皮肤切换报 `skin-center-404`,真因是 URL 被我们拼错,不是皮肤中心说没这套皮肤)。
|
|
23856
|
+
if (p === '/api' || p.startsWith('/api/')) return p;
|
|
23851
23857
|
return BASE + (p.startsWith('/') ? p : '/' + p);
|
|
23852
23858
|
}
|
|
23853
23859
|
|