pi-hub-server 0.0.0-stage → 0.3.2
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/LICENSE +21 -0
- package/README.md +403 -2
- package/bin/pi-hub.mjs +353 -0
- package/docs/AUTH.md +141 -0
- package/package.json +45 -4
- package/src/config.mjs +54 -0
- package/src/otp.mjs +162 -0
- package/src/pairing.mjs +403 -0
- package/src/pi-args.mjs +51 -0
- package/src/pi-session.mjs +635 -0
- package/src/proxy-auth.mjs +181 -0
- package/src/registry.mjs +145 -0
- package/src/rpc-once.mjs +83 -0
- package/src/server.mjs +1532 -0
- package/src/session-lock.mjs +42 -0
- package/src/sessions-index.mjs +179 -0
- package/src/static.mjs +148 -0
- package/src/totp.mjs +151 -0
- package/src/update-check.mjs +218 -0
- package/src/web-auth.mjs +450 -0
- package/systemd/pi-hub.service +22 -0
- package/web/app.js +1339 -0
- package/web/icons/icon.svg +7 -0
- package/web/index.html +121 -0
- package/web/manifest.webmanifest +20 -0
- package/web/style.css +782 -0
- package/web/sw.js +45 -0
package/web/sw.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// pi hub 的 Service Worker:只缓存外壳(HTML/CSS/JS/图标),网络优先、失败回落缓存。
|
|
2
|
+
// 不缓存 /v1 响应(会话与 SSE 都是实时的,缓存只会让状态错乱)。
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const CACHE = "pihub-shell-v1";
|
|
6
|
+
const SHELL = ["/", "/index.html", "/app.js", "/style.css", "/manifest.webmanifest", "/icons/icon.svg"];
|
|
7
|
+
|
|
8
|
+
self.addEventListener("install", (event) => {
|
|
9
|
+
event.waitUntil(
|
|
10
|
+
caches
|
|
11
|
+
.open(CACHE)
|
|
12
|
+
.then((cache) => cache.addAll(SHELL))
|
|
13
|
+
.then(() => self.skipWaiting())
|
|
14
|
+
.catch(() => self.skipWaiting()),
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
self.addEventListener("activate", (event) => {
|
|
19
|
+
event.waitUntil(
|
|
20
|
+
caches
|
|
21
|
+
.keys()
|
|
22
|
+
.then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key))))
|
|
23
|
+
.then(() => self.clients.claim()),
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
self.addEventListener("fetch", (event) => {
|
|
28
|
+
const request = event.request;
|
|
29
|
+
if (request.method !== "GET") return;
|
|
30
|
+
const url = new URL(request.url);
|
|
31
|
+
if (url.origin !== self.location.origin) return;
|
|
32
|
+
if (url.pathname.startsWith("/v1/")) return;
|
|
33
|
+
|
|
34
|
+
event.respondWith(
|
|
35
|
+
fetch(request)
|
|
36
|
+
.then((response) => {
|
|
37
|
+
if (response.ok) {
|
|
38
|
+
const copy = response.clone();
|
|
39
|
+
caches.open(CACHE).then((cache) => cache.put(request, copy)).catch(() => {});
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
42
|
+
})
|
|
43
|
+
.catch(() => caches.match(request).then((hit) => hit ?? caches.match("/index.html"))),
|
|
44
|
+
);
|
|
45
|
+
});
|