@iasiv5/dsh-skins 1.5.24 → 1.5.26
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.en.md +1 -1
- package/README.i18n.yaml +2 -2
- package/README.md +1 -1
- package/assets/manifest.json +61 -0
- package/assets/meirenzhi/b_meirenzhi_mupeiling.webp +0 -0
- package/assets/meirenzhi/b_meirenzhi_nangongque.webp +0 -0
- package/assets/meirenzhi/b_meirenzhi_nangongwan.webp +0 -0
- package/assets/meirenzhi/b_meirenzhi_yinyue.webp +0 -0
- package/assets/meirenzhi/b_meirenzhi_yuntai.webp +0 -0
- package/assets/meirenzhi/b_meirenzhi_ziling.webp +0 -0
- package/assets/uefi-harness/b_uefi-harness_art.webp +0 -0
- package/lib/client.js +148 -12
- package/lib/index.js +110 -20
- package/package.json +5 -2
package/lib/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// src/index.js
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import { cpSync, existsSync as existsSync2, mkdtempSync, readdirSync as readdirSync2, renameSync as renameSync3, rmSync } from "node:fs";
|
|
4
|
-
import { dirname as dirname2, join as
|
|
3
|
+
import { cpSync, existsSync as existsSync2, mkdtempSync, readFileSync as readFileSync3, readdirSync as readdirSync2, renameSync as renameSync3, rmSync } from "node:fs";
|
|
4
|
+
import { dirname as dirname2, join as join3, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
|
|
6
7
|
// src/host/personalization/store.js
|
|
7
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
8
9
|
import {
|
|
10
|
+
appendFileSync,
|
|
9
11
|
closeSync,
|
|
10
12
|
copyFileSync,
|
|
11
13
|
existsSync,
|
|
@@ -411,8 +413,17 @@ var QUARANTINE_DIR = "quarantine";
|
|
|
411
413
|
var DISK_SAFETY_RESERVE = 64 * 1024 * 1024;
|
|
412
414
|
var CORRUPT_BACKUP_LIMIT = 3;
|
|
413
415
|
var ID_ATTEMPTS = 5;
|
|
416
|
+
var AUDIT_FILE = "audit.jsonl";
|
|
417
|
+
var AUDIT_MAX_BYTES = 1048576;
|
|
418
|
+
function summarizeAuditValue(value) {
|
|
419
|
+
if (value === void 0) return null;
|
|
420
|
+
if (value === null || typeof value === "number" || typeof value === "boolean") return value;
|
|
421
|
+
if (typeof value === "string") return resolveImageRef(value) !== null ? value : { string: value.length };
|
|
422
|
+
return { object: Object.keys(value).length };
|
|
423
|
+
}
|
|
414
424
|
function defaultFs() {
|
|
415
425
|
return {
|
|
426
|
+
appendFileSync,
|
|
416
427
|
existsSync,
|
|
417
428
|
mkdirSync: mkdirSync2,
|
|
418
429
|
readFileSync,
|
|
@@ -490,6 +501,8 @@ function createPersonalizationStore(options = {}) {
|
|
|
490
501
|
const stateFile = join(dataDir, STATE_FILE);
|
|
491
502
|
const assetsDir = join(dataDir, ASSETS_DIR);
|
|
492
503
|
const quarantineDir = join(dataDir, QUARANTINE_DIR);
|
|
504
|
+
const auditFile = join(dataDir, AUDIT_FILE);
|
|
505
|
+
const auditMaxBytes = Number.isInteger(options.auditMaxBytes) && options.auditMaxBytes > 0 ? options.auditMaxBytes : AUDIT_MAX_BYTES;
|
|
493
506
|
let state = null;
|
|
494
507
|
let mode = "normal";
|
|
495
508
|
let recovery = null;
|
|
@@ -519,10 +532,48 @@ function createPersonalizationStore(options = {}) {
|
|
|
519
532
|
function blobFileFor(id, extension) {
|
|
520
533
|
return join(assetsDir, `${id}.${extension}`);
|
|
521
534
|
}
|
|
522
|
-
function commitState(next) {
|
|
535
|
+
function commitState(next, { source, previous = state, ops } = {}) {
|
|
523
536
|
atomicWriteText(stateFile, `${JSON.stringify(next, null, 2)}
|
|
524
537
|
`, fs);
|
|
525
538
|
state = next;
|
|
539
|
+
recordAudit(previous, next, source ?? "unknown", ops);
|
|
540
|
+
}
|
|
541
|
+
function recordAudit(previous, next, source, ops) {
|
|
542
|
+
try {
|
|
543
|
+
const skins = [];
|
|
544
|
+
const skinIds = /* @__PURE__ */ new Set([...Object.keys(previous?.skins ?? {}), ...Object.keys(next.skins ?? {})]);
|
|
545
|
+
for (const skinId of skinIds) {
|
|
546
|
+
const before = previous?.skins?.[skinId] ?? {};
|
|
547
|
+
const after = next.skins?.[skinId] ?? {};
|
|
548
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
549
|
+
if (JSON.stringify(before[key]) === JSON.stringify(after[key])) continue;
|
|
550
|
+
skins.push({ skin: skinId, key, from: summarizeAuditValue(before[key]), to: summarizeAuditValue(after[key]) });
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const libraryBefore = new Set(Object.keys(previous?.library ?? {}));
|
|
554
|
+
const libraryAfter = new Set(Object.keys(next.library ?? {}));
|
|
555
|
+
const entry = {
|
|
556
|
+
ts: new Date(now()).toISOString(),
|
|
557
|
+
profile,
|
|
558
|
+
source,
|
|
559
|
+
revision: next.revision,
|
|
560
|
+
prevRevision: previous?.revision ?? null,
|
|
561
|
+
...ops === void 0 ? {} : { ops },
|
|
562
|
+
skins,
|
|
563
|
+
libraryAdded: [...libraryAfter].filter((id) => !libraryBefore.has(id)),
|
|
564
|
+
libraryRemoved: [...libraryBefore].filter((id) => !libraryAfter.has(id))
|
|
565
|
+
};
|
|
566
|
+
rotateAuditIfNeeded();
|
|
567
|
+
fs.appendFileSync(auditFile, `${JSON.stringify(entry)}
|
|
568
|
+
`);
|
|
569
|
+
} catch {
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function rotateAuditIfNeeded() {
|
|
573
|
+
try {
|
|
574
|
+
if (fs.statSync(auditFile).size >= auditMaxBytes) fs.renameSync(auditFile, `${auditFile}.1`);
|
|
575
|
+
} catch {
|
|
576
|
+
}
|
|
526
577
|
}
|
|
527
578
|
function enqueue(work) {
|
|
528
579
|
const run = chain.then(work);
|
|
@@ -580,7 +631,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
580
631
|
ensureDirs();
|
|
581
632
|
const assetFiles = listAssetFiles();
|
|
582
633
|
if (read.kind === "missing" && assetFiles.length === 0) {
|
|
583
|
-
commitState(emptyState());
|
|
634
|
+
commitState(emptyState(), { source: "install", previous: null });
|
|
584
635
|
mode = "normal";
|
|
585
636
|
gcNow();
|
|
586
637
|
return;
|
|
@@ -606,6 +657,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
606
657
|
gcNow();
|
|
607
658
|
}
|
|
608
659
|
function normalizeState() {
|
|
660
|
+
const previous = structuredClone(state);
|
|
609
661
|
const provider = metaProviderFactory(state.library);
|
|
610
662
|
let removed = false;
|
|
611
663
|
for (const skinId of Object.keys(state.skins)) {
|
|
@@ -634,7 +686,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
634
686
|
}
|
|
635
687
|
if (removed) {
|
|
636
688
|
state.revision += 1;
|
|
637
|
-
commitState(state);
|
|
689
|
+
commitState(state, { source: "normalize", previous });
|
|
638
690
|
}
|
|
639
691
|
}
|
|
640
692
|
function gcNow() {
|
|
@@ -800,7 +852,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
800
852
|
}
|
|
801
853
|
}
|
|
802
854
|
draft.revision += 1;
|
|
803
|
-
commitState(draft);
|
|
855
|
+
commitState(draft, { source: "operations", ops: [...new Set(operations.map((operation) => operation?.op))] });
|
|
804
856
|
for (const meta of removedAssets) {
|
|
805
857
|
try {
|
|
806
858
|
fs.unlinkSync(blobFileFor(meta.id, meta.extension));
|
|
@@ -889,7 +941,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
889
941
|
draft.library[id] = asset;
|
|
890
942
|
draft.revision += 1;
|
|
891
943
|
try {
|
|
892
|
-
commitState(draft);
|
|
944
|
+
commitState(draft, { source: "upload" });
|
|
893
945
|
} catch (error) {
|
|
894
946
|
try {
|
|
895
947
|
fs.unlinkSync(target);
|
|
@@ -912,7 +964,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
912
964
|
const affectedSkins = [];
|
|
913
965
|
const meta = applyGalleryDelete(draft, id, affectedSkins);
|
|
914
966
|
draft.revision += 1;
|
|
915
|
-
commitState(draft);
|
|
967
|
+
commitState(draft, { source: "delete" });
|
|
916
968
|
try {
|
|
917
969
|
fs.unlinkSync(blobFileFor(meta.id, meta.extension));
|
|
918
970
|
} catch {
|
|
@@ -956,7 +1008,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
956
1008
|
draft.library = recovery.candidateLibrary;
|
|
957
1009
|
draft.revision = 1;
|
|
958
1010
|
draft.recoveryCleanup = { quarantine: [...recovery.quarantine] };
|
|
959
|
-
commitState(draft);
|
|
1011
|
+
commitState(draft, { source: "recovery-confirm" });
|
|
960
1012
|
finishRecoveryCleanup();
|
|
961
1013
|
mode = "normal";
|
|
962
1014
|
recovery = null;
|
|
@@ -976,7 +1028,7 @@ function createPersonalizationStore(options = {}) {
|
|
|
976
1028
|
}
|
|
977
1029
|
const cleaned = structuredClone(state);
|
|
978
1030
|
delete cleaned.recoveryCleanup;
|
|
979
|
-
commitState(cleaned);
|
|
1031
|
+
commitState(cleaned, { source: "recovery-cleanup" });
|
|
980
1032
|
}
|
|
981
1033
|
function pruneCorruptBackups() {
|
|
982
1034
|
const dir = join(dataDir);
|
|
@@ -1132,7 +1184,7 @@ function decodeDisplayName(request) {
|
|
|
1132
1184
|
}
|
|
1133
1185
|
}
|
|
1134
1186
|
function mountPersonalizationRoutes(host, options) {
|
|
1135
|
-
const { store, assetsBasePath = "/dsh-skins/assets", trustedHosts = [] } = options;
|
|
1187
|
+
const { store, assetsBasePath = "/dsh-skins/assets", trustedHosts = [], serveBuiltinAsset } = options;
|
|
1136
1188
|
const disposers = [];
|
|
1137
1189
|
const fence = (request, response) => {
|
|
1138
1190
|
if (isTrustedRequest(request, typeof trustedHosts === "function" ? trustedHosts() : trustedHosts)) return true;
|
|
@@ -1219,7 +1271,8 @@ function mountPersonalizationRoutes(host, options) {
|
|
|
1219
1271
|
if (!fence(request, response)) return;
|
|
1220
1272
|
if (!method(request, response, "GET")) return;
|
|
1221
1273
|
try {
|
|
1222
|
-
const
|
|
1274
|
+
const requestUrl = String(request.url ?? "");
|
|
1275
|
+
const blob = store.serveAsset(requestUrl) ?? serveBuiltinAsset?.(requestUrl) ?? null;
|
|
1223
1276
|
if (blob === null) {
|
|
1224
1277
|
return sendJson(response, 404, { error: "asset not found", code: "ASSET_NOT_FOUND" });
|
|
1225
1278
|
}
|
|
@@ -1252,6 +1305,35 @@ function mountPersonalizationRoutes(host, options) {
|
|
|
1252
1305
|
};
|
|
1253
1306
|
}
|
|
1254
1307
|
|
|
1308
|
+
// src/host/builtin-assets.js
|
|
1309
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
1310
|
+
import { join as join2 } from "node:path";
|
|
1311
|
+
var BUILTIN_FILE_PATTERN = /^b_([a-z0-9][a-z0-9-]*)_([a-z0-9][a-z0-9-]*)\.webp$/;
|
|
1312
|
+
var ASSETS_PREFIX_PATTERN = /\/dsh-skins\/assets\/([^/]+)$/;
|
|
1313
|
+
function createBuiltinAssetServer({ assetsDir, manifest }) {
|
|
1314
|
+
const byName = /* @__PURE__ */ new Map();
|
|
1315
|
+
for (const entry of manifest?.entries ?? []) {
|
|
1316
|
+
const name2 = `b_${entry.skinId}_${entry.assetKey}.webp`;
|
|
1317
|
+
if (BUILTIN_FILE_PATTERN.test(name2)) byName.set(name2, entry);
|
|
1318
|
+
}
|
|
1319
|
+
return {
|
|
1320
|
+
serveBuiltinAsset(url) {
|
|
1321
|
+
if (typeof url !== "string") return null;
|
|
1322
|
+
const prefixMatch = ASSETS_PREFIX_PATTERN.exec(url.split("?")[0]);
|
|
1323
|
+
if (prefixMatch === null) return null;
|
|
1324
|
+
const entry = byName.get(prefixMatch[1]);
|
|
1325
|
+
if (entry === void 0) return null;
|
|
1326
|
+
if (entry.file.split("/").pop() !== prefixMatch[1]) return null;
|
|
1327
|
+
try {
|
|
1328
|
+
const buffer = readFileSync2(join2(assetsDir, entry.file));
|
|
1329
|
+
return { buffer, meta: { mime: entry.mime, byteLength: buffer.length, sha256: entry.sha256 } };
|
|
1330
|
+
} catch {
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1255
1337
|
// src/host/trusted-hosts.js
|
|
1256
1338
|
function resolveTrustedHosts(ctx) {
|
|
1257
1339
|
let startup, runtime;
|
|
@@ -1270,27 +1352,27 @@ function resolveTrustedHosts(ctx) {
|
|
|
1270
1352
|
var name = "@iasiv5/dsh-skins";
|
|
1271
1353
|
function expandHomePath(path) {
|
|
1272
1354
|
if (path === "~") return homedir();
|
|
1273
|
-
if (path.startsWith("~/") || path.startsWith("~\\")) return
|
|
1355
|
+
if (path.startsWith("~/") || path.startsWith("~\\")) return join3(homedir(), path.slice(2));
|
|
1274
1356
|
return path;
|
|
1275
1357
|
}
|
|
1276
1358
|
function dshHome() {
|
|
1277
1359
|
const configured = process.env.DSH_HOME?.trim();
|
|
1278
|
-
return resolve(expandHomePath(configured ||
|
|
1360
|
+
return resolve(expandHomePath(configured || join3(homedir(), ".dsh")));
|
|
1279
1361
|
}
|
|
1280
1362
|
function hostProfileFor(root, cwd = process.cwd()) {
|
|
1281
1363
|
const normalized = (path) => process.platform === "win32" ? resolve(path).toLowerCase() : resolve(path);
|
|
1282
|
-
return normalized(cwd) === normalized(
|
|
1364
|
+
return normalized(cwd) === normalized(join3(expandHomePath(root), "profiles", "desktop")) ? "desktop" : "web";
|
|
1283
1365
|
}
|
|
1284
1366
|
function dataDirForProfile(root, profile) {
|
|
1285
1367
|
root = resolve(expandHomePath(root));
|
|
1286
|
-
const legacy =
|
|
1368
|
+
const legacy = join3(root, "dsh-skins");
|
|
1287
1369
|
if (profile !== "desktop") return legacy;
|
|
1288
|
-
const desktop =
|
|
1370
|
+
const desktop = join3(root, "dsh-skins-desktop");
|
|
1289
1371
|
if (existsSync2(desktop) || !existsSync2(legacy)) return desktop;
|
|
1290
|
-
const stage = mkdtempSync(
|
|
1372
|
+
const stage = mkdtempSync(join3(root, ".dsh-skins-desktop-migrate-"));
|
|
1291
1373
|
try {
|
|
1292
1374
|
for (const name2 of readdirSync2(legacy)) {
|
|
1293
|
-
cpSync(
|
|
1375
|
+
cpSync(join3(legacy, name2), join3(stage, name2), { recursive: true, force: false, errorOnExist: true });
|
|
1294
1376
|
}
|
|
1295
1377
|
renameSync3(stage, desktop);
|
|
1296
1378
|
} catch (error) {
|
|
@@ -1310,9 +1392,17 @@ function apply(ctx) {
|
|
|
1310
1392
|
profile
|
|
1311
1393
|
});
|
|
1312
1394
|
hostContext.effect(() => {
|
|
1395
|
+
let serveBuiltinAsset;
|
|
1396
|
+
try {
|
|
1397
|
+
const assetsDir = join3(dirname2(fileURLToPath(import.meta.url)), "..", "assets");
|
|
1398
|
+
const manifest = JSON.parse(readFileSync3(join3(assetsDir, "manifest.json"), "utf8"));
|
|
1399
|
+
serveBuiltinAsset = createBuiltinAssetServer({ assetsDir, manifest }).serveBuiltinAsset;
|
|
1400
|
+
} catch {
|
|
1401
|
+
}
|
|
1313
1402
|
return mountPersonalizationRoutes(hostContext, {
|
|
1314
1403
|
store: personalization,
|
|
1315
|
-
trustedHosts: () => resolveTrustedHosts(ctx)
|
|
1404
|
+
trustedHosts: () => resolveTrustedHosts(ctx),
|
|
1405
|
+
serveBuiltinAsset
|
|
1316
1406
|
});
|
|
1317
1407
|
}, "dsh-skins: personalization routes");
|
|
1318
1408
|
});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@iasiv5/dsh-skins",
|
|
3
3
|
"description": "DSH Web 皮肤插件:多套品牌皮肤侧栏热切换。",
|
|
4
4
|
"icon": "./icon.svg",
|
|
5
|
-
"version": "1.5.
|
|
5
|
+
"version": "1.5.26",
|
|
6
6
|
"homepage": "https://github.com/iasiv5/dsh-skins#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"lib",
|
|
37
|
+
"assets",
|
|
37
38
|
"cordis.patch.yml",
|
|
38
39
|
"locale",
|
|
39
40
|
"README.md",
|
|
@@ -85,8 +86,10 @@
|
|
|
85
86
|
"test": "pnpm run build && node smoke-test.cjs && node scripts/repro-stale-grid-paint.mjs --gate && node scripts/repro-fullscreen-collapse.mjs --gate && node scripts/repro-plugin-panel-readability.mjs --gate && node --test tests/*.test.mjs",
|
|
86
87
|
"verify:readme": "node scripts/verify-readme-pairing.mjs",
|
|
87
88
|
"verify:bundle": "node scripts/verify-bundle-guard.mjs",
|
|
89
|
+
"verify:delivery": "node scripts/verify-delivery.mjs",
|
|
88
90
|
"verify:hooks": "node scripts/verify-upstream-hooks.mjs",
|
|
89
|
-
"
|
|
91
|
+
"verify:hot-deploy": "bash scripts/verify-hot-deploy-roundtrip.sh",
|
|
92
|
+
"check": "pnpm run check:lockfile && pnpm run build && node --check lib/client.js && node --check lib/index.js && pnpm run lint && pnpm run test && pnpm run verify:readme && pnpm run verify:bundle && pnpm run verify:hooks && pnpm run verify:delivery && git diff --exit-code -- lib/index.js lib/client.js",
|
|
90
93
|
"lint": "eslint ."
|
|
91
94
|
}
|
|
92
95
|
}
|