alink-cli 0.8.6 → 0.8.7
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/dist/bin.mjs +123 -6
- package/dist/bin.mjs.map +1 -1
- package/dist/daemon.js +30 -0
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -24357,6 +24357,30 @@ function webLink(hub, token) {
|
|
|
24357
24357
|
u.search = `?token=${encodeURIComponent(token)}`;
|
|
24358
24358
|
return u.toString();
|
|
24359
24359
|
}
|
|
24360
|
+
function hubHttpUrl(hub) {
|
|
24361
|
+
if (PUBLIC_BASE) return PUBLIC_BASE.replace(/\/$/, "");
|
|
24362
|
+
const u = new URL(hub);
|
|
24363
|
+
u.protocol = u.protocol === "wss:" ? "https:" : "http:";
|
|
24364
|
+
u.pathname = "";
|
|
24365
|
+
u.search = "";
|
|
24366
|
+
return u.toString().replace(/\/$/, "");
|
|
24367
|
+
}
|
|
24368
|
+
async function uploadEnckey(hub, machineToken, machineId, enckey) {
|
|
24369
|
+
const url3 = `${hubHttpUrl(hub)}/api/machines/${encodeURIComponent(machineId)}/enckey`;
|
|
24370
|
+
const response = await fetch(url3, {
|
|
24371
|
+
method: "POST",
|
|
24372
|
+
headers: {
|
|
24373
|
+
"Content-Type": "application/json",
|
|
24374
|
+
"X-Requested-With": "agentlink",
|
|
24375
|
+
Authorization: `Bearer ${machineToken}`
|
|
24376
|
+
},
|
|
24377
|
+
body: JSON.stringify({ enckey })
|
|
24378
|
+
});
|
|
24379
|
+
if (!response.ok) {
|
|
24380
|
+
const body = await response.text().catch(() => "");
|
|
24381
|
+
throw new Error(`enckey upload failed: ${response.status} ${body.slice(0, 200)}`);
|
|
24382
|
+
}
|
|
24383
|
+
}
|
|
24360
24384
|
async function probeVersion(bin) {
|
|
24361
24385
|
const out = await captureCommand(bin, ["--version"], 3e3);
|
|
24362
24386
|
const first = out?.trim().split("\n")[0]?.trim();
|
|
@@ -24760,6 +24784,12 @@ function connect2() {
|
|
|
24760
24784
|
send(ws, { type: "register", hostname: hostname3(), daemonVersion: ownVersion(), dirs: DIRS, home: homedir6(), agents, e2e: CRED.enckey !== void 0 });
|
|
24761
24785
|
console.log(`[daemon] registered. Waiting for work pushed from the hub...`);
|
|
24762
24786
|
writeStatus("connected");
|
|
24787
|
+
if (CRED.multi && CRED.machineId && ENCKEY) {
|
|
24788
|
+
uploadEnckey(HUB, TOKEN, CRED.machineId, ENCKEY).then(
|
|
24789
|
+
() => console.log(`[daemon] enckey uploaded to hub for cross-device recovery`),
|
|
24790
|
+
(err) => console.error(`[daemon] enckey upload failed: ${err instanceof Error ? err.message : err}`)
|
|
24791
|
+
);
|
|
24792
|
+
}
|
|
24763
24793
|
if (printedLink) return;
|
|
24764
24794
|
printedLink = true;
|
|
24765
24795
|
if (CRED.multi) {
|
package/package.json
CHANGED