dsh-any-background 0.2.3 → 0.2.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/README.md +141 -142
- package/README.zh.md +141 -142
- package/lib/client.js +3 -3
- package/lib/client.js.map +1 -1
- package/lib/index.js +153 -58
- package/package.json +10 -12
package/lib/index.js
CHANGED
|
@@ -537,69 +537,164 @@ async function handleVideoUpload(req, res) {
|
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
const NS = "dshAnyBackground";
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
message: `unknown endpoint ${ep}`,
|
|
574
|
-
details: { issues: [] }
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
} catch (e) {
|
|
579
|
-
return {
|
|
540
|
+
const RPC_CHANNEL = "/dsh-any-background";
|
|
541
|
+
const RPC_BODY_MAX = 314572800;
|
|
542
|
+
/** Dispatch one decoded RPC method to the matching persistence routine and
|
|
543
|
+
* return the wire `result` half of the server-response envelope. */
|
|
544
|
+
async function handleRpcMethod(endpoint, payload) {
|
|
545
|
+
const method = endpoint.slice(`${NS}/`.length);
|
|
546
|
+
try {
|
|
547
|
+
switch (method) {
|
|
548
|
+
case "read": return {
|
|
549
|
+
ok: true,
|
|
550
|
+
value: {
|
|
551
|
+
config: await readConfig(),
|
|
552
|
+
wallpaper: await readWallpaper(),
|
|
553
|
+
videoUrl: await videoUrl()
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
case "writeConfig": return {
|
|
557
|
+
ok: true,
|
|
558
|
+
value: await writeConfig(payload?.config ?? {})
|
|
559
|
+
};
|
|
560
|
+
case "setWallpaper": return {
|
|
561
|
+
ok: true,
|
|
562
|
+
value: await writeWallpaper(payload?.dataUrl ?? null)
|
|
563
|
+
};
|
|
564
|
+
case "setVideo": return {
|
|
565
|
+
ok: true,
|
|
566
|
+
value: await writeVideo(payload?.dataUrl ?? null)
|
|
567
|
+
};
|
|
568
|
+
case "setWallpaperUrl": return {
|
|
569
|
+
ok: true,
|
|
570
|
+
value: await writeWallpaperFromUrl(payload?.url ?? null)
|
|
571
|
+
};
|
|
572
|
+
default: return {
|
|
580
573
|
ok: false,
|
|
581
574
|
error: {
|
|
582
|
-
code: "dsh-any-background/
|
|
583
|
-
message:
|
|
584
|
-
details: {}
|
|
575
|
+
code: "dsh-any-background/bad-request",
|
|
576
|
+
message: `unknown endpoint ${endpoint}`,
|
|
577
|
+
details: { issues: [] }
|
|
585
578
|
}
|
|
586
579
|
};
|
|
587
580
|
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
581
|
+
} catch (e) {
|
|
582
|
+
return {
|
|
583
|
+
ok: false,
|
|
584
|
+
error: {
|
|
585
|
+
code: "dsh-any-background/internal",
|
|
586
|
+
message: e instanceof Error ? e.message : String(e),
|
|
587
|
+
details: {}
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function apply(ctx) {
|
|
593
|
+
ctx.inject(["connection", "webServer"], (webCtx) => {
|
|
594
|
+
webCtx.effect(() => webCtx.webServer.register({
|
|
595
|
+
kind: "prefix",
|
|
596
|
+
path: RPC_CHANNEL,
|
|
597
|
+
handler: async (req, res) => {
|
|
598
|
+
const rejection = webCtx.connection.requestRejection(req);
|
|
599
|
+
if (rejection !== void 0) {
|
|
600
|
+
res.writeHead(rejection);
|
|
601
|
+
res.end(rejection === 401 ? "unauthorized" : "forbidden");
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (req.method !== "POST") {
|
|
605
|
+
res.writeHead(405, { "Content-Type": "application/json" });
|
|
606
|
+
res.end(JSON.stringify({
|
|
607
|
+
ok: false,
|
|
608
|
+
error: {
|
|
609
|
+
code: "dsh-any-background/bad-request",
|
|
610
|
+
message: "expected POST",
|
|
611
|
+
details: {}
|
|
612
|
+
}
|
|
613
|
+
}));
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const pathname = new URL(req.url ?? "/", "http://dsh.internal").pathname;
|
|
617
|
+
const endpoint = pathname.startsWith(`${RPC_CHANNEL}/`) ? pathname.slice(20) : void 0;
|
|
618
|
+
if (endpoint === void 0 || endpoint.length === 0) {
|
|
619
|
+
res.writeHead(404);
|
|
620
|
+
res.end();
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const chunks = [];
|
|
624
|
+
let received = 0;
|
|
625
|
+
for await (const chunk of req) {
|
|
626
|
+
const buf = chunk;
|
|
627
|
+
received += buf.byteLength;
|
|
628
|
+
if (received > RPC_BODY_MAX) {
|
|
629
|
+
res.writeHead(413, { connection: "close" });
|
|
630
|
+
res.end();
|
|
631
|
+
req.destroy();
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
chunks.push(buf);
|
|
635
|
+
}
|
|
636
|
+
let env;
|
|
637
|
+
try {
|
|
638
|
+
env = JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}");
|
|
639
|
+
} catch {
|
|
640
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
641
|
+
res.end(JSON.stringify({
|
|
642
|
+
ok: false,
|
|
643
|
+
error: {
|
|
644
|
+
code: "dsh-any-background/bad-request",
|
|
645
|
+
message: "body is not JSON",
|
|
646
|
+
details: {}
|
|
647
|
+
}
|
|
648
|
+
}));
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (env === null || typeof env !== "object" || env.type !== "client-request" || typeof env.rpcId !== "string" || typeof env.method !== "string") {
|
|
652
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
653
|
+
res.end(JSON.stringify({
|
|
654
|
+
ok: false,
|
|
655
|
+
error: {
|
|
656
|
+
code: "dsh-any-background/bad-request",
|
|
657
|
+
message: "invalid client-request envelope",
|
|
658
|
+
details: {}
|
|
659
|
+
}
|
|
660
|
+
}));
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (env.method !== endpoint) {
|
|
664
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
665
|
+
res.end(JSON.stringify({
|
|
666
|
+
type: "server-response",
|
|
667
|
+
rpcId: env.rpcId,
|
|
668
|
+
result: {
|
|
669
|
+
ok: false,
|
|
670
|
+
error: {
|
|
671
|
+
code: "dsh-any-background/bad-request",
|
|
672
|
+
message: `method ${env.method} does not match endpoint ${endpoint}`,
|
|
673
|
+
details: { issues: [] }
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}));
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
const result = await handleRpcMethod(endpoint, env.payload);
|
|
680
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
681
|
+
res.end(JSON.stringify({
|
|
682
|
+
type: "server-response",
|
|
683
|
+
rpcId: env.rpcId,
|
|
684
|
+
result
|
|
685
|
+
}));
|
|
686
|
+
}
|
|
687
|
+
}), "dsh-any-background: rpc channel");
|
|
688
|
+
webCtx.effect(() => webCtx.webServer.register({
|
|
689
|
+
kind: "prefix",
|
|
690
|
+
path: VIDEO_ROUTE,
|
|
691
|
+
handler: serveVideo
|
|
692
|
+
}), "dsh-any-background: video route");
|
|
693
|
+
webCtx.effect(() => webCtx.webServer.register({
|
|
694
|
+
kind: "exact",
|
|
695
|
+
path: UPLOAD_ROUTE,
|
|
696
|
+
handler: handleVideoUpload
|
|
697
|
+
}), "dsh-any-background: upload route");
|
|
603
698
|
});
|
|
604
699
|
}
|
|
605
700
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-any-background",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Appearance plugin for DeepSeek Harness: custom theme color (PS-style color wheel), background wallpaper with opacity/blur controls, and separate main/settings interface opacity.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"author": "Tkingxiao",
|
|
24
24
|
"type": "module",
|
|
25
|
+
"engines": {
|
|
26
|
+
"dsh": ">=0.1.2-rc.1"
|
|
27
|
+
},
|
|
25
28
|
"exports": {
|
|
26
29
|
".": {
|
|
27
30
|
"default": "./lib/index.js"
|
|
@@ -63,14 +66,13 @@
|
|
|
63
66
|
"@deepseek-ai/dsh-home-paths": "^0.1.0-rc.6"
|
|
64
67
|
},
|
|
65
68
|
"peerDependencies": {
|
|
66
|
-
"@deepseek-ai/cordis": "^4.0.
|
|
67
|
-
"@deepseek-ai/dsh-client-locale": "^0.1.
|
|
68
|
-
"@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.6",
|
|
69
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
70
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.2-alpha.2",
|
|
69
71
|
"@deepseek-ai/dsh-client-store": "^0.1.2-alpha.2",
|
|
70
|
-
"@deepseek-ai/dsh-client-connection": "^0.1.
|
|
71
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.1.
|
|
72
|
-
"@deepseek-ai/dsh-client-ui-theme": "^0.1.
|
|
73
|
-
"@deepseek-ai/dsh-invariants": "^0.1.
|
|
72
|
+
"@deepseek-ai/dsh-client-connection": "^0.1.2-alpha.2",
|
|
73
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.1.2-alpha.2",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-theme": "^0.1.2-alpha.2",
|
|
75
|
+
"@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
|
|
74
76
|
"react": "^18.2.0"
|
|
75
77
|
},
|
|
76
78
|
"peerDependenciesMeta": {
|
|
@@ -89,9 +91,6 @@
|
|
|
89
91
|
"@deepseek-ai/dsh-client-ui-settings": {
|
|
90
92
|
"optional": true
|
|
91
93
|
},
|
|
92
|
-
"@deepseek-ai/dsh-client-runtime": {
|
|
93
|
-
"optional": true
|
|
94
|
-
},
|
|
95
94
|
"@deepseek-ai/dsh-client-ui-theme": {
|
|
96
95
|
"optional": true
|
|
97
96
|
},
|
|
@@ -109,7 +108,6 @@
|
|
|
109
108
|
"client": {
|
|
110
109
|
"platform": "web",
|
|
111
110
|
"inject": [
|
|
112
|
-
"@deepseek-ai/dsh-client-runtime",
|
|
113
111
|
"@deepseek-ai/dsh-client-store",
|
|
114
112
|
"@deepseek-ai/dsh-client-locale",
|
|
115
113
|
"@deepseek-ai/dsh-client-connection",
|