@leonidstern/labit 0.6.3-main.12 → 0.6.3-main.13
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/CHANGELOG.md +1 -0
- package/dist/local.mjs +19 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,7 @@ Versions follow [semver](https://semver.org). Before 1.0, a minor version can ch
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
- Phone links with two labs on one computer: each lab keeps its own pass (`lab_guest_<port>`), so joining a try lab no longer logs the phone out of the other, and a used link again takes that phone to its page instead of "used up".
|
|
7
8
|
- Hosted labs sync: each page's comments have a revision (`lab:rev:<page>` in Redis, counted up by every comment, reply, resolve, move and delete). An open page asks for it every 10 s (`GET ?page=…&rev`, a few bytes) and reloads the comments only when it moved, so someone else's reply shows within seconds instead of on your next visit. Hidden tabs don't ask; local labs keep their live stream.
|
|
8
9
|
- With a dev server (`--proxy`), its reload waits while the chat, a thread, the list or a new comment is open, not only while words are typed, so an update no longer closes the chat under you. It comes in once you close it, as the lab's own reload already did.
|
|
9
10
|
- The ⋯ menu ends with which labit the lab runs (`labit 0.6.2`), and for a local edge build what it merged on top of main (`LABIT_EDGE`, e.g. `edge: main + #89 #91`), so labs on different builds can be told apart at a glance.
|
package/dist/local.mjs
CHANGED
|
@@ -868,10 +868,17 @@ var writeMe = (name) => {
|
|
|
868
868
|
return name.trim();
|
|
869
869
|
};
|
|
870
870
|
var myName = readMe();
|
|
871
|
+
var cookieOf = (req, name) => {
|
|
872
|
+
const all = req.headers.cookie || "";
|
|
873
|
+
for (const n of [`${name}_${PORT}`, name]) {
|
|
874
|
+
const m = new RegExp(`(?:^|;\\s*)${n}=([^;]+)(?:\\s*;|$)`).exec(all);
|
|
875
|
+
if (m) return m[1];
|
|
876
|
+
}
|
|
877
|
+
return "";
|
|
878
|
+
};
|
|
871
879
|
var guestName = (req) => {
|
|
872
|
-
const raw = /(?:^|;\s*)lab_me=([^;]+)(?:\s*;|$)/.exec(req.headers.cookie || "");
|
|
873
880
|
try {
|
|
874
|
-
const n = decodeURIComponent(
|
|
881
|
+
const n = decodeURIComponent(cookieOf(req, "lab_me"));
|
|
875
882
|
return NAME_OK(n) ? n.trim() : "";
|
|
876
883
|
} catch {
|
|
877
884
|
return "";
|
|
@@ -880,10 +887,14 @@ var guestName = (req) => {
|
|
|
880
887
|
var nameFor = (req) => isLoopback(req) ? myName : guestName(req);
|
|
881
888
|
var sign = (id) => createHmac("sha256", TOKEN).update(`lab-guest:${id}`).digest("hex").slice(0, 32);
|
|
882
889
|
var guestOk = (req) => {
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
890
|
+
const all = req.headers.cookie || "";
|
|
891
|
+
for (const n of [`lab_guest_${PORT}`, "lab_guest"]) {
|
|
892
|
+
const raw = new RegExp(`(?:^|;\\s*)${n}=([0-9a-f]{16})\\.([0-9a-f]{32})(?:\\s*;|$)`).exec(all);
|
|
893
|
+
if (!raw) continue;
|
|
894
|
+
const want = Buffer.from(sign(raw[1])), got = Buffer.from(raw[2]);
|
|
895
|
+
if (want.length === got.length && timingSafeEqual(want, got)) return raw[1];
|
|
896
|
+
}
|
|
897
|
+
return false;
|
|
887
898
|
};
|
|
888
899
|
var mayIn = (req) => isLoopback(req) || !WIFI || !!guestOk(req);
|
|
889
900
|
var markSvg = (size, style = "") => `<svg width="${size}" height="${size}" viewBox="0 0 64 64" aria-hidden="true"${style ? ` style="${style}"` : ""}><path transform="translate(-1 -.5)" fill="currentColor" fill-rule="evenodd" d="M18.9 24.67L24.4 3h11.5L31.28 21.2A22.8 22.8 0 0 0 18.9 24.67ZM37.07 22.02L41.9 3h11.5L47.1 27.85A22.8 22.8 0 0 0 37.07 22.02ZM31 26a18 18 0 0 1 18 18 18 18 0 0 1-18 18H15.57a2.57 2.57 0 0 1-2.57-2.57V44A18 18 0 0 1 31 26ZM24.8 45a6.2 6.2 0 1 0 12.4 0a6.2 6.2 0 1 0-12.4 0Z"/></svg>`;
|
|
@@ -893,14 +904,14 @@ var gate = (res, why = "This lab opens with a one-time link.") => res.writeHead(
|
|
|
893
904
|
);
|
|
894
905
|
var landing = (to) => typeof to === "string" && to.length < 300 && /^\/(?![/\\])\S*$/.test(to) ? to : "/";
|
|
895
906
|
var GUEST_LIFE = 86400;
|
|
896
|
-
var guestCookie = (id) => `
|
|
907
|
+
var guestCookie = (id) => `lab_guest_${PORT}=${id}.${sign(id)}; Path=/; Max-Age=${GUEST_LIFE}; HttpOnly; SameSite=Lax`;
|
|
897
908
|
var redeem = (req, res, code, me = "", to = "") => {
|
|
898
909
|
const until = passes.get(code);
|
|
899
910
|
passes.delete(code);
|
|
900
911
|
if (!until || until < Date.now()) return mayIn(req) ? res.writeHead(302, { location: landing(to) }).end() : gate(res, "That link is used up or too old.");
|
|
901
912
|
console.log(`[lab] a guest opened a one-time link (${String(req.socket.remoteAddress).replace(/^::ffff:/, "")})`);
|
|
902
913
|
const cookies = [guestCookie(randomBytes(8).toString("hex"))];
|
|
903
|
-
if (NAME_OK(me)) cookies.push(`
|
|
914
|
+
if (NAME_OK(me)) cookies.push(`lab_me_${PORT}=${encodeURIComponent(me.trim())}; Path=/; Max-Age=2592000; SameSite=Lax`);
|
|
904
915
|
return res.writeHead(302, { location: landing(to), "set-cookie": cookies }).end();
|
|
905
916
|
};
|
|
906
917
|
var isAgent = (req) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonidstern/labit",
|
|
3
|
-
"version": "0.6.3-main.
|
|
3
|
+
"version": "0.6.3-main.13",
|
|
4
4
|
"description": "Pin comments on pages, read by your agent as plain text. Local mode: comment on pages on your computer and Claude answers on the pins.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|